Accord.Tests.MachineLearning.MeanShiftTest.MeanShiftConstructorTest2 C# (CSharp) Méthode

MeanShiftConstructorTest2() private méthode

private MeanShiftConstructorTest2 ( ) : void
Résultat void
        public void MeanShiftConstructorTest2()
        {
            Accord.Math.Tools.SetupGenerator(1);

            // Declare some observations
            double[][] observations = 
            {
                new double[] { -5, -2, -4 },
                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 uniform kernel density function
            UniformKernel kernel = new UniformKernel();

            // Create a new Mean-Shift algorithm for 3 dimensional samples
            MeanShift meanShift = new MeanShift(dimension: 3, kernel: kernel, bandwidth: 2);

            // Compute the algorithm, retrieving an integer array
            //  containing the labels for each of the observations
            int[] labels = meanShift.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 = meanShift.Clusters.Nearest(observations);
            Assert.IsTrue(labels.IsEqual(labels2));

            // the data must not have changed!
            Assert.IsTrue(orig.IsEqual(observations));

            Assert.AreEqual(3 / 9.0, meanShift.Clusters.Proportions[labels[6]], 1e-6);
            Assert.AreEqual(2 / 9.0, meanShift.Clusters.Proportions[labels[0]], 1e-6);
            Assert.AreEqual(4 / 9.0, meanShift.Clusters.Proportions[labels[2]], 1e-6);
        }