Example #1
0
        public void FitTest2()
        {
            int[]             symbols = { 3, 5 };
            JointDistribution target  = new JointDistribution(symbols);

            double[][] observations =
            {
                new double[] { 0, 0 },
                new double[] { 1, 1 },
                new double[] { 2, 1 },
            };

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

            target.Fit(observations, weights);

            double[] p = target.Frequencies;

            double actual;

            actual = target.ProbabilityMassFunction(new[] { 0, 0 });
            Assert.AreEqual(0.5, actual);

            actual = target.ProbabilityMassFunction(new[] { 1, 1 });
            Assert.AreEqual(0.25, actual);

            actual = target.ProbabilityMassFunction(new[] { 2, 1 });
            Assert.AreEqual(0.25, actual);
        }
        public void FitTest_vector_inputs()
        {
            double[] expected = { 0.50, 0.00, 0.25, 0.25 };

            JointDistribution target;

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

            Assert.IsTrue(Matrix.IsEqual(expected, actual));
        }
        public void FitTest3()
        {
            JointDistribution target = new JointDistribution(new[] { -1 }, new[] { 4 });

            double[] values  = { 0.00, 1.00, 2.00, 3.00 };
            double[] weights = { 0.25, 0.25, 0.25, 0.25 };

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

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

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