/// <summary> /// Initializes a new β 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 β 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); }