예제 #1
0
        public double GetPValue(BitArray input)
        {
            var pi = 0.0;

            foreach (var bit in input)
            {
                if ((bool)bit)
                {
                    pi++;
                }
            }

            pi /= input.Length;

            if (Math.Abs(pi - 0.5) >= 2.0 / Math.Sqrt(input.Length))
            {
                return(0.0);
            }

            var V = 1.0;

            for (int k = 0; k < input.Length - 1; k++)
            {
                if (input[k] != input[k + 1])
                {
                    V++;
                }
            }

            var erfcArg = Math.Abs(V - 2 * input.Length * pi * (1 - pi)) / (2 * Math.Sqrt(2 * input.Length) * pi * (1 - pi));
            var pValue  = Special.Erfc(erfcArg);

            return(pValue);
        }
예제 #2
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 < mu)
            {
                return(0);
            }

            return(Special.Erfc((float)Math.Sqrt(scale / (2 * (x - mu)))));
        }
예제 #3
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)
        {
            float a = (float)Math.Sqrt(x);
            float b = (float)Math.Sqrt(1.0 / x);
            float z = (a - b) / gamma;

            // Normal cumulative distribution function
            return(Special.Erfc(-z / 1.4142135623731f) * 0.5f);
        }
예제 #4
0
        /// <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>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// </remarks>
        ///
        public override double DistributionFunction(double x)
        {
            double a = Math.Sqrt(x);
            double b = Math.Sqrt(1.0 / x);
            double z = (a - b) / shape;

            // Normal cumulative distribution function
            return(Special.Erfc(-z / Constants.Sqrt2) * 0.5);
        }
        /// <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>
        ///
        /// <example>
        ///   See <see cref="InverseGaussianDistribution"/>.
        /// </example>
        ///
        protected internal override double InnerDistributionFunction(double x)
        {
            double sqrt = Math.Sqrt(lambda / x);

            double a = 0.5 * Special.Erfc(sqrt * (mean - x) / (Constants.Sqrt2 * mean));
            double b = 0.5 * Special.Erfc(sqrt * (mean + x) / (Constants.Sqrt2 * mean));
            double c = Math.Exp((2.0 * lambda) / mean);

            return(a + b * c);
        }
예제 #6
0
        /// <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)
        {
            if (x < location)
            {
                return(0);
            }

            double cdf = Special.Erfc(Math.Sqrt(scale / (2 * (x - location))));

            return(cdf);
        }
예제 #7
0
        /// <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>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// </remarks>
        ///
        protected internal override double InnerDistributionFunction(double x)
        {
            double c = x - location;

            double a = Math.Sqrt(c);
            double b = Math.Sqrt(1.0 / c);
            double z = (a - b) / shape;

            // Normal cumulative distribution function
            return(Special.Erfc(-z / Constants.Sqrt2) * 0.5);
        }
예제 #8
0
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this Log-Normal distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        /// <remarks>
        ///
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        ///
        /// <para>
        ///  The calculation is computed through the relationship to the error function
        ///  as <see cref="Accord.Math.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2. See
        ///  [Weisstein] for more details.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description>
        ///       Weisstein, Eric W. "Normal Distribution Function." From MathWorld--A Wolfram Web
        ///       Resource. http://mathworld.wolfram.com/NormalDistributionFunction.html </description></item>
        ///   </list></para>
        /// </remarks>
        ///
        /// <example>
        ///   See <see cref="LognormalDistribution"/>.
        /// </example>
        ///
        public override double DistributionFunction(double x)
        {
            if (x <= 0)
            {
                return(0.0);
            }

            double z = (Math.Log(x) - location) / shape;

            return(0.5 * Special.Erfc(-z / Constants.Sqrt2));
        }
예제 #9
0
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this Normal distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        ///
        /// <remarks>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// <para>
        ///  The calculation is computed through the relationship to the error function
        ///  as <see cref="Accord.Math.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description>
        ///       Weisstein, Eric W. "Normal Distribution." From MathWorld--A Wolfram Web Resource.
        ///       Available on: http://mathworld.wolfram.com/NormalDistribution.html </description></item>
        ///     <item><description><a href="http://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function">
        ///       Wikipedia, The Free Encyclopedia. Normal distribution. Available on:
        ///       http://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function </a></description></item>
        ///   </list></para>
        /// </remarks>
        ///
        public override double DistributionFunction(double x)
        {
            double z = (x - mean) / stdDev;

            return(Special.Erfc(-z / Special.Sqrt2) * 0.5);

            /*
             *  // For a normal distribution with zero variance, the cdf is the Heaviside
             *  // step function (Wipedia, http://en.wikipedia.org/wiki/Normal_distribution)
             *  return (x >= mean) ? 1.0 : 0.0;
             */
        }
