public void FitTest2()
        {
            double[][] observations =
            {
                new double[] { 1, 2 },
                new double[] { 1, 2 },
                new double[] { 1, 2 },
                new double[] { 1, 2 }
            };


            var target = new MultivariateNormalDistribution(2);

            bool thrown = false;

            try { target.Fit(observations); }
            catch (NonPositiveDefiniteMatrixException) { thrown = true; }

            Assert.IsTrue(thrown);

            NormalOptions options = new NormalOptions()
            {
                Regularization = double.Epsilon
            };

            // No exception thrown
            target.Fit(observations, options);
        }
Пример #2
0
        public void FitTest5()
        {
            double[][] observations =
            {
                new double[] { 1, 2 },
                new double[] { 1, 2 },
                new double[] { 0, 1 },
                new double[] { 5, 7 }
            };

            double[] weights = { 1, 1, 0, 0 };

            var target = new MultivariateNormalDistribution(2);

            bool thrown = false;

            try { target.Fit(observations, weights); }
            catch (NonPositiveDefiniteMatrixException) { thrown = true; }

            Assert.IsTrue(thrown);

            NormalOptions options = new NormalOptions()
            {
                Robust = true
            };

            // No exception thrown
            target.Fit(observations, weights, options);

            checkDegenerate(target);
        }
        public void FitTest3()
        {
            double[][] observations =
            {
                new double[] { 1, 2 },
                new double[] { 2, 4 },
                new double[] { 3, 6 },
                new double[] { 4, 8 }
            };


            var target = new MultivariateNormalDistribution(2);

            NormalOptions options = new NormalOptions()
            {
                Robust = true
            };

            target.Fit(observations, options);

            double pdf = target.ProbabilityDensityFunction(4, 2);
            double cdf = target.DistributionFunction(4, 2);
            bool   psd = target.Covariance.IsPositiveDefinite();

            Assert.AreEqual(0.043239154739844896, pdf);
            Assert.AreEqual(0.12263905840338646, cdf);
            Assert.IsFalse(psd);
        }
Пример #4
0
        /// <summary>
        ///   Estimates a new Normal distribution from a given set of observations.
        /// </summary>
        ///
        /// <example>
        ///   Please see <see cref="MultivariateNormalDistribution"/>.
        /// </example>
        ///
        public static MultivariateNormalDistribution Estimate(double[][] observations, double[] weights, NormalOptions options)
        {
            MultivariateNormalDistribution n = new MultivariateNormalDistribution(observations[0].Length);

            n.Fit(observations, weights, options);
            return(n);
        }
Пример #5
0
        public void FitTest()
        {
            double[][] observations =
            {
                new double[] { 0.1000, -0.2000 },
                new double[] { 0.4000,  0.6000 },
                new double[] { 2.0000,  0.2000 },
                new double[] { 2.0000,  0.3000 }
            };

            double[] mean = Accord.Statistics.Tools.Mean(observations);
            double[,] cov = Accord.Statistics.Tools.Covariance(observations);

            {
                var target = new MultivariateNormalDistribution(2);

                double[] weigths = { 0.25, 0.25, 0.25, 0.25 };

                target.Fit(observations, weigths);

                Assert.IsTrue(Matrix.IsEqual(mean, target.Mean));
                Assert.IsTrue(Matrix.IsEqual(cov, target.Covariance, 1e-10));
            }

            {
                var target = new MultivariateNormalDistribution(2);

                double[] weigths = { 1, 1, 1, 1 };

                target.Fit(observations, weigths);

                Assert.IsTrue(Matrix.IsEqual(mean, target.Mean));
                Assert.IsTrue(Matrix.IsEqual(cov, target.Covariance, 1e-10));
            }
        }
Пример #6
0
        public void EstimateDistribution(List <double[]> inputs)
        {
            var normal = new MultivariateNormalDistribution(3);

            normal.Fit(inputs.ToArray(), new NormalOptions()
            {
                Robust = true
            });
        }