Class: Statistical::Rng::Bernoulli

Inherits:
TwoPoint
  • Object
show all
Defined in:
lib/statistical/rng/bernoulli.rb

Overview

This class models a bernoulli trial using the TwoPoint distribution as as base distribution / trial system.

Instance Attribute Summary

Attributes inherited from TwoPoint

#generator, #p, #q, #states

Instance Method Summary collapse

Methods inherited from TwoPoint

#rand, #support, #type

Constructor Details

#initialize(dobj = nil, seed = Random.new_seed) ⇒ Bernoulli

Companion RNG class for the Bernoulli distribution. Requires a distrbution object of the same type. Defaults to standard bernoulli if arguments are unspecified

Author:

  • Vaibhav Yenamandra



19
20
21
22
23
24
25
26
# File 'lib/statistical/rng/bernoulli.rb', line 19

def initialize(dobj = nil, seed = Random.new_seed)
  unless dobj.nil? || dobj.is_a?(Statistical::Distribution::Bernoulli)
    raise TypeError,
          "Expected Distribution object or nil, found #{dobj.class}"
  end
  dobj = Statistical::Distribution::Bernoulli.new if dobj.nil?
  super(dobj, seed)
end