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

            var d = (x - _location) / _scale;

            return(SpecialFunctions.GammaLn((_freedom + 1.0) / 2.0)
                   - (0.5 * ((_freedom + 1.0) * Math.Log(1.0 + (d * d / _freedom))))
                   - SpecialFunctions.GammaLn(_freedom / 2.0)
                   - (0.5 * Math.Log(_freedom * Math.PI)) - Math.Log(_scale));
        }
示例#2
0
        /// <summary>
        /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂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 log density at <paramref name="x"/>.</returns>
        /// <seealso cref="DensityLn"/>
        public static double PDFLn(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.PDFLn(location, scale, x));
            }

            var d = (x - location) / scale;

            return(SpecialFunctions.GammaLn((freedom + 1.0) / 2.0)
                   - (0.5 * ((freedom + 1.0) * Math.Log(1.0 + (d * d / freedom))))
                   - SpecialFunctions.GammaLn(freedom / 2.0)
                   - (0.5 * Math.Log(freedom * Math.PI)) - Math.Log(scale));
        }
示例#3
0
        /// <summary>
        /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂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 log density at <paramref name="x"/>.</returns>
        /// <seealso cref="DensityLn"/>
        public static double PDFLn(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.PDFLn(location, Constants.Sqrt2 * scale, x));
            }
            if (alpha == 1d && beta == 0d)
            {
                return(Cauchy.PDFLn(location, scale, x));
            }

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

            throw new NotSupportedException();
        }