Beispiel #1
0
        /// <summary>
        /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
        /// </summary>
        /// <param name="x">The location at which to compute the density.</param>
        /// <returns>the density at <paramref name="x"/>.</returns>
        public double Density(double x)
        {
            // TODO JVG we can probably do a better job for Cauchy special case
            if (_freedom >= 1e+8d)
            {
                return(Normal.PDF(_location, _scale, x));
            }

            var d = (x - _location) / _scale;

            return(Math.Exp(SpecialFunctions.GammaLn((_freedom + 1.0) / 2.0) - SpecialFunctions.GammaLn(_freedom / 2.0))
                   * Math.Pow(1.0 + (d * d / _freedom), -0.5 * (_freedom + 1.0))
                   / Math.Sqrt(_freedom * Math.PI)
                   / _scale);
        }
Beispiel #2
0
        /// <summary>
        /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
        /// </summary>
        /// <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>
        /// <param name="x">The location at which to compute the density.</param>
        /// <returns>the density at <paramref name="x"/>.</returns>
        /// <seealso cref="Density"/>
        public static double PDF(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 (freedom >= 1e+8d)
            {
                return(Normal.PDF(location, scale, x));
            }

            var d = (x - location) / scale;

            return(Math.Exp(SpecialFunctions.GammaLn((freedom + 1.0) / 2.0) - SpecialFunctions.GammaLn(freedom / 2.0))
                   * Math.Pow(1.0 + (d * d / freedom), -0.5 * (freedom + 1.0))
                   / Math.Sqrt(freedom * Math.PI)
                   / scale);
        }
Beispiel #3
0
        /// <summary>
        /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
        /// </summary>
        /// <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>
        /// <param name="x">The location at which to compute the density.</param>
        /// <returns>the density at <paramref name="x"/>.</returns>
        /// <seealso cref="Density"/>
        public static double PDF(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.PDF(location, Constants.Sqrt2 * scale, x));
            }
            if (alpha == 1d && beta == 0d)
            {
                return(Cauchy.PDF(location, scale, x));
            }

            if (alpha == 0.5d && beta == 1d && x >= location)
            {
                return((Math.Sqrt(scale / Constants.Pi2) * Math.Exp(-scale / (2 * (x - location)))) / Math.Pow(x - location, 1.5));
            }

            throw new NotSupportedException();
        }