public void TestKMeansClusterAlgorithmWithThreeElements()
        {
            var clusterer = new KMeansClusterer(new EuclideanDistanceCalculator());
            var elements = new List<ClusterPoint>();
            elements.Add(new ClusterPoint { X = -1, Y = -1 });
            elements.Add(new ClusterPoint { X = 0, Y = 0 });
            elements.Add(new ClusterPoint { X = 1, Y = 1 });
            const uint expectedClusterCount = 2;
            var clusters = clusterer.CreateClusters(elements, expectedClusterCount);
            Assert.IsNotNull(clusters, @"The clusters must not be null!");

            uint clusterCount = 0;
            int expectedElementCount = elements.Count;
            int elementCount = 0;
            foreach (var cluster in clusters)
            {
                clusterCount++;
                foreach (var element in cluster.Elements)
                {
                    elementCount++;
                }
            }
            Assert.AreEqual(expectedClusterCount, clusterCount, @"The cluster count was not expected!");
            Assert.AreEqual(expectedElementCount, elementCount, @"The element count was not expected!");
        }
        public void TestKMeansClusterAlgorithmWithGeonamesCountryFile()
        {
            var clusterer = new KMeansClusterer(new EuclideanDistanceCalculator());
            var elements = new ClusterPointTextFile(new FileInfo(@"data\aa.txt"), "\t", 4, 3, 1);
            const uint expectedClusterCount = 10;
            var clusters = clusterer.CreateClusters(elements, expectedClusterCount);
            Assert.IsNotNull(clusters, @"The clusters must not be null!");

            uint clusterCount = 0;
            foreach (var cluster in clusters)
            {
                clusterCount++;
            }
            Assert.AreEqual(expectedClusterCount, clusterCount, @"The cluster count was not expected!");
        }
Пример #3
0
 public void StartClustering(IEnumerable <Vector2> points)
 {
     this.clusterer = new KMeansClusterer(points, this.clustersCount);
     StateHasChanged();
 }