Exemplo n.º 1
0
        /// <summary>
        ///   Generates a random observation from the
        ///   F-distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="d1">The first degree of freedom.</param>
        /// <param name="d2">The second degree of freedom.</param>
        ///
        /// <returns>A random double value sampled from the specified F-distribution.</returns>
        ///
        public static double Random(int d1, int d2)
        {
            double x = GammaDistribution.Random(shape: d1 / 2.0, scale: 2);
            double y = GammaDistribution.Random(shape: d2 / 2.0, scale: 2);

            return(x / y);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Estimates a new Gamma distribution from a given set of observations.
        /// </summary>
        ///
        public static GammaDistribution Estimate(double[] observations, double[] weights)
        {
            var n = new GammaDistribution();

            n.Fit(observations, weights, null);
            return(n);
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Generates a random observation from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        /// <param name="source">The random number generator to use as a source of randomness.
        ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
        ///
        /// <returns>A random double value sampled from the specified Beta distribution.</returns>
        ///
        public static double Random(double alpha, double beta, Random source)
        {
            double x = GammaDistribution.Random(alpha, 1, source);
            double y = GammaDistribution.Random(beta, 1, source);

            return(x / (x + y));
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Generates a random observation from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        ///
        /// <returns>A random double value sampled from the specified Beta distribution.</returns>
        ///
        public static double Random(double alpha, double beta)
        {
            var rand = Accord.Math.Random.Generator.Random;

            double x = GammaDistribution.Random(alpha, 1);
            double y = GammaDistribution.Random(beta, 1);

            return(x / (x + y));
        }
Exemplo n.º 5
0
 /// <summary>
 ///   Generates a random vector of observations from the
 ///   Nakagami distribution with the given parameters.
 /// </summary>
 ///
 /// <param name="shape">The shape parameter μ.</param>
 /// <param name="spread">The spread parameter ω.</param>
 /// <param name="samples">The number of samples to generate.</param>
 ///
 /// <returns>An array of double values sampled from the specified Nakagami distribution.</returns>
 ///
 public static double[] Random(double shape, double spread, int samples)
 {
     double[] g = GammaDistribution.Random(shape: shape, scale: spread / shape, samples: samples);
     for (int i = 0; i < g.Length; i++)
     {
         g[i] = Math.Sqrt(g[i]);
     }
     return(g);
 }
 /// <summary>
 ///   Generates a random vector of observations from the
 ///   Nakagami distribution with the given parameters.
 /// </summary>
 ///
 /// <param name="shape">The shape parameter μ.</param>
 /// <param name="spread">The spread parameter ω.</param>
 /// <param name="samples">The number of samples to generate.</param>
 /// <param name="result">The location where to store the samples.</param>
 /// <param name="source">The random number generator to use as a source of randomness.
 ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
 ///
 /// <returns>An array of double values sampled from the specified Nakagami distribution.</returns>
 ///
 public static double[] Random(double shape, double spread, int samples, double[] result, Random source)
 {
     GammaDistribution.Random(shape, spread / shape, samples, result, source: source);
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = Math.Sqrt(result[i]);
     }
     return(result);
 }
Exemplo n.º 7
0
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   F-distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="d1">The first degree of freedom.</param>
        /// <param name="d2">The second degree of freedom.</param>
        /// <param name="samples">The number of samples to generate.</param>
        /// <param name="result">The location where to store the samples.</param>
        /// <param name="source">The random number generator to use as a source of randomness.
        ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
        ///
        /// <returns>An array of double values sampled from the specified F-distribution.</returns>
        ///
        public static double[] Random(int d1, int d2, int samples, double[] result, Random source)
        {
            double[] x = GammaDistribution.Random(shape: d1 / 2.0, scale: 2, samples: samples, result: result, source: source);
            double[] y = GammaDistribution.Random(shape: d2 / 2.0, scale: 2, samples: samples, source: source);

            for (int i = 0; i < x.Length; i++)
            {
                x[i] /= y[i];
            }
            return(x);
        }
Exemplo n.º 8
0
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        /// <param name="samples">The number of samples to generate.</param>
        /// <param name="result">The location where to store the samples.</param>
        /// <param name="source">The random number generator to use as a source of randomness.
        ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
        ///
        /// <returns>An array of double values sampled from the specified Beta distribution.</returns>
        ///
        public static double[] Random(double alpha, double beta, int samples, double[] result, Random source)
        {
            double[] x = GammaDistribution.Random(alpha, 1, samples, result, source);
            double[] y = GammaDistribution.Random(beta, 1, samples, source);

            for (int i = 0; i < x.Length; i++)
            {
                result[i] = x[i] / (x[i] + y[i]);
            }

            return(result);
        }
        /// <summary>
        ///   Estimates a new Gamma distribution from a given set of observations.
        /// </summary>
        ///
        public static GammaDistribution Estimate(double[] observations,
                                                 double[] weights = null, double tol = 1e-8, int iterations = 1000)
        {
            var n = new GammaDistribution();

            n.Fit(observations, weights, new GammaOptions()
            {
                Tolerance  = tol,
                Iterations = iterations
            });
            return(n);
        }
Exemplo n.º 10
0
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   F-distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="d1">The first degree of freedom.</param>
        /// <param name="d2">The second degree of freedom.</param>
        /// <param name="samples">The number of samples to generate.</param>
        ///
        /// <returns>An array of double values sampled from the specified F-distribution.</returns>
        ///
        public static double[] Random(int d1, int d2, int samples)
        {
            double[] x = GammaDistribution.Random(shape: d1 / 2.0, scale: 2, samples: samples);
            double[] y = GammaDistribution.Random(shape: d2 / 2.0, scale: 2, samples: samples);

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = x[i] / y[i];
            }

            return(x);
        }
Exemplo n.º 11
0
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</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 Beta distribution.</returns>
        ///
        public static double[] Random(double alpha, double beta, int samples, double[] result)
        {
            var rand = Accord.Math.Random.Generator.Random;

            double[] x = GammaDistribution.Random(alpha, 1, samples, result);
            double[] y = GammaDistribution.Random(beta, 1, samples);

            for (int i = 0; i < x.Length; i++)
            {
                result[i] = x[i] / (x[i] + y[i]);
            }

            return(result);
        }
 /// <summary>
 ///   Generates a random observation from the
 ///   Nakagami distribution with the given parameters.
 /// </summary>
 ///
 /// <param name="shape">The shape parameter μ.</param>
 /// <param name="spread">The spread parameter ω.</param>
 /// <param name="source">The random number generator to use as a source of randomness.
 ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
 ///
 /// <returns>A random double value sampled from the specified Nakagami distribution.</returns>
 ///
 public static double Random(double shape, double spread, Random source)
 {
     return(Math.Sqrt(GammaDistribution.Random(shape: shape, scale: spread / shape, source: source)));
 }
Exemplo n.º 13
0
 /// <summary>
 ///   Generates a random vector of observations from the
 ///   Chi-Square distribution with the given parameters.
 /// </summary>
 ///
 /// <returns>An array of double values sampled from the specified Chi-Square distribution.</returns>
 ///
 public static double[] Random(int degreesOfFreedom, int samples, double[] result, Random source)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2,
                                     samples: samples, result: result, source: source));
 }
