Пример #1
0
        public void JointDistributionConstructorTest()
        {
            int[]             symbols = { 3, 5 };
            JointDistribution target  = new JointDistribution(symbols);

            double[] p = target.Frequencies;

            Assert.AreEqual(3 * 5, p.Length);

            for (int i = 0; i < p.Length; i++)
            {
                p[i] = i;
            }

            double actual;

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

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

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

            actual = target.ProbabilityMassFunction(new int[] { 2, 4 });
            Assert.AreEqual(14, actual);
        }
Пример #2
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);
        }
Пример #3
0
        public void UniformTest()
        {
            int a = 2;
            int b = 5;
            int n = b - a + 1;

            // Wikipedia definitions
            double expectedMean = (a + b) / 2.0;
            double expectedVar  = (System.Math.Pow(b - a + 1, 2) - 1) / 12.0;
            double p            = 1.0 / n;


            JointDistribution dist = JointDistribution.Uniform(1, a, b);

            Assert.AreEqual(expectedMean, dist.Mean[0]);
            // Assert.AreEqual(expectedVar, dist.Variance);
            Assert.AreEqual(n, dist.Frequencies.Length);


            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 0 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 1 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 2 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 3 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 4 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 5 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 6 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 7 }));
        }
Пример #4
0
        public void ProbabilityMassFunctionTest()
        {
            JointDistribution dist = JointDistribution.Uniform(1, 2, 5);
            double            p    = 0.25;

            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 0 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 1 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 2 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 3 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 4 }));
            Assert.AreEqual(p, dist.ProbabilityMassFunction(new[] { 5 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 6 }));
            Assert.AreEqual(0, dist.ProbabilityMassFunction(new[] { 7 }));
        }