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.
280 281 282 283 284 285 286 287 |
# File 'lib/random_variates.rb', line 280 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.
278 279 280 |
# File 'lib/random_variates.rb', line 278 def alpha @alpha end |
#beta ⇒ Object (readonly)
Returns the value of attribute beta.
278 279 280 |
# File 'lib/random_variates.rb', line 278 def beta @beta end |
Instance Method Details
#next ⇒ Object
289 290 291 |
# File 'lib/random_variates.rb', line 289 def next __gen__(@alpha, @beta) end |