Пример #1
0
        public void test2()
        {
            WriteLine("Generating the normal samples spacial points. ");
            double[] mu1             = new double[] { 200, 0 }, mu2 = new double[] { -200, 0 };
            double   sd              = 50;
            int      EachClusterSize = 100;

            // SpacialPoint ExpectedCenter1 = new SpacialPoint(mu1);
            // SpacialPoint ExpectedCenter2 = new SpacialPoint(mu2);
            WriteLine($"2 hypothetical centers: [[{mu1[0]}, {mu1[1]}], [{mu2[0]},{mu2[1]}],");
            int Counter = 10;

            WriteLine("Average Normalized Deviations from centroid to centers");

            while (--Counter != 0)
            {
                Point[] samples1 = SpatialPoint.NormalRandomPoints(mu1, sd, EachClusterSize);
                Point[] samples2 = SpatialPoint.NormalRandomPoints(mu2, sd, EachClusterSize);

                Point[] merged = new Point[samples1.Length + samples2.Length];
                Array.Copy(samples1, 0, merged, 0, samples1.Length);
                Array.Copy(samples2, 0, merged, samples1.Length, samples2.Length);

                KMinSpanningTree Kmst = new KMinSpanningTree(merged);
                WriteLine("------------------------Centroids:----------------------------------");
                Point[][] SetOfClusters = MakeNestedArrayFomPointCollection(Kmst.KSpanningTree);
                SaveTheClustersToJson($"tests_output/test2_clusters{Counter}.json", SetOfClusters);
            }
        }
Пример #2
0
            public Task GetTestInstance()
            {
                TestRecord that = this;
                Task       r    = new Task
                                  (
                    () =>
                {
                    Stopwatch sw = new Stopwatch();

                    SpatialPoint ExpectedCenter1 = new SpatialPoint(Mu1), ExpectedCenter2 = new SpatialPoint(Mu2);

                    Point[] samples1 = SpatialPoint.NormalRandomPoints(Mu1, 1, SizeofEachCluster);
                    Point[] samples2 = SpatialPoint.NormalRandomPoints(Mu2, 1, SizeofEachCluster);

                    Point[] merged = new Point[samples1.Length + samples2.Length];
                    Array.Copy(samples1, 0, merged, 0, samples1.Length);
                    Array.Copy(samples2, 0, merged, samples1.Length, samples2.Length);

                    sw.Start();
                    FullGraphClustering fg = new FullGraphClustering(merged);

                    Point c1  = fg.Centroid1;
                    Point c2  = fg.Centroid2;
                    double d1 = Math.Min(Point.Dis(c1, ExpectedCenter1), Point.Dis(c1, ExpectedCenter2));
                    double d2 = Math.Min(Point.Dis(c2, ExpectedCenter1), Point.Dis(c2, ExpectedCenter2));
                    double d  = (d1 + d2) / 2;
                    d        /= SDaway;
                    sw.Stop();
                    that.Register(d, sw.Elapsed.TotalMilliseconds);
                }
                                  );

                return(r);
            }
        public void TestPointsClass()
        {
            Point p1 = new SpatialPoint(new int[] { 0, 0, 0 });
            Point p2 = new SpatialPoint(new int[] { 1, 1, 1 });

            Assert.IsTrue(Point.Dis(p1, p2) == Math.Sqrt(3));
        }
        public void TestClustering()
        {
            WriteLine("Generating the normal samples spacial points. ");
            double[]     mu1             = new double[] { 0, 0, 0 }, mu2 = new double[] { 200, 200, 200 };
            double       sd              = 100;
            int          EachClusterSize = 500;
            SpatialPoint ExpectedCenter1 = new SpatialPoint(mu1);
            SpatialPoint ExpectedCenter2 = new SpatialPoint(mu2);

            WriteLine($"2 hypothetical centers: [[{mu1[0]}, {mu1[1]}, {mu1[2]}], [{mu2[0]},{mu2[1]},{mu2[2]}]],");
            int Counter = 100;

            WriteLine("Average Normalized Deviations from centroid to centers");

            double DeviationAverage = 0;

            while (--Counter != 0)
            {
                Point[] samples1 = SpatialPoint.NormalRandomPoints(mu1, sd, EachClusterSize);
                Point[] samples2 = SpatialPoint.NormalRandomPoints(mu2, sd, EachClusterSize);

                Point[] merged = new Point[samples1.Length + samples2.Length];
                Array.Copy(samples1, 0, merged, 0, samples1.Length);
                Array.Copy(samples2, 0, merged, samples1.Length, samples2.Length);

                FullGraphClustering fg = new FullGraphClustering(merged);

                Point  c1 = fg.Centroid1;
                Point  c2 = fg.Centroid2;
                double d1 = Math.Min(Point.Dis(c1, ExpectedCenter1), Point.Dis(c1, ExpectedCenter2));
                double d2 = Math.Min(Point.Dis(c2, ExpectedCenter1), Point.Dis(c2, ExpectedCenter2));
                double d  = (
                    d1 / (Math.Sqrt(mu1.Length) * sd)
                    +
                    d2 / (Math.Sqrt(mu2.Length) * sd)
                    ) / 2;
                WriteLine(
                    d
                    );
                DeviationAverage += d / 100;
            }
            WriteLine($"Average Deviation: {DeviationAverage}");
        }