Module: Distribution::Beta::Ruby_

Extended by:
Math
Defined in:
lib/distribution/beta/ruby.rb

Constant Summary

Constants included from MathExtension18

MathExtension18::B0, MathExtension18::B1, MathExtension18::B10, MathExtension18::B12, MathExtension18::B14, MathExtension18::B16, MathExtension18::B2, MathExtension18::B4, MathExtension18::B6, MathExtension18::B8, MathExtension18::LOG_2PI, MathExtension18::N

Constants included from MathExtension

MathExtension::EULER, MathExtension::LN2, MathExtension::LNPI, MathExtension::LOG_FLOAT_MIN, MathExtension::ROOT3_FLOAT_EPSILON, MathExtension::ROOT3_FLOAT_MIN, MathExtension::ROOT4_FLOAT_EPSILON, MathExtension::ROOT4_FLOAT_MIN, MathExtension::ROOT5_FLOAT_EPSILON, MathExtension::ROOT5_FLOAT_MIN, MathExtension::ROOT6_FLOAT_EPSILON, MathExtension::ROOT6_FLOAT_MIN, MathExtension::SQRT2, MathExtension::SQRTPI

Class Method Summary collapse

Methods included from Math

beta, binomial_coefficient, binomial_coefficient_gamma, combinations, erfc_e, exact_regularized_beta, factorial, fast_factorial, gamma, gammp, gammq, incomplete_beta, incomplete_gamma, lbeta, lgamma, logbeta, loggamma, permutations, regularized_beta, rising_factorial, unnormalized_incomplete_gamma

Methods included from MathExtension18

#gamma, #lgamma, #loggamma

Methods included from MathExtension

#beta, #binomial_coefficient, #binomial_coefficient_gamma, #binomial_coefficient_multiplicative, #erfc_e, #exact_regularized_beta, #exp_err, #factorial, #fast_factorial, #gammq, #incomplete_beta, #incomplete_gamma, #lbeta, #logbeta, #loggamma, #permutations, #regularized_beta, #rising_factorial, #unnormalized_incomplete_gamma

Class Method Details

.cdf(x, a, b) ⇒ Object

Gamma cumulative distribution function Translated from GSL-1.9: cdf/beta.c gsl_cdf_beta_P



32
33
34
35
36
# File 'lib/distribution/beta/ruby.rb', line 32

def cdf(x,a,b)
  return 0.0 if x <= 0.0
  return 1.0 if x >= 1.0
  Math::IncompleteBeta.axpy(1.0, 0.0, a,b,x)
end

.pdf(x, a, b) ⇒ Object

Beta distribution probability density function

Adapted from GSL-1.9 (apparently by Knuth originally), found in randist/beta.c

Form: p(x) dx = (Gamma(a + b)/(Gamma(a) Gamma(b))) x^(a-1) (1-x)^(b-1) dx

References



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/distribution/beta/ruby.rb', line 16

def pdf(x,a,b)
  return 0 if x < 0 || x > 1

  gab = Math.lgamma(a+b).first
  ga  = Math.lgamma(a).first
  gb  = Math.lgamma(b).first

  if x == 0.0 || x == 1.0
    Math.exp(gab - ga - gb) * x**(a-1) * (1-x)**(b-1)
  else
    Math.exp(gab - ga - gb + Math.log(x)*(a-1) + Math::Log.log1p(-x)*(b-1))
  end
end