예제 #1
0
 /// <summary>
 /// Returns the value of the probability distribution function.
 /// </summary>
 /// <param name="x">Value</param>
 /// <returns>float precision floating point number</returns>
 public float Distribution(float x)
 {
     if (x < 0)
     {
         return(0);
     }
     return(0.5f + 0.5f * Special.Erf((Maths.Log(x) - mu) / Maths.Sqrt(sigma * Maths.Sqrt2)));
 }
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   this distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">A single point in the distribution range.</param>
        ///
        /// <remarks>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.
        /// </remarks>
        ///
        public override double DistributionFunction(double x)
        {
            double y = Math.Abs(x);

            double den = Math.Sqrt(2) * sigma;
            double a   = (y + mu) / den;
            double b   = (y - mu) / den;

            double cdf = 0.5 * (Special.Erf(a) + Special.Erf(b));

            return(cdf);
        }
예제 #3
0
 private double F(double x)          // Standard Normal Cumulative Probability Distribution Function
 {
     if (x > 0)
     {
         var arg = x / Math.Sqrt(2);
         return(0.5 * (1 + Special.Erf(arg)));
     }
     else
     {
         var arg = -x / Math.Sqrt(2);
         return(0.5 * (1 - Special.Erf(arg)));
     }
 }
예제 #4
0
        public void InverseErfTest()
        {
            for (int i = 0; i < 100; i++)
            {
                double expected = i / 100.0;
                double erf      = Special.Erf(expected);
                double actual   = Special.Ierf(erf);

                Assert.AreEqual(expected, actual, 1e-15);

                Assert.IsFalse(double.IsNaN(expected));
                Assert.IsFalse(double.IsNaN(actual));
            }
        }
예제 #5
0
        /// <summary>
        ///   von-Mises cumulative distribution function.
        /// </summary>
        ///
        /// <remarks>
        ///   This method implements the Von-Mises CDF calculation code
        ///   as given by Geoffrey Hill on his original FORTRAN code and
        ///   shared under the GNU LGPL license.
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description>Geoffrey Hill, ACM TOMS Algorithm 518,
        ///     Incomplete Bessel Function I0: The von Mises Distribution,
        ///     ACM Transactions on Mathematical Software, Volume 3, Number 3,
        ///     September 1977, pages 279-284.</description></item>
        ///   </list></para>
        /// </remarks>
        ///
        /// <param name="x">The point where to calculate the CDF.</param>
        /// <param name="mu">The location parameter μ (mu).</param>
        /// <param name="kappa">The concentration parameter κ (kappa).</param>
        ///
        /// <returns>The value of the von-Mises CDF at point <paramref name="x"/>.</returns>
        ///
        public static double DistributionFunction(double x, double mu, double kappa)
        {
            double a1  = 12.0;
            double a2  = 0.8;
            double a3  = 8.0;
            double a4  = 1.0;
            double c1  = 56.0;
            double ck  = 10.5;
            double cdf = 0;

            if (x - mu <= -Math.PI)
            {
                return(0);
            }

            if (Math.PI <= x - mu)
            {
                return(1.0);
            }

            double z = kappa;

            double u = (x - mu + Math.PI) % (2.0 * Math.PI);

            if (u < 0.0)
            {
                u = u + 2.0 * Math.PI;
            }

            double y = u - Math.PI;

            if (z <= ck)
            {
                double v = 0.0;

                if (0.0 < z)
                {
                    double ip = Math.Floor(z * a2 - a3 / (z + a4) + a1);
                    double p  = ip;
                    double s  = Math.Sin(y);
                    double c  = Math.Cos(y);
                    y = p * y;
                    double sn = Math.Sin(y);
                    double cn = Math.Cos(y);
                    double r  = 0.0;
                    z = 2.0 / z;

                    for (int n = 2; n <= ip; n++)
                    {
                        p  = p - 1.0;
                        y  = sn;
                        sn = sn * c - cn * s;
                        cn = cn * c + y * s;
                        r  = 1.0 / (p * z + r);
                        v  = (sn / p + v) * r;
                    }
                }

                cdf = (u * 0.5 + v) / Math.PI;
            }
            else
            {
                double c = 24.0 * z;
                double v = c - c1;
                double r = Math.Sqrt((54.0 / (347.0 / v + 26.0 - c) - 6.0 + c) / 12.0);
                z = Math.Sin(0.5 * y) * r;
                double s = 2.0 * z * z;
                v = v - s + 3.0;
                y = (c - s - s - 16.0) / 3.0;
                y = ((s + 1.75) * s + 83.5) / v - y;
                double arg  = z * (1.0 - s / (y * y));
                double erfx = Special.Erf(arg);
                cdf = 0.5 * erfx + 0.5;
            }

            cdf = Math.Max(cdf, 0.0);
            cdf = Math.Min(cdf, 1.0);

            return(cdf);
        }
예제 #6
0
 /// <summary>
 /// Cumulative distribution function.
 /// </summary>
 public double CDF(double x)
 {
     return((1 + Special.Erf(x / Sqrt2)) / 2);
 }
예제 #7
0
        public static double[] Laplace(double[] array, double avarage, double disp) // знаходимо функцію лапласа
        {
            double[] fixedArrayValues = new double[21];
            for (int i = 0; i < 21; i++)
            {
                fixedArrayValues[i] = (array[i] - avarage) / Math.Sqrt(disp);
            }

            double[] laplaceValues = new double[21];
            for (int i = 0; i < 21; i++)
            {
                laplaceValues[i] = (1 / Math.Sqrt(2 * Math.PI)) * (Math.Sqrt(Math.PI) * (Special.Erf(fixedArrayValues[i] / Math.Sqrt(2)) + 1)) / Math.Sqrt(2);
            }
            return(laplaceValues);
        }
예제 #8
0
파일: Gaussian.cs 프로젝트: asiryan/UMapx
 /// <summary>
 /// Returns the value of the probability distribution function.
 /// </summary>
 /// <param name="x">Value</param>
 /// <returns>float precision floating point number</returns>
 public float Distribution(float x)
 {
     return(0.5f + 0.5f * Special.Erf((x - mu) / Maths.Sqrt(2.0f * sigma * sigma)));
 }
예제 #9
0
 /// <summary>
 ///   Normal cumulative distribution function.
 /// </summary>
 ///
 /// <returns>
 ///   The area under the Gaussian p.d.f. integrated
 ///   from minus infinity to the given value.
 /// </returns>
 ///
 public static double Log(double value)
 {
     return(0.5 * Special.Log1p(Special.Erf(value / Constants.Sqrt2)));
 }
예제 #10
0
 /// <summary>
 ///   Normal cumulative distribution function.
 /// </summary>
 ///
 /// <returns>
 ///   The area under the Gaussian p.d.f. integrated
 ///   from minus infinity to the given value.
 /// </returns>
 ///
 public static double Function(double value)
 {
     return(0.5 + 0.5 * Special.Erf(value / Constants.Sqrt2));
 }