Class: RubyStatistics::Distribution::Uniform
- Inherits:
-
Object
- Object
- RubyStatistics::Distribution::Uniform
- Defined in:
- lib/ruby-statistics/distribution/uniform.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
- #cumulative_function(value) ⇒ Object
- #density_function(value) ⇒ Object
-
#initialize(a, b) ⇒ Uniform
constructor
A new instance of Uniform.
- #mean ⇒ Object (also: #median)
- #variance ⇒ Object
Constructor Details
#initialize(a, b) ⇒ Uniform
Returns a new instance of Uniform.
6 7 8 9 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 6 def initialize(a, b) self.left = a.to_r self.right = b.to_r end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
4 5 6 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 4 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
4 5 6 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 4 def right @right end |
Instance Method Details
#cumulative_function(value) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 19 def cumulative_function(value) if value < left 0 elsif value >= left && value <= right (value - left)/(right - left) else 1 end end |
#density_function(value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 11 def density_function(value) if value >= left && value <= right 1/(right - left) else 0 end end |
#mean ⇒ Object Also known as: median
29 30 31 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 29 def mean (1/2.0) * ( left + right ) end |
#variance ⇒ Object
35 36 37 |
# File 'lib/ruby-statistics/distribution/uniform.rb', line 35 def variance (1/12.0) * ( right - left ) ** 2 end |