public ActionResult GetClusters() { try { var eventClusters = new List <Streamer[]>(); // Cluster on geographical positions var geoClusters = _denStream.Cluster(); // Cluster on the stream descriptions foreach (var geoCluster in geoClusters) { if (geoCluster.Length > 10) // Shrinkage clustering requires a proper data set to function { eventClusters.AddRange(_shrinkageClustering.Cluster(geoCluster)); } else { eventClusters.Add(geoCluster); } } return(Ok(eventClusters)); } catch (Exception e) { if (_env.IsDevelopment() || TEST_ENV) { return(BadRequest(e.Message)); } return(BadRequest()); } }
public void Cluster_SevenBroadcasters_NotEmptyClusters() { dynamic jsonArr = JsonConvert.DeserializeObject( File.ReadAllText($"../../../shrinkage_empty_test.json")); var streamers = new List <Streamer>(); foreach (var s in jsonArr) { var id = (string)s.id; var lat = (float)s.latitude; var lon = (float)s.longitude; var timestamp = (int)s.timeStamp; var streamDescription = new [] { 1.2f, 1.4f, 1.5f }; streamers.Add(new Streamer(lon, lat, streamDescription, timestamp, id)); } var clusters = SC.Cluster(streamers); Assert.That(clusters, Is.Not.Empty); }
public Streamer[][] GetClusters() { var eventClusters = new List <Streamer[]>(); // Cluster on geographical positions var geoClusters = _denStream.Cluster(); // Cluster on the stream descriptions foreach (var geoCluster in geoClusters) { eventClusters.AddRange(_shrinkageClustering.Cluster(geoCluster)); } return(eventClusters.ToArray()); }
public T[][] Cluster() { _clusteringInProgress = true; // Lock PCMC and OCMC collections _dbscan = new DbScan <CoreMicroCluster <T> >(50, 2, CurrentTime, _microClusterSimilarityFunction); var pcmcClusters = _dbscan.Cluster(PotentialCoreMicroClusters); var clusters = new List <T[]>(); foreach (var pcmcCluster in pcmcClusters) { var cluster = new List <T>(); foreach (var pcmc in pcmcCluster) { cluster.AddRange(pcmc.Points); } clusters.Add(cluster.ToArray()); } _clusteringInProgress = false; // Unlock PCMC and OCMC collections return(clusters.ToArray()); }
public T[][] Cluster() { if (_userTerminated) { throw new InvalidOperationException( "Cluster maintenance has been terminated by the user. " + "Cannot cluster without maintenance."); } // Lock micro cluster map during clustering, force merge the remaining points _clusteringInProgress = true; while (!_dataStream.IsEmpty) { var successfulDequeue = _dataStream.TryDequeue(out var p); if (!successfulDequeue) { continue; } // Merge the dataPoint into the micro cluster map Merge(p); } try { // Check if there is less than 10 streamers - if so, just return them if (MicroClusters.Count == 1 && MicroClusters.First().Points.Count < 10) { return(new[] { MicroClusters.First().Points.ToArray() }); } _dbscan = new TimelessDbScan <UntimedMicroCluster <T> >(50, 2, _microClusterSimilarityFunction); var pcmcClusters = _dbscan.Cluster(_microClusters); var clusters = new List <T[]>(); foreach (var pcmcCluster in pcmcClusters) { var cluster = new List <T>(); foreach (var pcmc in pcmcCluster) { cluster.AddRange(pcmc.Points); } clusters.Add(cluster.ToArray()); } _clusteringInProgress = false; // Unlock cluster map return(clusters.ToArray()); } catch (Exception e) { // Throw to return to client as a 400 throw e; } finally { _clusteringInProgress = false; } }