private void ExpandCluster(DbscanPoint newPoint, IEnumerable <DbscanPoint> neighborPts, int clusterId) { newPoint.ClusterId = clusterId; var queue = new Queue <DbscanPoint>(neighborPts); while (queue.Count > 0) { var point = queue.Dequeue(); if (point.ClusterId == UNCLASSIFIED) { point.ClusterId = clusterId; } if (point.IsVisited) { continue; } point.IsVisited = true; var neighbors = neighbor(point.ClusterPoint); if (neighbors.Count() >= MinPts) { foreach (var neighbor in neighbors.Where(neighbor => !neighbor.IsVisited)) { queue.Enqueue(neighbor); } } } }
public ClusteringStarted(DbscanPoint <TF> point, DbscanPoint <TF>[] neighborPoints, int clusterId, double epsilon, int minimumPoints) { Point = point; NeighborPoints = neighborPoints; ClusterId = clusterId; Epsilon = epsilon; MinimumPoints = minimumPoints; }
/// <summary> /// /// </summary> /// <param name="allPoints">Dataset</param> /// <param name="point">point to be in a cluster</param> /// <param name="neighborPts">other points in same region with point parameter</param> /// <param name="clusterId">given clusterId</param> /// <param name="epsilon">Desired region ball range</param> /// <param name="minPts">Minimum number of points to be in a region</param> private void ExpandCluster(KDTree.KDTree <DbscanPoint <T> > tree, DbscanPoint <T> p, DbscanPoint <T>[] neighborPts, int clusterId, double epsilon, int minPts) { p.ClusterId = clusterId; //for (int i = 0; i < neighborPts.Length; i++) //{ // DbscanPoint<T> pn = neighborPts[i]; // if (!pn.IsVisited) // { // pn.IsVisited = true; // DbscanPoint<T>[] neighborPts2 = RegionQuery(tree, pn.ClusterPoint, epsilon); ; // if (neighborPts2.Length >= minPts) // { // neighborPts = neighborPts.Union(neighborPts2).ToArray(); // } // } // if (pn.ClusterId == (int)ClusterIds.Unclassified) // pn.ClusterId = clusterId; //} var queue = new Queue <DbscanPoint <T> >(neighborPts); while (queue.Count > 0) { var point = queue.Dequeue(); if (point.ClusterId == (int)ClusterIds.Unclassified) { point.ClusterId = clusterId; } if (point.IsVisited) { continue; } point.IsVisited = true; var neighbors = RegionQuery(tree, point.ClusterPoint, epsilon); if (neighbors.Length >= minPts) { foreach (var neighbor in neighbors.Where(neighbor => !neighbor.IsVisited)) { queue.Enqueue(neighbor); } } } }
public void ComputeClusterDbscan(T[] allPoints, double epsilon, int minPts, out HashSet <T[]> clusters, ref List <int> clusterIds) { DbscanPoint <T>[] allPointsDbscan = allPoints.Where(x => x.posX != 0 || x.posY != 0 || x.posZ != 0) .Select(x => new DbscanPoint <T>(x)).ToArray(); var tree = new KDTree.KDTree <DbscanPoint <T> >(3); for (var i = 0; i < allPointsDbscan.Length; ++i) { Record temp = allPointsDbscan[i].ClusterPoint; tree.AddPoint(new double[] { temp.posX, temp.posY, temp.posZ }, allPointsDbscan[i]); } int clusterId = 0; for (int i = 0; i < allPointsDbscan.Length; i++) { DbscanPoint <T> p = allPointsDbscan[i]; if (p.IsVisited) { clusterIds.Add(p.ClusterId); continue; } p.IsVisited = true; var neighborPts = RegionQuery(tree, p.ClusterPoint, epsilon); if (neighborPts.Length < minPts) { p.ClusterId = (int)ClusterIds.Noise; } else { clusterId++; ExpandCluster(tree, p, neighborPts, clusterId, epsilon, minPts); } clusterIds.Add(p.ClusterId); } clusters = new HashSet <T[]>( allPointsDbscan .Where(x => x.ClusterId > 0) .GroupBy(x => x.ClusterId) .Select(x => x.Select(y => y.ClusterPoint).ToArray()) ); }
private void ExpandCluster(DbscanPoint[] allPoints, DbscanPoint p, DbscanPoint[] neighborPts, int c, double epsilon, int minPts) { p.ClusterId = c; for (int i = 0; i < neighborPts.Length; i++) { var pn = neighborPts[i]; if (!pn.IsVisited) { pn.IsVisited = true; DbscanPoint[] neighborPts2 = null; RegionQuery(allPoints, pn.ClusterPoint, epsilon, out neighborPts2); if (neighborPts2.Length >= minPts) { neighborPts = neighborPts.Union(neighborPts2).ToArray(); } } if (pn.ClusterId == (int)ClusterIds.UNCLASSIFIED) { pn.ClusterId = c; } } }
public void Process(DbscanPoint <TF> point) { if (point.ClusterId.HasValue && !Result.Clusters.ContainsKey(point.ClusterId.Value)) { Result.Clusters.Add(point.ClusterId.Value, new List <DbscanPoint <TF> >()); } switch (point) { case DbscanPoint <TF> core when core.PointType == PointType.Core: Result.Clusters[core.ClusterId.Value].Add(core); break; case DbscanPoint <TF> border when border.PointType == PointType.Border: Result.Clusters[border.ClusterId.Value].Add(border); break; case DbscanPoint <TF> noise when noise.PointType == PointType.Noise: Result.Noise.Add(noise); break; } }
public bool CheckCenterEmpty(T[] clusterPoints, T centerPoint, double epsilon, int maxPts) { DbscanPoint <T>[] clusterPointsDbscan = clusterPoints.Select(x => new DbscanPoint <T>(x)).ToArray(); var tree = new KDTree.KDTree <DbscanPoint <T> >(3); for (var i = 0; i < clusterPointsDbscan.Length; ++i) { Record temp = clusterPointsDbscan[i].ClusterPoint; tree.AddPoint(new double[] { temp.posX, temp.posY, temp.posZ }, clusterPointsDbscan[i]); } Record tempCenter = new DbscanPoint <T>(centerPoint).ClusterPoint; tree.AddPoint(new double[] { tempCenter.posX, tempCenter.posY, tempCenter.posZ }, new DbscanPoint <T>(centerPoint)); var neighborPts = RegionQuery(tree, centerPoint, epsilon); if (neighborPts.Length > maxPts) { return(false); } else { return(true); } }
public PointProcessFinished(DbscanPoint <TF> point) { Point = point; }
public PointProcessStarted(DbscanPoint <TF> point) { Point = point; }
public PointAlreadyProcessed(DbscanPoint <TF> point) { Point = point; }
public RegionQueryStarted(DbscanPoint <TF> point, double epsilon, int minimumPoints) { Point = point; Epsilon = epsilon; MinimumPoints = minimumPoints; }
public RegionQueryFinished(DbscanPoint <TF> point, DbscanPoint <TF>[] neighborPoints) { Point = point; NeighborPoints = neighborPoints; }
public PointTypeAssigned(DbscanPoint <TF> point, PointType assignedType) { Point = point; AssignedType = assignedType; }
private void visit(DbscanPoint p) { p.IsVisited = true; increceCounterAndNotify(); }