Inheritance: DistributionBase, IDistribution, IUnivariateDistribution
 /// <summary>
 ///   Creates a new <see cref="GeneralContinuousDistribution"/> 
 ///   from an existing <see cref="UnivariateContinuousDistribution">
 ///   continuous distribution</see>.
 /// </summary>
 /// 
 /// <param name="distribution">The distribution.</param>
 /// 
 /// <returns>A <see cref="GeneralContinuousDistribution"/> representing the same
 /// <paramref name="distribution"/> but whose measures and functions are computed
 /// using numerical integration and differentiation.</returns>
 /// 
 public static GeneralContinuousDistribution FromDistribution(UnivariateContinuousDistribution distribution)
 {
     GeneralContinuousDistribution dist = new GeneralContinuousDistribution();
     dist.support = distribution.Support;
     dist.pdf = distribution.ProbabilityDensityFunction;
     dist.cdf = distribution.DistributionFunction;
     return dist;
 }
        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));
            }
        }
        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));
            }
        }
        /// <summary>
        ///   Creates a new <see cref="GeneralContinuousDistribution"/> with the given PDF and CDF functions.
        /// </summary>
        /// 
        /// <param name="distribution">A distribution whose properties will be numerically estimated.</param>
        /// 
        public GeneralContinuousDistribution(UnivariateContinuousDistribution distribution)
        {
            if (distribution == null)
                throw new ArgumentNullException("distribution");

            this.method = new InfiniteAdaptiveGaussKronrod(100);
            this.pdf = distribution.ProbabilityDensityFunction;
            this.cdf = distribution.DistributionFunction;
            this.support = distribution.Support;
        }