예제 #10
0
        /// <summary>
        /// Returns the value of the probability density function.
        /// </summary>
        /// <param name="x">Value</param>
        /// <returns>float precision floating point number</returns>
        public float Function(float x)
        {
            float c = x - mu;

            float a = (float)Math.Sqrt(c / beta);
            float b = (float)Math.Sqrt(beta / c);

            float alpha = (a + b) / (2 * gamma * c);
            float z     = (a - b) / gamma;

            // Normal cumulative distribution function
            return(alpha * Special.Erfc(-z / 1.4142135623731f) * 0.5f);
        }
예제 #11
0
        public double GetPValue(BitArray input)
        {
            var sum = 0.0;

            foreach (var bit in input)
            {
                sum += (bool)bit ? 1 : -1;
            }

            var stat   = Math.Abs(sum) / Math.Sqrt(input.Length);
            var pValue = Special.Erfc(stat / Math.Sqrt(2));

            return(pValue);
        }
예제 #12
0
        /// <summary>
        ///   Gets the probability density function (pdf) for
        ///   this distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">A single point in the distribution range.</param>
        ///
        /// <returns>
        ///   The probability of <c>x</c> occurring
        ///   in the current distribution.
        /// </returns>
        ///
        /// <remarks>
        /// <para>
        ///   The Probability Density Function (PDF) describes the
        ///   probability that a given value <c>x</c> will occur.</para>
        /// </remarks>
        ///
        protected internal override double InnerProbabilityDensityFunction(double x)
        {
            double c = x - location;

            double a = Math.Sqrt(c / scale);
            double b = Math.Sqrt(scale / c);

            double alpha = (a + b) / (2 * shape * c);
            double z     = (a - b) / shape;


            // Normal cumulative distribution function
            return(alpha * Special.Erfc(-z / Constants.Sqrt2) * 0.5);
        }
예제 #13
0
        public void InverseErfcTest()
        {
            for (int i = 0; i < 100; i++)
            {
                double expected = i / 100.0;
                double erfc     = Special.Erfc(expected);
                double actual   = Special.Ierfc(erfc);

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

                Assert.IsFalse(double.IsNaN(expected));
                Assert.IsFalse(double.IsNaN(actual));
            }
        }
예제 #14
0
        /// <summary>
        /// Метод, считающий p-value на основе частоты встречаемости 1 и 0
        /// </summary>
        /// <param name="hash">Псевдослучайная последовательность</param>
        /// <returns>p-value</returns>
        public double getPValue(BitArray hash)
        {
            // сумма 1 и -1
            double sum = 0;

            foreach (bool v in hash)
            {
                sum += v ? 1 : -1;
            }

            var absoluteSum = Math.Abs(sum) / Math.Sqrt(hash.Length);
            var pValue      = Special.Erfc(absoluteSum / _rootOf2); // erfc - Complementary Error Function (дополнительная функция ошибок)

            return(pValue);
        }
예제 #15
0
        /// <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>
        ///
        /// <example>
        ///   See <see cref="InverseGaussianDistribution"/>.
        /// </example>
        ///
        public override double DistributionFunction(double x)
        {
            if (x < 0)
            {
                return(0);
            }

            double sqrt = Math.Sqrt(lambda / x);

            double a = 0.5 * Special.Erfc(sqrt * (mean - x) / (Constants.Sqrt2 * mean));
            double b = 0.5 * Special.Erfc(sqrt * (mean + x) / (Constants.Sqrt2 * mean));
            double c = Math.Exp((2.0 * lambda) / mean);

            return(a + b * c);
        }
예제 #16
0
파일: RunsAlg.cs 프로젝트: danmoka/blake
        // ошибка в описании теста (2-6): (2) написано, что НЕ запускать тест, если
        // сумма БОЛЬШЕ, чем значение в частотном тесте
        // далее пишут пример, где показывают, что сумма меньше, и они говорят, что тест запускать не надо

        /// <summary>
        /// Метод, считающий p-value на основе количества непрерывных последовательностей одинаковых бит
        /// </summary>
        /// <param name="hash">Псевдослучайная последовательность</param>
        /// <returns>p-value</returns>
        public double getPValue(BitArray hash)
        {
            var    hashLength     = hash.Length;
            double onesProportion = 0; // доля единиц

            foreach (bool v in hash)
            {
                if (v)
                {
                    onesProportion++;
                }
            }

            onesProportion /= hashLength;

            if (onesProportion - 0.5 > 2 / Math.Sqrt(hashLength))
            {
                return(0);
            }

            var numberOfHoles = 1;

            for (int i = 0; i < hash.Length - 1; i++)
            {
                if (hash[i] ^ hash[i + 1]) // если биты не совпадают, то
                {
                    numberOfHoles++;
                }
            }

            // erfc - Complementary Error Function (дополнительная функция ошибок)
            var pValue = Special.Erfc(Math.Abs(numberOfHoles - 2 * hashLength * onesProportion * (1 - onesProportion)) /
                                      (2 * Math.Sqrt(2 * hashLength) * onesProportion * (1 - onesProportion)));

            return(pValue);
        }
