예제 #1
0
        /// <summary>
        /// Perform the example.
        /// </summary>
        public void Run()
        {
            // read the iris data from the resources
            Assembly assembly = Assembly.GetExecutingAssembly();
            var res = assembly.GetManifestResourceStream("AIFH_Vol1.Resources.iris.csv");

            // did we fail to read the resouce
            if (res == null)
            {
                Console.WriteLine("Can't read iris data from embedded resources.");
                return;
            }

            // load the data
            var istream = new StreamReader(res);
            DataSet ds = DataSet.Load(istream);
            istream.Close();

            // perform the cluster
            IList<BasicData> observations = ds.ExtractUnsupervisedLabeled(4);
            KMeansClustering kmeans = new KMeansClustering(3);
            kmeans.InitForgy(observations);
            int iterations = kmeans.Iteration(1000);
            Console.WriteLine("Finished after " + iterations + " iterations.");

            for (int i = 0; i < kmeans.K; i++)
            {
                Cluster cluster = kmeans.Clusters[i];
                Console.WriteLine("* * * Cluster #" + i);
                foreach (BasicData d in cluster.Observations)
                {
                    Console.WriteLine(d.ToString());
                }
            }
        }
예제 #2
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
        public void TestClusterForgy()
        {
            var kmeans = new KMeansClustering(4) {RandomGeneration = new BasicGenerateRandom(22)};
            kmeans.InitForgy(GetDataSet());
            int iterations = kmeans.Iteration(1000);
            Assert.AreEqual(2, iterations);

            Cluster cluster1 = kmeans.Clusters[0];
            Cluster cluster2 = kmeans.Clusters[1];
            Cluster cluster3 = kmeans.Clusters[2];
            Cluster cluster4 = kmeans.Clusters[3];

            Assert.AreEqual(3, cluster1.Observations.Count);
            Assert.AreEqual(3, cluster2.Observations.Count);
            Assert.AreEqual(3, cluster3.Observations.Count);
            Assert.AreEqual(3, cluster4.Observations.Count);
        }
예제 #3
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestTooManyClusters()
 {
     var kmeans = new KMeansClustering(13);
     kmeans.InitRandom(GetDataSet());
 }
예제 #4
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestNoObservations()
 {
     IList<BasicData> list = new List<BasicData>();
     var kmeans = new KMeansClustering(3);
     kmeans.InitForgy(list);
 }
예제 #5
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestNoDimension()
 {
     IList<BasicData> list = new List<BasicData>();
     list.Add(new BasicData(0));
     var kmeans = new KMeansClustering(3);
     kmeans.InitForgy(list);
 }
예제 #6
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestMaxClusters()
 {
     var kmeans = new KMeansClustering(12);
     kmeans.RandomGeneration = new BasicGenerateRandom(22);
     kmeans.InitRandom(GetDataSet());
     int iterations = kmeans.Iteration(1000);
     Assert.AreEqual(1, iterations);
 }
예제 #7
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestGeneral()
 {
     var kmeans = new KMeansClustering(5);
     Assert.AreEqual(5, kmeans.K);
     kmeans.RandomGeneration = new BasicGenerateRandom();
     kmeans.DistanceMetric = new EuclideanDistance();
 }
예제 #8
0
파일: TestKMeans.cs 프로젝트: pwoolcoc/aifh
 public void TestEarlyIteration()
 {
     var kmeans = new KMeansClustering(3);
     kmeans.Iteration();
 }