working on it ...

Filters

Explore Public Snippets

Sort by

Found 817 snippets

    public by Geometry  2227  4  4  1

    Random: Returns a random symbol within the given symbol probabilities.

    Returns a random symbol within the given symbol probabilities. The probabilities for the discrete symbols. A random symbol within the given probabilities.
    /// <summary>
    ///   Returns a random symbol within the given symbol probabilities.
    /// </summary>
    /// 
    /// <param name="probabilities">The probabilities for the discrete symbols.</param>
    /// 
    /// <returns>A random symbol within the given probabilities.</returns>
    /// 
    public static int Random(double[] probabilities)
    {
        double uniform = Accord.Math.Random.Generator.Random.NextDouble();
    
        double cumulativeSum = 0;
    
        // Use the probabilities to partition the [0,1] interval 
        //  and check inside which range the values fall into.
    
        for (int i = 0; i < probabilities.Length; i++)
        {
            cumulativeSum += probabilities[i];
    
            if (uniform < cumulativeSum)
                return i;
        }
    
        throw new InvalidOperationException("Generated value is not between 0 and 1.");
    }

    public by Geometry  2018  2  4  1

    Uniform: Constructs a new uniform discrete distribution.

    Constructs a new uniform discrete distribution. The integer value where the distribution starts, also known as a. Default value is 0. The integer value where the distribution ends, also known as b.
    /// <summary>
    ///   Constructs a new uniform discrete distribution.
    /// </summary>
    /// 
    /// <param name="a">
    ///   The integer value where the distribution starts, also
    ///   known as <c>a</c>. Default value is 0.</param>
    /// <param name="b">
    ///   The integer value where the distribution ends, also 
    ///   known as <c>b</c>.</param>
    ///   
    public static GeneralDiscreteDistribution Uniform(int a, int b)
    {
        if (a > b)
        {
            throw new ArgumentOutOfRangeException("b",
                "The starting number a must be lower than b.");
        }
    
        return new GeneralDiscreteDistribution(a, b - a + 1);
    }

    public by Geometry  1778  2  4  0

    WMinimum: Computes the Wilcoxon's W statistic.

    Computes the Wilcoxon's W statistic. The W statistic is computed as the minimum of the W+ and W- statistics.
    /// <summary>
    ///   Computes the Wilcoxon's W statistic.
    /// </summary>
    /// 
    /// <remarks>
    ///   The W statistic is computed as the
    ///   minimum of the W+ and W- statistics.
    /// </remarks>
    /// 
    public static double WMinimum(int[] signs, double[] ranks)
    {
        double wp = 0, wn = 0;
        for (int i = 0; i < signs.Length; i++)
        {
            if (signs[i] < 0)
                wn += ranks[i];
    
            else if (signs[i] > 0)
                wp += ranks[i];
        }
    
        double min = Math.Min(wp, wn);
    
        return min;
    }

    public by Geometry  1513  8  4  0

    WNegative: Computes the Wilcoxon's W- statistic.

    Computes the Wilcoxon's W- statistic. The W- statistic is computed as the sum of all negative signed ranks.
    /// <summary>
    ///   Computes the Wilcoxon's W- statistic.
    /// </summary>
    /// 
    /// <remarks>
    ///   The W- statistic is computed as the
    ///   sum of all negative signed ranks.
    /// </remarks>
    /// 
    public static double WNegative(int[] signs, double[] ranks)
    {
        double sum = 0;
        for (int i = 0; i < signs.Length; i++)
            if (signs[i] < 0)
                sum += ranks[i];
        return sum;
    }

    public by Geometry  1300  1  5  0

    WPositive: Computes the Wilcoxon's W+ statistic.

    Computes the Wilcoxon's W+ statistic. The W+ statistic is computed as the sum of all positive signed ranks.
    /// <summary>
    ///   Computes the Wilcoxon's W+ statistic.
    /// </summary>
    /// 
    /// <remarks>
    ///   The W+ statistic is computed as the
    ///   sum of all positive signed ranks.
    /// </remarks>
    /// 
    public static double WPositive(int[] signs, double[] ranks)
    {
        double sum = 0;
        for (int i = 0; i < signs.Length; i++)
            if (signs[i] > 0)
                sum += ranks[i];
    
        return sum;
    }

    public by Geometry  1444  0  4  1

    Random: Generates a random observation from the Weibull distribution with the given parameters.

    Generates a random observation from the Weibull distribution with the given parameters. The scale parameter lambda. The shape parameter k. A random double value sampled from the specified Weibull distribution.
    /// <summary>
    ///   Generates a random observation from the 
    ///   Weibull distribution with the given parameters.
    /// </summary>
    /// 
    /// <param name="scale">The scale parameter lambda.</param>
    /// <param name="shape">The shape parameter k.</param>
    /// 
    /// <returns>A random double value sampled from the specified Weibull distribution.</returns>
    /// 
    public static double Random(double shape, double scale)
    {
        double u = Accord.Math.Random.Generator.Random.NextDouble();
        return scale * Math.Pow(-Math.Log(u), 1 / shape);
    }

    public by Geometry  1362  1  4  1

    Random: Generates a random vector of observations from the Weibull distribution with the given parameters.

    Generates a random vector of observations from the Weibull distribution with the given parameters. The scale parameter lambda. The shape parameter k. The number of samples to generate. The location where to store the samples. An array of double values sampled from the specified Weibull distribution.
    /// <summary>
    ///   Generates a random vector of observations from the 
    ///   Weibull distribution with the given parameters.
    /// </summary>
    /// 
    /// <param name="scale">The scale parameter lambda.</param>
    /// <param name="shape">The shape parameter k.</param>
    /// <param name="samples">The number of samples to generate.</param>
    /// <param name="result">The location where to store the samples.</param>
    ///
    /// <returns>An array of double values sampled from the specified Weibull distribution.</returns>
    /// 
    public static double[] Random(double shape, double scale, int samples, double[] result)
    {
        var random = Accord.Math.Random.Generator.Random;
        for (int i = 0; i < samples; i++)
            result[i] = scale * Math.Pow(-Math.Log(random.NextDouble()), 1 / shape);
        return result;
    }

    public by Geometry  1505  7  4  0

    DistributionFunction: von-Mises cumulative distribution function.

    von-Mises cumulative distribution function. 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. References: Geoffrey Hill, ACM TOMS Algorithm 518, Incomplete Bessel Function I0: The von Mises Distribution,
    /// <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;
    }

    public by Geometry  1116  0  5  0

    Estimate: Estimates a new von-Mises distribution from a given set of angles.

    Estimates a new von-Mises distribution from a given set of angles.
    /// <summary>
    ///   Estimates a new von-Mises distribution from a given set of angles.
    /// </summary>
    /// 
    public static VonMisesDistribution Estimate(double[] angles, double[] weights, VonMisesOptions options)
    {
        VonMisesDistribution vonMises = new VonMisesDistribution();
        vonMises.Fit(angles, weights, options);
        return vonMises;
    }

    public by Geometry  1090  0  5  0

    CircularUniform: Creates a new circular uniform distribution by creating a new <see cref="VonMisesDistribution"/> with zero kappa.

    Creates a new circular uniform distribution by creating a new with zero kappa. The mean value μ (mu). A with zero kappa, which is equivalent to creating an uniform circular distribution.
    /// <summary>
    ///   Creates a new circular uniform distribution by creating a
    ///   new <see cref="VonMisesDistribution"/> with zero kappa.
    /// </summary>
    /// 
    /// <param name="mean">The mean value μ (mu).</param>
    /// 
    /// <returns>
    ///   A <see cref="VonMisesDistribution"/> with zero kappa, which
    ///   is equivalent to creating an uniform circular distribution.
    /// </returns>
    /// 
    public static VonMisesDistribution CircularUniform(double mean)
    {
        return new VonMisesDistribution(mean, 0);
    }
    • Public Snippets
    • Channels Snippets