Fit() public method

Fits the underlying distribution to a given set of observations.
public Fit ( double observations, double weights ) : IDistribution
observations double /// The array of observations to fit the model against. ///
weights double /// The weight vector containing the weight for each of the samples. ///
return IDistribution
        public void FitTest2()
        {
            double[] expected = { 0.50, 0.00, 0.25, 0.25 };

            GeneralDiscreteDistribution target;

            double[] values = { 0.00, 2.00, 3.00 };
            double[] weights = { 0.50, 0.25, 0.25 };
            target = new GeneralDiscreteDistribution(4);
            target.Fit(values, weights);
            double[] actual = target.Frequencies;

            Assert.IsTrue(Matrix.IsEqual(expected, actual));

            // --

            double[] values2 = { 0.00, 0.00, 2.00, 3.00 };
            double[] weights2 = { 0.25, 0.25, 0.25, 0.25 };
            target = new GeneralDiscreteDistribution(4);
            target.Fit(values2, weights2);
            double[] actual2 = target.Frequencies;
            Assert.IsTrue(Matrix.IsEqual(expected, actual2));
        }
        public void FitTest_vector_inputs()
        {
            double[] expected = { 0.50, 0.00, 0.25, 0.25 };

            GeneralDiscreteDistribution target;

            double[] values = { 0.00, 2.00, 3.00 };
            double[] weights = { 0.50, 0.25, 0.25 };
            target = new GeneralDiscreteDistribution(4);
            target.Fit(values, weights);
            double[] actual = target.Frequencies;

            Assert.IsTrue(Matrix.IsEqual(expected, actual));

            // --

            double[][] values2 = 
            {
                new[] { 1.00, 0.00, 0.00, 0.00 },
                new[] { 0.00, 0.00, 0.00, 0.00 },
                new[] { 0.00, 0.00, 1.00, 0.00 },
                new[] { 0.00, 0.00, 0.00, 1.00 },
            };

            double[] weights2 = { 0.50, 0.00, 0.25, 0.25 };

            target = new GeneralDiscreteDistribution(4);
            target.Fit(values2, weights2);
            double[] actual2 = target.Frequencies;
            Assert.IsTrue(Matrix.IsEqual(expected, actual2));


            double[][] values3 = 
            {
                new[] { 1.00, 0.00, 0.00, 0.00 },
                new[] { 0.00, 1.00, 0.00, 0.00 },
                new[] { 0.00, 0.00, 1.00, 0.00 },
                new[] { 0.00, 0.00, 0.00, 1.00 },
            };

            double[] weights3 = { 0.50, 0.00, 0.25, 0.25 };

            target = new GeneralDiscreteDistribution(4);
            target.Fit(values3, weights3);
            double[] actual3 = target.Frequencies;
            Assert.IsTrue(Matrix.IsEqual(expected, actual3));


            double[][] values4 = 
            {
                new[] { 0.50, 0.00, 0.00, 0.00 },
                new[] { 0.00, 0.00, 0.00, 0.00 },
                new[] { 0.00, 0.00, 0.25, 0.00 },
                new[] { 0.00, 0.00, 0.00, 0.25 },
            };

            target = new GeneralDiscreteDistribution(4);
            target.Fit(values4);
            double[] actual4 = target.Frequencies;
            Assert.IsTrue(Matrix.IsEqual(expected, actual4));
        }
        public void GenerateTest()
        {
            double[] transProbRow = { 0.2, 0.5, 0.3 };
            var gdd = new GeneralDiscreteDistribution(transProbRow);
            int n = 100000;
            {
                int[] samples = gdd.Generate(n);
                var target = new GeneralDiscreteDistribution(3);
                target.Fit(samples);
                Assert.AreEqual(0.2, target.Frequencies[0], 0.01);
                Assert.AreEqual(0.5, target.Frequencies[1], 0.01);
                Assert.AreEqual(0.3, target.Frequencies[2], 0.01);
            }

            {
                int[] samples = new int[n].Apply((x) => gdd.Generate());
                var target = new GeneralDiscreteDistribution(3);
                target.Fit(samples);
                Assert.AreEqual(0.2, target.Frequencies[0], 0.01);
                Assert.AreEqual(0.5, target.Frequencies[1], 0.01);
                Assert.AreEqual(0.3, target.Frequencies[2], 0.01);
            }

            {
                double[] samples = gdd.Generate(n).ToDouble();
                var target = new GeneralDiscreteDistribution(3);
                target.Fit(samples);
                Assert.AreEqual(0.2, target.Frequencies[0], 0.01);
                Assert.AreEqual(0.5, target.Frequencies[1], 0.01);
                Assert.AreEqual(0.3, target.Frequencies[2], 0.01);
            }

            {
                double[] samples = new int[n].Apply((x) => (double)gdd.Generate());
                var target = new GeneralDiscreteDistribution(3);
                target.Fit(samples);
                Assert.AreEqual(0.2, target.Frequencies[0], 0.01);
                Assert.AreEqual(0.5, target.Frequencies[1], 0.01);
                Assert.AreEqual(0.3, target.Frequencies[2], 0.01);
            }
        }
        public void FitTest3()
        {
            GeneralDiscreteDistribution target = new GeneralDiscreteDistribution(-1, 4);
            double[] values = { 0.00, 1.00, 2.00, 3.00 };
            double[] weights = { 0.25, 0.25, 0.25, 0.25 };

            target.Fit(values.Subtract(1), weights);

            double[] expected = { 0.25, 0.25, 0.25, 0.25 };
            double[] actual = target.Frequencies;

            Assert.IsTrue(Matrix.IsEqual(expected, actual));
        }