Class: Statistics::Distribution::Normal
- Inherits:
-
Object
- Object
- Statistics::Distribution::Normal
- Defined in:
- lib/statistics/distribution/normal.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mean ⇒ Object
(also: #mode)
Returns the value of attribute mean.
-
#standard_deviation ⇒ Object
Returns the value of attribute standard_deviation.
-
#variance ⇒ Object
Returns the value of attribute variance.
Instance Method Summary collapse
- #cumulative_function(value) ⇒ Object
- #density_function(value) ⇒ Object
-
#initialize(avg, std) ⇒ Normal
constructor
A new instance of Normal.
Constructor Details
#initialize(avg, std) ⇒ Normal
Returns a new instance of Normal.
7 8 9 10 11 |
# File 'lib/statistics/distribution/normal.rb', line 7 def initialize(avg, std) self.mean = avg.to_f self.standard_deviation = std.to_f self.variance = std.to_f**2 end |
Instance Attribute Details
#mean ⇒ Object Also known as: mode
Returns the value of attribute mean.
4 5 6 |
# File 'lib/statistics/distribution/normal.rb', line 4 def mean @mean end |
#standard_deviation ⇒ Object
Returns the value of attribute standard_deviation.
4 5 6 |
# File 'lib/statistics/distribution/normal.rb', line 4 def standard_deviation @standard_deviation end |
#variance ⇒ Object
Returns the value of attribute variance.
4 5 6 |
# File 'lib/statistics/distribution/normal.rb', line 4 def variance @variance end |
Instance Method Details
#cumulative_function(value) ⇒ Object
13 14 15 |
# File 'lib/statistics/distribution/normal.rb', line 13 def cumulative_function(value) (1/2.0) * (1.0 + Math.erf((value - mean)/(standard_deviation * Math.sqrt(2.0)))) end |
#density_function(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/statistics/distribution/normal.rb', line 17 def density_function(value) return 0 if standard_deviation <= 0 up_right = (value - mean)**2.0 down_right = 2.0 * variance right = Math.exp(-(up_right/down_right)) left_down = Math.sqrt(2.0 * Math::PI * variance) left_up = 1.0 (left_up/(left_down) * right) end |