Class: ERV::GeometricDistribution
- Inherits:
-
Distribution
- Object
- Distribution
- ERV::GeometricDistribution
- Defined in:
- lib/erv/geometric_distribution.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ GeometricDistribution
constructor
A new instance of GeometricDistribution.
Methods inherited from Distribution
Constructor Details
#initialize(opts) ⇒ GeometricDistribution
Returns a new instance of GeometricDistribution.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/erv/geometric_distribution.rb', line 10 def initialize(opts) super(opts) raise ArgumentError unless opts[:probability_of_success] p = opts[:probability_of_success].to_f if RUBY_PLATFORM == 'java' # create distribution d = JGeometricDistribution.new(@rng, p) # setup sampling function @func = Proc.new { d.sample } else # setup sampling function # # WARNING: I HAVEN'T TRIED THIS CODE!!! # Note that GSL implements the shifted version of the geometric # distribution, so we might need to change the result (removing 1?) @func = Proc.new { @rng.geometric(p) } end end |