Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of a Gamma distribution with the given parameters.
        /// </summary>
        /// <param name="shape">The shape parameter, which must be positive.</param>
        /// <param name="scale">The scale parameter, which must be positive.</param>
        public GammaDistribution(double shape, double scale)
        {
            if (shape <= 0.0)
            {
                throw new ArgumentOutOfRangeException("shape");
            }
            if (scale <= 0.0)
            {
                throw new ArgumentOutOfRangeException("scale");
            }
            a = shape;
            s = scale;

            // depending on size of a, store Gamma(a) or -Ln(Gamma(a)) for future use
            if (a < 64.0)
            {
                ga = AdvancedMath.Gamma(a);
            }
            else
            {
                ga = -AdvancedMath.LogGamma(a);
            }

            gammaRng = DeviateGeneratorFactory.GetGammaGenerator(a);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new &#x3B2; distribution.
 /// </summary>
 /// <param name="alpha">The left shape parameter, which controls the form of the distribution near x=0.</param>
 /// <param name="beta">The right shape parameter, which controls the form of the distribution near x=1.</param>
 /// <remarks>
 /// <para>The <paramref name="alpha"/> shape parameter controls the form of the distribution near x=0. The
 /// <paramref name="beta"/> shape parameter controls the form of the distribution near z=1. If a shape parameter
 /// is less than one, the PDF diverges on the side of the distribution it controls. If a shape parameter
 /// is greater than one, the PDF goes to zero on the side of the distribution it controls. If the left and right
 /// shape parameters are equal, the distribution is symmetric about x=1/2.</para>
 /// </remarks>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="alpha"/> or <paramref name="beta"/> is non-positive.</exception>
 public BetaDistribution(double alpha, double beta)
 {
     if (alpha <= 0.0)
     {
         throw new ArgumentOutOfRangeException(nameof(alpha));
     }
     if (beta <= 0.0)
     {
         throw new ArgumentOutOfRangeException(nameof(beta));
     }
     this.a = alpha;
     this.b = beta;
     // cache value of B(alpha, beta) to avoid having to re-calculate it whenever needed
     this.bigB = AdvancedMath.Beta(alpha, beta);
     // get a beta generator
     if (alpha < 0.75 && beta < 0.75)
     {
         this.betaRng = new JoehnkBetaGenerator(alpha, beta);
     }
     else if (alpha > 1.0 && beta > 1.0)
     {
         this.betaRng = new ChengBetaGenerator(alpha, beta);
     }
     else
     {
         this.betaRng = DeviateGeneratorFactory.GetBetaGenerator(alpha, beta);
     }
     // get a beta inverter
     this.betaInverter = new BetaInverter(alpha, beta);
 }
 /// <summary>
 /// Initializes a new normal distribution with the given mean and standard deviation.
 /// </summary>
 /// <param name="mu">The mean.</param>
 /// <param name="sigma">The standard deviation, which must be positive.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="sigma"/> is less than or equal to zero.</exception>
 public NormalDistribution(double mu, double sigma)
 {
     if (sigma <= 0.0)
     {
         throw new ArgumentOutOfRangeException(nameof(sigma));
     }
     this.mu        = mu;
     this.sigma     = sigma;
     this.normalRng = DeviateGeneratorFactory.GetNormalGenerator();
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new Cauchy distribution.
 /// </summary>
 /// <param name="mu">The centroid of the distribution.</param>
 /// <param name="gamma">The width parameter of the distribution.</param>
 public CauchyDistribution(double mu, double gamma)
 {
     if (gamma <= 0.0)
     {
         throw new ArgumentNullException(nameof(gamma));
     }
     this.mu        = mu;
     this.gamma     = gamma;
     this.cauchyRng = DeviateGeneratorFactory.GetCauchyGenerator();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new &#x3B2; distribution.
 /// </summary>
 /// <param name="alpha">The left shape parameter, which controls the form of the distribution near x=0.</param>
 /// <param name="beta">The right shape parameter, which controls the form of the distribution near x=1.</param>
 /// <remarks>
 /// <para>The <paramref name="alpha"/> shape parameter controls the form of the distribution near x=0. The
 /// <paramref name="beta"/> shape parameter controls the form of the distribution near z=1. If a shape parameter
 /// is less than one, the PDF diverges on the side of the distribution it controls. If a shape parameter
 /// is greater than one, the PDF goes to zero on the side of the distribution it controls. If the left and right
 /// shapre parameters are equal, the distribution is symmetric about x=1/2.</para>
 /// </remarks>
 /// <seealso href="http://en.wikipedia.org/wiki/Beta_distribution" />
 public BetaDistribution(double alpha, double beta)
 {
     if (alpha <= 0.0)
     {
         throw new ArgumentOutOfRangeException("alpha");
     }
     if (beta <= 0.0)
     {
         throw new ArgumentOutOfRangeException("beta");
     }
     this.alpha = alpha;
     this.beta  = beta;
     // cache value of B(alpha, beta) to avoid having to re-calculate it whenever needed
     this.bigB = AdvancedMath.Beta(alpha, beta);
     // get a beta generator
     this.betaRng = DeviateGeneratorFactory.GetBetaGenerator(alpha, beta);
     // get a beta inverter
     this.betaInverter = new BetaInverter(alpha, beta);
 }