Ejemplo n.º 1
0
 static List<Vertex> GetRegion(List<Vertex> points, Vertex p, double eps)
 {
     List<Vertex> region = new List<Vertex>();
     for (int i = 0; i < points.Count; i++)
     {
         double distSquared = Vertex.EuclideDistance(p, points[i]);
         if (distSquared <= eps) region.Add(points[i]);
     }
     return region;
 }
Ejemplo n.º 2
0
 public void PostClustering()
 {
     for (int i = 0; i < C.Count; i++)
     {
         if (C[i].Data.Count < 2)
         {
             AddToClosestCluster(C[i]);
             i--;
         }
     }
     List<Vertex> docs = DocVertexes;
     Vertex[] ClusterCoords = new Vertex[C.Count];
     //Получение кооддинат кластеров
     for (int i = 0; i < C.Count; i++)
     {
         ClusterCoords[i] = C[i].ClusterCenter;
     }
     //Добавление вершин-документов
     for (int i = 0; i < docs.Count; i++)
     {
         double minDist = double.MaxValue;
         int clstIndex = 0;
         for (int j = 0; j < ClusterCoords.Length; j++)
         {
             if (Vertex.EuclideDistance(docs[i], ClusterCoords[j]) < minDist)
             {
                 minDist = Vertex.EuclideDistance(docs[i], ClusterCoords[j]);
                 clstIndex = j;
             }
         }
         C[clstIndex].Data.Add(docs[i]);
     }
 }
Ejemplo n.º 3
0
 static bool ExpandCluster(List<Vertex> points, Vertex p, int clusterId, double eps, int minPts)
 {
     List<Vertex> seeds = GetRegion(points, p, eps);
     if (seeds.Count < minPts) // no core point
     {
         p.ClusterId = Vertex.NOISE;
         return false;
     }
     else // all points in seeds are density reachable from point 'p'
     {
         for (int i = 0; i < seeds.Count; i++) seeds[i].ClusterId = clusterId;
         seeds.Remove(p);
         while (seeds.Count > 0)
         {
             Vertex currentP = seeds[0];
             List<Vertex> result = GetRegion(points, currentP, eps);
             if (result.Count >= minPts)
             {
                 for (int i = 0; i < result.Count; i++)
                 {
                     Vertex resultP = result[i];
                     if (resultP.ClusterId == Vertex.UNCLASSIFIED || resultP.ClusterId == Vertex.NOISE)
                     {
                         if (resultP.ClusterId == Vertex.UNCLASSIFIED) seeds.Add(resultP);
                         resultP.ClusterId = clusterId;
                     }
                 }
             }
             seeds.Remove(currentP);
         }
         return true;
     }
 }
Ejemplo n.º 4
0
 public static double EuclideDistance(Vertex a, Vertex b)
 {
     return Math.Sqrt(Math.Pow(a.x - b.x, 2) + Math.Pow(a.y - b.y, 2) + Math.Pow(a.z - b.z, 2));
 }