working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,955 snippets matching: distribution

    public by maholtz  253845  1  5  1

    linux distribution version and kernel

    Gives the name of the distribution, the version, the codename (f.e. quantal) and the x86 or i386 etc.
    # Linux Distribution
    cat /etc/lsb-release
    # output:
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=12.10
    DISTRIB_CODENAME=quantal
    DISTRIB_DESCRIPTION="Ubuntu 12.10"
    -----------------------------
    
    # Kernel Version
    uname -a
    # output
    Linux COMPUTERNAME 3.5.0-51-generic #76-Ubuntu SMP Thu May 15 21:19:10 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    
    # IS this a 64Bit CPU
    # get INFOs about your CPU
    cat /proc/cpuinfo
    
    # if there is a flag "lm" your cpu is 64 Bit (long mode)
    cat /proc/cpuinfo | grep flags | grep " lm "
    

    public by Geometry  79457  0  5  0

    BivariateComplemented: Complemented bivariate normal cumulative distribution function.

    Complemented bivariate normal cumulative distribution function. The value of the first variate. The value of the second variate. The correlation coefficient between x and y. This can be computed from a covariance matrix C as rho = C_12 / (sqrt(C_11) * sqrt(C_22)).
    /// <summary>
    ///   Complemented bivariate normal cumulative distribution function.
    /// </summary>
    /// 
    /// <param name="x">The value of the first variate.</param>
    /// <param name="y">The value of the second variate.</param>
    /// <param name="rho">The correlation coefficient between x and y. This can be computed
    /// from a covariance matrix C as  <code>rho = C_12 / (sqrt(C_11) * sqrt(C_22))</code>.</param>
    /// <returns></returns>
    /// 
    public static double BivariateComplemented(double x, double y, double rho)
    {
        return BVND(x, y, rho);
    }

    public by Geometry  109518  0  5  0

    Random: Creates a rows-by-cols matrix random data drawn from a given distribution.

    Creates a rows-by-cols matrix random data drawn from a given distribution.
    /// <summary>
            ///   Creates a rows-by-cols matrix random data drawn from a given distribution.
            /// </summary>
            /// 
            [Obsolete("Please use INumberGenerator<T> instead.")]
    #pragma warning disable 0618
            public static double[,] Random(int rows, int cols, IRandomNumberGenerator generator)
            {
                return Random<double>(rows, cols, new RandomNumberGeneratorAdapter(generator));
            }

    public by Geometry  23321  0  4  0

    OneSideUpperTail: Computes the Upper Tail of the P[Dn &gt;= x] distribution.

    Computes the Upper Tail of the P[Dn &gt;= x] distribution. This function approximates the upper tail of the P[Dn &gt;= x] distribution using the one-sided Kolmogorov-Smirnov statistic.
    /// <summary>
    ///   Computes the Upper Tail of the P[Dn &gt;= x] distribution.
    /// </summary>
    ///
    /// <remarks>
    ///   This function approximates the upper tail of the P[Dn &gt;= x]
    ///   distribution using the one-sided Kolmogorov-Smirnov statistic.
    /// </remarks>
    ///
    public static double OneSideUpperTail(double n, double x)
    {
        if (n > 200000)
        {
            // Use an asymptotic formula for n too high
            double t = (6 * n * x + 1.0);
            double z = t * t / (18 * n);
            double v = (1.0 - (2 * z * z - 4 * z - 1.0) / (18 * n)) * Math.Exp(-z);
    
            if (v <= 0.0) return 0.0;
            if (v >= 1.0) return 1.0;
            else return 1.0 * v;
        }
        else
        {
            // Use Smirnov's stable formula for computing Pn+, the upper tail of
            // the one-sided Kolmogorov's statistic Dn+. This upper tail of the
            // one-sided statistic can then be used to approximate the upper tail
            // Pn of the Kolmogorov statistic Dn with Pn ~ 2*Pn+.
    
            int jmax = (int)(n * (1.0 - x));
            if ((1.0 - x - (double)jmax / n) <= 0.0)
                jmax--;
    
            // Initialize
            int jdiv = (n > 3000) ? 2 : 3;
            int jstart = jmax / jdiv + 1;
    
            double logBinomial = Special.LogBinomial(n, jstart);
            double LOGJMAX = logBinomial;
            double EPSILON = 1.0E-12;
    
    
            // Start computing the series
            double sum = 0;
    
            for (int j = jstart; j <= jmax; j++)
            {
                double q = (double)j / n + x;
                double term = logBinomial + (j - 1) * Math.Log(q) + (n - j) * Special.Log1p(-q);
                double t = Math.Exp(term);
    
                sum += t;
                logBinomial += Math.Log((double)(n - j) / (j + 1));
    
                if (t <= sum * EPSILON)
                    break;
            }
    
            jstart = jmax / jdiv;
            logBinomial = LOGJMAX + Math.Log((double)(jstart + 1) / (n - jstart));
    
            for (int j = jstart; j > 0; j--)
            {
                double q = (double)j / n + x;
                double term = logBinomial + (j - 1) * Math.Log(q) + (n - j) * Special.Log1p(-q);
                double t = Math.Exp(term);
    
                sum += t;
                logBinomial += Math.Log((double)j / (n - j + 1));
    
                if (t <= sum * EPSILON)
                    break;
            }
    
    
            return sum * x + Math.Exp(n * Special.Log1p(-x));
        }
    }

    public by Geometry  799  0  4  0

    distributionFunctionLowerTail: Computes the cumulative probability at <c>t</c> of the non-central T-distribution with DF degrees of freedom and non-centrality parameter.

    Computes the cumulative probability at t of the non-central T-distribution with DF degrees of freedom and non-centrality parameter. This function is based on the original work done by Russell Lent hand John Burkardt, shared under the LGPL license. Original FORTRAN code can be found at: http://people.sc.fsu.edu/~jburkardt/f77_src/asa2
    /// <summary>
    ///   Computes the cumulative probability at <c>t</c> of the
    ///   non-central T-distribution with DF degrees of freedom 
    ///   and non-centrality parameter.
    /// </summary>
    /// 
    /// <remarks>
    ///   This function is based on the original work done by
    ///   Russell Lent hand John Burkardt, shared under the
    ///   LGPL license. Original FORTRAN code can be found at:
    ///   http://people.sc.fsu.edu/~jburkardt/f77_src/asa243/asa243.html
    /// </remarks>
    /// 
    private static double distributionFunctionLowerTail(double t, double df, double delta)
    {
        double alnrpi = 0.57236494292470008707;
        double errmax = 1.0E-10;
        int itrmax = 100;
        double r2pi = 0.79788456080286535588;
    
        if (df <= 0.0)
        {
            throw new ArgumentOutOfRangeException("df",
                "Degrees of freedom must be positive.");
        }
    
        double del;
        bool negdel;
    
        if (t < 0.0)
        {
            del = -delta;
            negdel = true;
        }
        else
        {
            del = delta;
            negdel = false;
        }
    
        // Initialize twin series.
        double en = 1.0;
        double x = t * t / (t * t + df);
        double value = 0;
    
        if (x <= 0.0)
        {
            // upper tail of normal cumulative function
            value += Normal.Complemented(del);
    
            if (negdel)
                value = 1.0 - value;
            return value;
        }
    
        double lambda = del * del;
        double p = 0.5 * Math.Exp(-0.5 * lambda);
        double q = r2pi * p * del;
        double s = 0.5 - p;
        double a = 0.5;
        double b = 0.5 * df;
        double rxb = Math.Pow(1.0 - x, b);
        double albeta = alnrpi + Gamma.Log(b) - Gamma.Log(a + b);
        double xodd = Beta.Incomplete(a, b, x);
        double godd = 2.0 * rxb * Math.Exp(a * Math.Log(x) - albeta);
        double xeven = 1.0 - rxb;
        double geven = b * x * rxb;
        value = p * xodd + q * xeven;
    
        // Repeat until convergence.
        while (true)
        {
            a = a + 1.0;
            xodd = xodd - godd;
            xeven = xeven - geven;
            godd = godd * x * (a + b - 1.0) / a;
            geven = geven * x * (a + b - 0.5) / (a + 0.5);
            p = p * lambda / (2.0 * en);
            q = q * lambda / (2.0 * en + 1.0);
            s = s - p;
            en = en + 1.0;
            value = value + p * xodd + q * xeven;
            double errbd = 2.0 * s * (xodd - godd);
    
            if (errbd <= errmax)
                break;
    
            if (itrmax < en)
                throw new ConvergenceException("Maximum number of iterations reached.");
        }
    
        // upper tail of normal cumulative function
        value = value + Normal.Complemented(del);
    
        if (negdel)
            value = 1.0 - value;
    
        return value;
    }

    public by Geometry  28986  0  4  0

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

    Generates a random vector of observations from a distribution with the given parameters. The number of samples to generate. The mean vector μ (mu) for the distribution. The covariance matrix Σ (sigma) for the distribution. A random vector of observations drawn from this distribution.
    /// <summary>
    ///   Generates a random vector of observations from a distribution with the given parameters.
    /// </summary>
    /// 
    /// <param name="samples">The number of samples to generate.</param>
    /// <param name="mean">The mean vector μ (mu) for the distribution.</param>
    /// <param name="covariance">The covariance matrix Σ (sigma) for the distribution.</param>
    /// 
    /// <returns>A random vector of observations drawn from this distribution.</returns>
    /// 
    public static double[][] Generate(int samples, double[] mean, double[,] covariance)
    {
        var normal = new MultivariateNormalDistribution(mean, covariance);
        return normal.Generate(samples);
    }

    public by Geometry  2015  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  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  1238  7  5  0

    Discrete: Creates a new <see cref="MetropolisHasting"/> sampler using symmetric geometric distributions as the parameter proposal generation priors.

    Creates a new sampler using symmetric geometric distributions as the parameter proposal generation priors. The number of dimensions in each observation. The target distribution whose samples should be generated. A sampling algorithm that can generate samples from the target distribution.
    /// <summary>
    ///   Creates a new <see cref="MetropolisHasting"/> sampler using symmetric geometric distributions
    ///   as the parameter proposal generation priors. 
    /// </summary>
    /// 
    /// <param name="dimensions">The number of dimensions in each observation.</param>
    /// <param name="distribution">The target distribution whose samples should be generated.</param>
    /// 
    /// <returns>A sampling algorithm that can generate samples from the target distribution.</returns>
    /// 
    public static MetropolisHasting<int, Independent<SymmetricGeometricDistribution>, T> Discrete<T>(int dimensions, T distribution)
        where T : IMultivariateDistribution<int[]>
    {
        return new MetropolisHasting<int, Independent<SymmetricGeometricDistribution>, T>(
            distribution, new Independent<SymmetricGeometricDistribution>(dimensions,
                () => new SymmetricGeometricDistribution(0.5)));
    }

    public by Geometry  1034  1  5  0

    inverseDistributionLeftTail: Gets the inverse of the cumulative distribution function (icdf) for the left tail T-distribution evaluated at probability <c>p</c>.

    Gets the inverse of the cumulative distribution function (icdf) for the left tail T-distribution evaluated at probability p. Based on the stdtril function from the Cephes Math Library Release 2.8, adapted with permission of Stephen L. Moshier.
    /// <summary>
    ///   Gets the inverse of the cumulative distribution function (icdf) for
    ///   the left tail T-distribution evaluated at probability <c>p</c>.
    /// </summary>
    /// 
    /// <remarks>
    ///   Based on the stdtril function from the Cephes Math Library
    ///   Release 2.8, adapted with permission of Stephen L. Moshier.
    /// </remarks>
    /// 
    private static double inverseDistributionLeftTail(double df, double p)
    {
        if (p > 0.25 && p < 0.75)
        {
            if (p == 0.5)
                return 0;
    
            double u = 1.0 - 2.0 * p;
            double z = Beta.IncompleteInverse(0.5, 0.5 * df, Math.Abs(u));
            double t = Math.Sqrt(df * z / (1.0 - z));
    
            if (p < 0.5)
                t = -t;
    
            return t;
        }
        else
        {
            int rflg = -1;
    
            if (p >= 0.5)
            {
                p = 1.0 - p;
                rflg = 1;
            }
    
            double z = Beta.IncompleteInverse(0.5 * df, 0.5, 2.0 * p);
    
            if ((Double.MaxValue * z) < df)
                return rflg * Double.MaxValue;
    
            double t = Math.Sqrt(df / z - df);
            return rflg * t;
        }
    }
    • Public Snippets
    • Channels Snippets