Class: ERV::GaussianDistribution
Constant Summary
Constants inherited
from Distribution
Distribution::DEFAULT_SEED
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GaussianDistribution.
7
8
9
10
11
12
13
|
# File 'lib/erv/gaussian_distribution.rb', line 7
def initialize(opts={})
super(opts)
raise ArgumentError unless opts[:mean] and opts[:sd]
@mu = opts[:mean].to_f
@sigma = opts[:sd].to_f
end
|
Instance Method Details
#mean ⇒ Object
27
28
29
|
# File 'lib/erv/gaussian_distribution.rb', line 27
def mean
@mu
end
|
#sample ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/erv/gaussian_distribution.rb', line 15
def sample
u_1 = @rng.rand
u_2 = @rng.rand
x = Math.sqrt(-2.0 * Math.log(u_1)) * Math.cos(2.0 * Math::PI * u_2)
@mu + @sigma * x
end
|
#variance ⇒ Object
31
32
33
|
# File 'lib/erv/gaussian_distribution.rb', line 31
def variance
@sigma ** 2
end
|