class Statistical::Rng::TwoPoint

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

Attributes

generator[R]
p[R]
q[R]
states[R]

Public Class Methods

new(dobj = nil, seed = Random.new_seed) click to toggle source

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

@author Vaibhav Yenamandra

@attr_reader [Float] p Probability of success state @attr_reader [Float] q Probability of failure state @attr_reader [Hash] states Possible states that the RNG can take up @attr_reader [Object] generator The PRNG being used for randomness

# 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

Public Instance Methods

==(other)
Alias for: eql?
rand() click to toggle source

Return the next random number from the sequence following the given distribution

@return next random number in the sequence

# File lib/statistical/rng/two_point.rb, line 39
def rand
  return @sdist.quantile(@generator.rand)
end
support() click to toggle source

The support set over which the distribution exists

# File lib/statistical/rng/two_point.rb, line 62
def support
  @sdist.support
end
type() click to toggle source

Return the type of the source distribution

@return source distribution's type

# File lib/statistical/rng/two_point.rb, line 57
def type
  @sdist.class
end

Private Instance Methods

eql?(other) click to toggle source

Compare against another rng to see if they are the same

@return [Boolean] true if and only if, source distributions are the same

and the prng has the same initial state
# File lib/statistical/rng/two_point.rb, line 47
def eql?(other)
  return other.is_a?(self.class) &&
         @p = other.p &&
              @states == other.states &&
              @generator == other.generator
end
Also aliased as: ==