コード例 #1
0
        /// <summary>
        /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
        /// </summary>
        /// <param name="x">The location at which to compute the cumulative distribution function.</param>
        /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
        public double CumulativeDistribution(double x)
        {
            // TODO JVG we can probably do a better job for Cauchy special case
            if (Double.IsPositiveInfinity(_freedom))
            {
                return(Normal.CDF(_location, _scale, x));
            }

            var k  = (x - _location) / _scale;
            var h  = _freedom / (_freedom + (k * k));
            var ib = 0.5 * SpecialFunctions.BetaRegularized(_freedom / 2.0, 0.5, h);

            return(x <= _location ? ib : 1.0 - ib);
        }
コード例 #2
0
ファイル: StudentT.cs プロジェクト: ulatekh/mathnet-numerics
        /// <summary>
        /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
        /// </summary>
        /// <param name="x">The location at which to compute the cumulative distribution function.</param>
        /// <param name="location">The location (μ) of the distribution.</param>
        /// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
        /// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
        /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
        /// <seealso cref="CumulativeDistribution"/>
        public static double CDF(double location, double scale, double freedom, double x)
        {
            if (scale <= 0.0 || freedom <= 0.0)
            {
                throw new ArgumentException(Resources.InvalidDistributionParameters);
            }

            // TODO JVG we can probably do a better job for Cauchy special case
            if (double.IsPositiveInfinity(freedom))
            {
                return(Normal.CDF(location, scale, x));
            }

            var k  = (x - location) / scale;
            var h  = freedom / (freedom + (k * k));
            var ib = 0.5 * SpecialFunctions.BetaRegularized(freedom / 2.0, 0.5, h);

            return(x <= location ? ib : 1.0 - ib);
        }
コード例 #3
0
        /// <summary>
        /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
        /// </summary>
        /// <param name="x">The location at which to compute the cumulative distribution function.</param>
        /// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
        /// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
        /// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
        /// <param name="location">The location (μ) of the distribution.</param>
        /// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
        /// <seealso cref="CumulativeDistribution"/>
        public static double CDF(double alpha, double beta, double scale, double location, double x)
        {
            if (alpha <= 0.0 || alpha > 2.0 || beta < -1.0 || beta > 1.0 || scale <= 0.0)
            {
                throw new ArgumentException(Resources.InvalidDistributionParameters);
            }

            if (alpha == 2d)
            {
                return(Normal.CDF(location, Constants.Sqrt2 * scale, x));
            }
            if (alpha == 1d && beta == 0d)
            {
                return(Cauchy.CDF(location, scale, x));
            }

            if (alpha == 0.5d && beta == 1d)
            {
                return(SpecialFunctions.Erfc(Math.Sqrt(scale / (2 * (x - location)))));
            }

            throw new NotSupportedException();
        }
コード例 #4
0
 internal static double CumulativeDistributionImpl(double mu, double lambda, double x)
 {
     return(Normal.CDF(0, 1, Math.Sqrt(lambda / x) * (x / mu - 1)) + Math.Exp(2 * lambda / mu) * Normal.CDF(0, 1, -Math.Sqrt(lambda / x) * (x / mu + 1)));
 }