public void BinarySplitConstructorTest() { Accord.Math.Tools.SetupGenerator(0); // Declare some observations double[][] observations = { new double[] { -5, -2, -1 }, new double[] { -5, -5, -6 }, new double[] { 2, 1, 1 }, new double[] { 1, 1, 2 }, new double[] { 1, 2, 2 }, new double[] { 3, 1, 2 }, new double[] { 11, 5, 4 }, new double[] { 15, 5, 6 }, new double[] { 10, 5, 6 }, }; double[][] orig = observations.MemberwiseClone(); // Create a new binary split with 3 clusters BinarySplit binarySplit = new BinarySplit(3); // Compute the algorithm, retrieving an integer array // containing the labels for each of the observations int[] labels = binarySplit.Compute(observations); // As a result, the first two observations should belong to the // same cluster (thus having the same label). The same should // happen to the next four observations and to the last three. Assert.AreEqual(labels[0], labels[1]); Assert.AreEqual(labels[2], labels[3]); Assert.AreEqual(labels[2], labels[4]); Assert.AreEqual(labels[2], labels[5]); Assert.AreEqual(labels[6], labels[7]); Assert.AreEqual(labels[6], labels[8]); Assert.AreNotEqual(labels[0], labels[2]); Assert.AreNotEqual(labels[2], labels[6]); Assert.AreNotEqual(labels[0], labels[6]); int[] labels2 = binarySplit.Clusters.Nearest(observations); Assert.IsTrue(labels.IsEqual(labels2)); // the data must not have changed! Assert.IsTrue(orig.IsEqual(observations)); }
public void buildModel() { if (inputMatrix == null) getMatrix(); switch (cType) { case clusterType.KMEANS: KMeans kmeans = new KMeans(k); kmeans.Compute(inputMatrix, precision); clusterCollection = kmeans.Clusters; model = kmeans; break; case clusterType.BINARY: BinarySplit bSplit = new BinarySplit(k); bSplit.Compute(inputMatrix, precision); clusterCollection = bSplit.Clusters; model = bSplit; //Console.WriteLine("BinarySplit"); break; case clusterType.GAUSSIANMIXTURE: GaussianMixtureModel gModel = new GaussianMixtureModel(k); gModel.Compute(inputMatrix, precision); clusterCollection = gModel.Gaussians; model = gModel; break; default: break; } lbl = new List<string>(); for (int i = 0; i < k; i++) { lbl.Add(i.ToString()); } }