Class: Statistical::Rng::TwoPoint
- Inherits:
-
Object
- Object
- Statistical::Rng::TwoPoint
- Defined in:
- lib/statistical/rng/two_point.rb
Overview
Random number generator to model the two point distribution used for working with problem where the state space has only two points with distinct probabilities
Direct Known Subclasses
Instance Attribute Summary collapse
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#p ⇒ Object
readonly
Returns the value of attribute p.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
-
#initialize(dobj = nil, seed = Random.new_seed) ⇒ TwoPoint
constructor
Companion RNG class for the two-point distribution.
-
#rand ⇒ Object
Return the next random number from the sequence following the given distribution.
-
#support ⇒ Object
The support set over which the distribution exists.
-
#type ⇒ Object
Return the type of the source distribution.
Constructor Details
#initialize(dobj = nil, seed = Random.new_seed) ⇒ TwoPoint
Companion RNG class for the two-point distribution. Requires a distrbution object of the corresponding type. Defaults to the standard bernoulli if no arguments are given
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statistical/rng/two_point.rb', line 22 def initialize(dobj = nil, seed = Random.new_seed) unless dobj.nil? || dobj.is_a?(Statistical::Distribution::TwoPoint) raise TypeError, "Expected Distribution object or nil, found #{dobj.class}" end dobj = Statistical::Distribution::TwoPoint.new if dobj.nil? @generator = Random.new(seed) @sdist = dobj @p = dobj.p @q = dobj.q @states = dobj.states end |
Instance Attribute Details
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
10 11 12 |
# File 'lib/statistical/rng/two_point.rb', line 10 def generator @generator end |
#p ⇒ Object (readonly)
Returns the value of attribute p.
10 11 12 |
# File 'lib/statistical/rng/two_point.rb', line 10 def p @p end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
10 11 12 |
# File 'lib/statistical/rng/two_point.rb', line 10 def q @q end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
10 11 12 |
# File 'lib/statistical/rng/two_point.rb', line 10 def states @states end |
Instance Method Details
#rand ⇒ Object
Return the next random number from the sequence following the given distribution
39 40 41 |
# File 'lib/statistical/rng/two_point.rb', line 39 def rand return @sdist.quantile(@generator.rand) end |
#support ⇒ Object
The support set over which the distribution exists
62 63 64 |
# File 'lib/statistical/rng/two_point.rb', line 62 def support @sdist.support end |
#type ⇒ Object
Return the type of the source distribution
57 58 59 |
# File 'lib/statistical/rng/two_point.rb', line 57 def type @sdist.class end |