Class: RV::Gamma
- Inherits:
-
Object
- Object
- RV::Gamma
- Includes:
- RV_Generator
- Defined in:
- lib/random_variates.rb
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.
Instance Method Summary collapse
-
#initialize(alpha: 1.0, beta: 1.0, rng: U_GENERATOR) ⇒ Gamma
constructor
A new instance of Gamma.
- #next ⇒ Object
Methods included from RV_Generator
Constructor Details
#initialize(alpha: 1.0, beta: 1.0, rng: U_GENERATOR) ⇒ Gamma
Returns a new instance of Gamma.
284 285 286 287 288 289 290 291 |
# File 'lib/random_variates.rb', line 284 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 @rng = rng @std_normal = Normal.new(rng: rng) end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
282 283 284 |
# File 'lib/random_variates.rb', line 282 def alpha @alpha end |
#beta ⇒ Object (readonly)
Returns the value of attribute beta.
282 283 284 |
# File 'lib/random_variates.rb', line 282 def beta @beta end |
Instance Method Details
#next ⇒ Object
293 294 295 |
# File 'lib/random_variates.rb', line 293 def next __gen__(@alpha, @beta) end |