Exemplo n.º 14
0
 /// <summary>
 ///   Generates a random vector of observations from the current distribution.
 /// </summary>
 ///
 /// <param name="samples">The number of samples to generate.</param>
 /// <param name="result">The location where to store the samples.</param>
 ///
 /// <returns>A random vector of observations drawn from this distribution.</returns>
 ///
 public override double[] Generate(int samples, double[] result)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2, samples: samples, result: result));
 }
Exemplo n.º 15
0
 /// <summary>
 ///   Generates a random vector of observations from the current distribution.
 /// </summary>
 ///
 /// <param name="samples">The number of samples to generate.</param>
 /// <returns>A random vector of observations drawn from this distribution.</returns>
 ///
 public double[] Generate(int samples)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2, samples: samples));
 }
Exemplo n.º 16
0
 /// <summary>
 ///   Generates a random observation from the current distribution.
 /// </summary>
 ///
 /// <returns>A random observations drawn from this distribution.</returns>
 ///
 public double Generate()
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2));
 }
Exemplo n.º 17
0
 /// <summary>
 ///   Generates a random vector of observations from the
 ///   Chi-Square distribution with the given parameters.
 /// </summary>
 ///
 /// <returns>An array of double values sampled from the specified Chi-Square distribution.</returns>
 ///
 public static double[] Random(int degreesOfFreedom, int samples)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2, samples: samples));
 }
Exemplo n.º 18
0
        /// <summary>
        ///   Generates a random observation from the
        ///   Nakagami distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="shape">The shape parameter μ.</param>
        /// <param name="spread">The spread parameter ω.</param>
        ///
        /// <returns>A random double value sampled from the specified Nakagami distribution.</returns>
        ///
        public static double Random(double shape, double spread)
        {
            double g = GammaDistribution.Random(shape: shape, scale: spread / shape);

            return(Math.Sqrt(g));
        }
Exemplo n.º 19
0
 /// <summary>
 ///   Generates a random observation from the
 ///   Chi-Square distribution with the given parameters.
 /// </summary>
 ///
 /// <param name="degreesOfFreedom">The degrees of freedom for the distribution.</param>
 ///
 /// <returns>A random double value sampled from the specified Chi-Square distribution.</returns>
 ///
 public static double Random(int degreesOfFreedom)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2));
 }