Class: Gamma
Overview
Gamma generator based on Marsaglia and Tsang method Algorithm 4.33
Produces gamma RVs with expected value alpha * beta.
- Arguments
-
alpha-> the shape parameter (alpha> 0; default: 1). -
beta-> the rate parameter (beta> 0; default: 1). -
rng-> the (Enumerable) source of U(0, 1)‘s (default: U_GENERATOR)
-
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#beta ⇒ Object
readonly
Returns the value of attribute beta.
Attributes included from RV_Generator
Instance Method Summary collapse
-
#initialize(alpha: 1.0, beta: 1.0, rng: U_GENERATOR) ⇒ Gamma
constructor
A new instance of Gamma.
Methods included from RV_Generator
Constructor Details
#initialize(alpha: 1.0, beta: 1.0, rng: U_GENERATOR) ⇒ Gamma
Returns a new instance of Gamma.
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/random_variates.rb', line 246 def initialize(alpha: 1.0, beta: 1.0, rng: U_GENERATOR) raise 'Alpha and beta must be positive.' if alpha <= 0 || beta <= 0 @alpha = alpha @beta = beta std_normal = Gaussian.new(mean: 0.0, sd: 1.0, rng: rng) @generator = Enumerator.new do |yielder| loop { yielder << __gen__(alpha, beta, std_normal, rng) } end end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
244 245 246 |
# File 'lib/random_variates.rb', line 244 def alpha @alpha end |
#beta ⇒ Object (readonly)
Returns the value of attribute beta.
244 245 246 |
# File 'lib/random_variates.rb', line 244 def beta @beta end |