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 }
            };

            var target = new MultivariateEmpiricalDistribution(observations);

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

            bool thrown = false;

            try
            {
                target.Fit(observations, weigths);
            }
            catch (ArgumentException)
            {
                thrown = true;
            }

            Assert.IsTrue(thrown);
        }
        public void FitTest2()
        {
            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 MultivariateEmpiricalDistribution(observations);

            target.Fit(observations);

            Assert.IsTrue(Matrix.IsEqual(mean, target.Mean));
            Assert.IsTrue(Matrix.IsEqual(cov, target.Covariance, 1e-10));
        }
        public void FitTest()
        {
            double[] original     = { 5, 5, 1, 4, 1, 2, 2, 3, 3, 3, 4, 3, 3, 3, 4, 3, 2, 3 };
            var      distribution = new MultivariateEmpiricalDistribution(original.ToJagged());

            int[]      weights = { 2, 1, 1, 1, 2, 3, 1, 3, 1, 1, 1, 1 };
            double[]   sources = { 5, 1, 4, 1, 2, 3, 4, 3, 4, 3, 2, 3 };
            double[][] samples = sources.ToJagged();
            var        target  = new MultivariateEmpiricalDistribution(Jagged.Zeros(1, 1));

            target.Fit(samples, weights);

            Assert.AreEqual(distribution.Mean[0], target.Mean[0]);
            Assert.AreEqual(distribution.Median[0], target.Median[0]);
            Assert.AreEqual(distribution.Mode[0], target.Mode[0]);
            Assert.AreEqual(distribution.Smoothing[0, 0], target.Smoothing[0, 0]);
            Assert.AreEqual(distribution.Variance[0], target.Variance[0]);
            Assert.IsTrue(target.Weights.IsEqual(weights.Divide(weights.Sum())));
            Assert.AreEqual(target.Samples, samples);

            for (double x = 0; x < 6; x += 0.1)
            {
                double actual, expected;
                expected = distribution.ComplementaryDistributionFunction(x);
                actual   = target.ComplementaryDistributionFunction(x);
                Assert.AreEqual(expected, actual);

                expected = distribution.DistributionFunction(x);
                actual   = target.DistributionFunction(x);
                Assert.AreEqual(expected, actual);

                expected = distribution.LogProbabilityDensityFunction(x);
                actual   = target.LogProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, 1e-15);

                expected = distribution.ProbabilityDensityFunction(x);
                actual   = target.ProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, 1e-15);
            }
        }