Accord.Tests.Statistics.MultivariateMixtureDistributionTest.MixtureWeightsFitTest C# (CSharp) Méthode

MixtureWeightsFitTest() private méthode

private MixtureWeightsFitTest ( ) : void
Résultat void
        public void MixtureWeightsFitTest()
        {
            // Randomly initialize some mixture components
            MultivariateNormalDistribution[] components = new MultivariateNormalDistribution[2];
            components[0] = new MultivariateNormalDistribution(new double[] { 2 }, new double[,] { { 1 } });
            components[1] = new MultivariateNormalDistribution(new double[] { 5 }, new double[,] { { 1 } });

            // Create an initial mixture
            var mixture = new MultivariateMixture<MultivariateNormalDistribution>(components);

            // Now, suppose we have a weighted data
            // set. Those will be the input points:

            double[][] points = new double[] { 0, 3, 1, 7, 3, 5, 1, 2, -1, 2, 7, 6, 8, 6 } // (14 points)
                .ToJagged();

            // And those are their respective unnormalized weights:
            double[] weights = { 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 2, 3, 1, 1 }; // (14 weights)

            // Let's normalize the weights so they sum up to one:
            weights = weights.Divide(weights.Sum());

            // Now we can fit our model to the data:
            mixture.Fit(points, weights);   // done!

            // Our model will be:
            double mean1 = mixture.Components[0].Mean[0]; // 1.41126
            double mean2 = mixture.Components[1].Mean[0]; // 6.53301

            // With mixture coefficients
            double pi1 = mixture.Coefficients[0]; // 0.51408489193241225
            double pi2 = mixture.Coefficients[1]; // 0.48591510806758775

            Assert.AreEqual(1.4112610766836409, mean1);
            Assert.AreEqual(6.5330177004151064, mean2);

            Assert.AreEqual(0.51408489193241214, pi1);
            Assert.AreEqual(0.48591510806758781, pi2);

/*
            // If we need the GaussianMixtureModel functionality, we can
            // use the estimated mixture to initialize a new model:
            GaussianMixtureModel gmm = new GaussianMixtureModel(mixture);

            Assert.AreEqual(mean1, gmm.Gaussians[0].Mean[0]);
            Assert.AreEqual(mean2, gmm.Gaussians[1].Mean[0]);

            Assert.AreEqual(1.4112610766836404, mean1, 1e-10);
            Assert.AreEqual(6.5330177004151082, mean2, 1e-10);

            Assert.AreEqual(mixture.Coefficients[0], gmm.Gaussians[0].Proportion);
            Assert.AreEqual(mixture.Coefficients[1], gmm.Gaussians[1].Proportion);
 */ 
        }