Class: ERV::LogNormDistribution
Constant Summary
Constants inherited
from Distribution
Distribution::DEFAULT_SEED
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LogNormDistribution.
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/erv/lognorm_distribution.rb', line 5
def initialize(opts = {})
super(opts)
raise ArgumentError, 'mu is required' unless opts[:mu]
raise ArgumentError, 'sigma is required' unless opts[:sigma]
raise ArgumentError, 'sigma must be greater than zero' unless opts[:sigma].to_f > 0.0
@mu = opts[:mu].to_f
@sigma = opts[:sigma].to_f
@gaussian_dist = GaussianDistribution.new(mean: @mu, sd: @sigma)
end
|
Instance Method Details
#mean ⇒ Object
24
25
26
|
# File 'lib/erv/lognorm_distribution.rb', line 24
def mean
Math.exp(@mu + 0.5 * @sigma**2)
end
|
#sample ⇒ Object
19
20
21
22
|
# File 'lib/erv/lognorm_distribution.rb', line 19
def sample
Math.exp(@gaussian_dist.sample)
end
|
#variance ⇒ Object
28
29
30
|
# File 'lib/erv/lognorm_distribution.rb', line 28
def variance
Math.exp(2 * @mu + @sigma**2) * (Math.exp(@sigma**2) - 1)
end
|