예제 #17
0
 /// <summary>
 ///   The Probit mean (activation) function.
 /// </summary>
 ///
 /// <param name="x">A transformed value.</param>
 ///
 /// <returns>The reverse transformed value.</returns>
 ///
 public double Inverse(double x)
 {
     return(Special.Erfc(-x / Constants.Sqrt2) * 0.5);
 }
예제 #18
0
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this Log-Normal distribution evaluated at point <c>x</c>.
        /// </summary>
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        /// <remarks>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// <para>
        ///  The calculation is computed through the relationship to the error function
        ///  as <see cref="Accord.Math.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2. See
        ///  [Weisstein] for more details.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description>
        ///       Weisstein, Eric W. "Normal Distribution Function." From MathWorld--A Wolfram Web
        ///       Resource. http://mathworld.wolfram.com/NormalDistributionFunction.html </description></item>
        ///   </list></para>
        /// </remarks>
        ///
        public override double DistributionFunction(double x)
        {
            double z = (Math.Log(x) - location) / shape;

            return(0.5 * Special.Erfc(-z / Special.Sqrt2));
        }
예제 #19
0
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this distribution evaluated at point <c>x</c>.
        /// </summary>
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        /// <remarks>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// <para>
        ///  The calculation is computed through the relationship to
        ///  the function as <see cref="GABIZ.Base.Mathematic.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description><a href="http://mathworld.wolfram.com/NormalDistributionFunction.html">
        ///       http://mathworld.wolfram.com/NormalDistributionFunction.html</a></description></item>
        ///   </list></para>
        /// </remarks>
        public override double DistributionFunction(double x)
        {
            double z = (x - mean) / variance;

            return(Special.Erfc(-z / Special.Sqrt2) / 2.0);
        }
예제 #20
0
        /// <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>
        ///
        protected internal override double InnerDistributionFunction(double x)
        {
            double cdf = Special.Erfc(Math.Sqrt(scale / (2 * (x - location))));

            return(cdf);
        }
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this Log-Normal distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        /// <remarks>
        ///
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        ///
        /// <para>
        ///  The calculation is computed through the relationship to the error function
        ///  as <see cref="Accord.Math.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2. See
        ///  [Weisstein] for more details.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description>
        ///       Weisstein, Eric W. "Normal Distribution Function." From MathWorld--A Wolfram Web
        ///       Resource. http://mathworld.wolfram.com/NormalDistributionFunction.html </description></item>
        ///   </list></para>
        /// </remarks>
        ///
        /// <example>
        ///   See <see cref="LognormalDistribution"/>.
        /// </example>
        ///
        protected internal override double InnerDistributionFunction(double x)
        {
            double z = (Math.Log(x) - location) / shape;

            return(0.5 * Special.Erfc(-z / Constants.Sqrt2));
        }
예제 #22
0
        /// <summary>
        ///   Gets the cumulative distribution function (cdf) for
        ///   the this distribution evaluated at point <c>x</c>.
        /// </summary>
        /// <param name="x">
        ///   A single point in the distribution range.</param>
        /// <remarks>
        /// <para>
        ///   The Cumulative Distribution Function (CDF) describes the cumulative
        ///   probability that a given value or any value smaller than it will occur.</para>
        /// <para>
        ///  The calculation is computed through the relationship to
        ///  the function as <see cref="Accord.Math.Special.Erfc">erfc</see>(-z/sqrt(2)) / 2.</para>
        ///
        /// <para>
        ///   References:
        ///   <list type="bullet">
        ///     <item><description><a href="http://mathworld.wolfram.com/NormalDistributionFunction.html">
        ///       http://mathworld.wolfram.com/NormalDistributionFunction.html</a></description></item>
        ///   </list></para>
        /// </remarks>
        public override double DistributionFunction(double x)
        {
            double z = ZScore(x);

            return(Special.Erfc(-z / Special.Sqrt2) / 2.0);
        }
예제 #23
0
 /// <summary>
 ///   Complemented cumulative distribution function.
 /// </summary>
 ///
 /// <returns>
 ///   The area under the Gaussian p.d.f. integrated
 ///   from the given value to positive infinity.
 /// </returns>
 ///
 public static double Complemented(double value)
 {
     return(0.5 * Special.Erfc(value / Constants.Sqrt2));
 }