Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
 }
Esempio n. 4
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);
        }
Esempio n. 5
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));
        }
Esempio n. 6
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));
 }
Esempio n. 7
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));
 }
Esempio n. 8
0
 /// <summary>
 ///   Generates a random observation from the current distribution.
 /// </summary>
 ///
 /// <returns>A random observations drawn from this distribution.</returns>
 ///
 public override double Generate()
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2));
 }
Esempio n. 9
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 override double[] Generate(int samples)
 {
     return(GammaDistribution.Random(shape: degreesOfFreedom / 2.0, scale: 2, samples: samples));
 }