public void LogProbabilityMassFunctionTest()
        {
            MultinomialDistribution dist = new MultinomialDistribution(5, 0.25, 0.25, 0.25, 0.25);

            int[] observation = { 1, 1, 1, 2 };

            double actual   = dist.LogProbabilityMassFunction(observation);
            double expected = System.Math.Log(0.058593750);

            Assert.AreEqual(expected, actual, 1e-6);
        }
        public void LogProbabilityMassFunctionTest()
        {
            MultivariateDiscreteDistribution target = new MultinomialDistribution(5, 0.25, 0.25, 0.25, 0.25);

            int[] observation = { 1, 1, 1, 2 };

            double expected = System.Math.Log(target.ProbabilityMassFunction(observation));
            double actual   = target.LogProbabilityMassFunction(observation);

            Assert.AreEqual(expected, actual, 1e-6);
        }
        public void ConstructorTest()
        {
            int numberOfTrials = 5;

            double[] probabilities = { 0.25, 0.75 };

            // Create a new Multinomial distribution with 5 trials for 2 symbols
            var dist = new MultinomialDistribution(numberOfTrials, probabilities);

            int dimensions = dist.Dimension;                               // 2

            double[] mean   = dist.Mean;                                   // {  1.25, 3.75 }
            double[] median = dist.Median;                                 // {  1.25, 3.75 }
            double[] var    = dist.Variance;                               // { -0.9375, -0.9375 }

            double pdf1 = dist.ProbabilityMassFunction(new[] { 2, 3 });    // 0.26367187499999994
            double pdf2 = dist.ProbabilityMassFunction(new[] { 1, 4 });    // 0.3955078125
            double pdf3 = dist.ProbabilityMassFunction(new[] { 5, 0 });    // 0.0009765625
            double lpdf = dist.LogProbabilityMassFunction(new[] { 1, 4 }); // -0.9275847384929139


            string str = dist.ToString(CultureInfo.InvariantCulture);

            // output is "Multinomial(x; n = 5, p = { 0.25, 0.75 })"

            Assert.AreEqual(1.25, mean[0]);
            Assert.AreEqual(3.75, mean[1]);
            Assert.AreEqual(1.25, median[0]);
            Assert.AreEqual(3.75, median[1]);
            Assert.AreEqual(-0.9375, var[0]);
            Assert.AreEqual(-0.9375, var[1]);
            Assert.AreEqual(0.26367187499999994, pdf1);
            Assert.AreEqual(0.3955078125, pdf2);
            Assert.AreEqual(0.0009765625, pdf3);
            Assert.AreEqual(-0.9275847384929139, lpdf);
            Assert.AreEqual("Multinomial(x; n = 5, p = { 0.25, 0.75 })", str);
        }