Class: ERV::UniformDistribution
- Inherits:
-
Distribution
- Object
- Distribution
- ERV::UniformDistribution
- Defined in:
- lib/erv/uniform_distribution.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ UniformDistribution
constructor
A new instance of UniformDistribution.
- #sample ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ UniformDistribution
Returns a new instance of UniformDistribution.
8 9 10 11 12 13 14 15 |
# File 'lib/erv/uniform_distribution.rb', line 8 def initialize(opts={}) super(opts) raise ArgumentError unless opts[:max_value] max = opts[:max_value].to_f @min = opts[:min_value].try(:to_f) || 0.0 @range = max - @min end |
Instance Method Details
#sample ⇒ Object
17 18 19 20 21 22 |
# File 'lib/erv/uniform_distribution.rb', line 17 def sample # starting from a random variable X ~ U(0,1), which is provided by the # RNG, we can obtain a random variable Y ~ U(a,b) through location-scale # transformation: Y = a + (b-a) X. see [KROESE11], section 3.1.2.2. @min + @range * @rng.rand end |