Class: ERV::GpdDistribution
- Inherits:
-
Distribution
- Object
- Distribution
- ERV::GpdDistribution
- Defined in:
- lib/erv/general_pareto_distribution.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ GpdDistribution
constructor
A new instance of GpdDistribution.
Methods inherited from Distribution
Constructor Details
#initialize(opts) ⇒ GpdDistribution
Returns a new instance of GpdDistribution.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/erv/general_pareto_distribution.rb', line 13 def initialize(opts) super(opts) raise ArgumentError unless opts[:scale] and opts[:shape] scale = opts[:scale].to_f shape = opts[:shape].to_f location = opts[:location].try(:to_f) || 0.0 if RUBY_PLATFORM == 'java' # create uniform distribution d = UniformRealDistribution.new(@rng, 0.0, 1.0, UniformRealDistribution::DEFAULT_INVERSE_ABSOLUTE_ACCURACY) # setup sampling function @func = Proc.new { # this algorithm was taken from wikipedia u = 1.0 - d.sample location + (scale * ((u ** (-shape)) - 1.0) / shape) } else # setup sampling function @func = Proc.new { # this algorithm was taken from wikipedia u = 1.0 - @rng.uniform location + (scale * ((u ** (-shape)) - 1.0) / shape) } end end |