Accord.Tests.MachineLearning.GaussianMixtureModelTest.LargeSampleTest C# (CSharp) Method

LargeSampleTest() private method

private LargeSampleTest ( ) : void
return void
        public void LargeSampleTest()
        {
            Accord.Math.Tools.SetupGenerator(0);

            Func<double> r = () => Tools.Random.NextDouble();
            Func<double> b = () => Tools.Random.NextDouble() > 0.3 ? 1 : -1;

            // Test Samples
            int thousand = 1000;
            int million = thousand * thousand;
            double[][] samples = new double[5 * million][];

            Func<int, double[]> expand = (int label) =>
                {
                    var d = new double[10];
                    d[label] = 1;
                    return d;
                };

            for (int j = 0; j < samples.Length; j++)
            {
                if (j % 10 > 8)
                    samples[j] = new double[] { r() }.Concatenate(expand(Tools.Random.Next() % 10));
                else samples[j] = new double[] { r() * j }.Concatenate(expand(j % 10));
            }


            // Create a new Gaussian Mixture Model with 2 components
            GaussianMixtureModel gmm = new GaussianMixtureModel(5);

            // Compute the model
            double result = gmm.Compute(samples, new GaussianMixtureModelOptions()
            {
                NormalOptions = new NormalOptions()
                {
                    Regularization = 1e-5,
                }
            });


            for (int i = 0; i < samples.Length; i++)
            {
                var sample = samples[i];
                int c = gmm.Gaussians.Nearest(sample);

                Assert.AreEqual(c, (i % 10) >= 5 ? 1 : 0);
            }
        }
    }