private static void test(GeneralizedNormalDistribution target, UnivariateContinuousDistribution normal)
        {
            Assert.AreEqual(normal.Mean, target.Mean);
            Assert.AreEqual(normal.Variance, target.Variance, 1e-10);
            Assert.AreEqual(normal.Entropy, target.Entropy, 1e-10);
            Assert.AreEqual(normal.StandardDeviation, target.StandardDeviation, 1e-10);
            Assert.AreEqual(normal.Mode, target.Mode);
            Assert.AreEqual(normal.Median, target.Median);

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.ProbabilityDensityFunction(x);
                double expected = normal.ProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, 1e-15);
                Assert.IsFalse(Double.IsNaN(actual));
            }

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.LogProbabilityDensityFunction(x);
                double expected = normal.LogProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, 1e-10);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
Example #2
0
        private static void compare(TukeyLambdaDistribution target,
                                    UnivariateContinuousDistribution comparison, double tol)
        {
            Assert.AreEqual(comparison.Mean, target.Mean);
            Assert.AreEqual(comparison.Variance, target.Variance, tol);
            Assert.AreEqual(comparison.Entropy, target.Entropy, 1e-4);
            Assert.AreEqual(comparison.StandardDeviation, target.StandardDeviation, tol);
            Assert.AreEqual(comparison.Mode, target.Mode);
            Assert.AreEqual(comparison.Median, target.Median);

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.ProbabilityDensityFunction(x);
                double expected = comparison.ProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.DistributionFunction(x);
                double expected = comparison.DistributionFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }

            for (double x = -10; x < 10; x += 0.0001)
            {
                double actual   = target.LogProbabilityDensityFunction(x);
                double expected = comparison.LogProbabilityDensityFunction(x);
                Assert.AreEqual(expected, actual, tol);
                Assert.IsFalse(Double.IsNaN(actual));
            }
        }
        public void LogProbabilityDensityFunctionTest()
        {
            UnivariateContinuousDistribution target = CreateUnivariateContinuousDistribution();
            double x        = 18.14;
            double expected = System.Math.Log(0.011697993604177);
            double actual   = target.LogProbabilityDensityFunction(x);

            Assert.IsFalse(double.IsNaN(actual));
            Assert.AreEqual(expected, actual, 1e-10);
        }
 /// <summary>
 /// Get the probability of occurence of <paramref name="value"/> in the given <paramref name="distribution"/>.
 /// The least not 0, but epsilon.
 /// <summary>
 double GetProbability(UnivariateContinuousDistribution distribution, double value)
 {
     try
     {
         var p = distribution.LogProbabilityDensityFunction(value);
         return(p);
     }
     catch (InvalidOperationException)
     {
         return(Math.Log(epsilon));
     }
 }