Class: Rust::RandomVariableSlice
- Defined in:
- lib/rust/stats/probabilities.rb
Direct Known Subclasses
Instance Method Summary collapse
- #<(n) ⇒ Object
- #<=(n) ⇒ Object
- #==(n) ⇒ Object
- #>(n) ⇒ Object
- #>=(n) ⇒ Object
- #between(a, b) ⇒ Object
- #expected ⇒ Object
-
#initialize(values) ⇒ RandomVariableSlice
constructor
A new instance of RandomVariableSlice.
- #ml ⇒ Object
- #probability(v = nil) ⇒ Object
- #so_that ⇒ Object
Constructor Details
#initialize(values) ⇒ RandomVariableSlice
Returns a new instance of RandomVariableSlice.
36 37 38 39 40 |
# File 'lib/rust/stats/probabilities.rb', line 36 def initialize(values) raise TypeError, "Expected Hash" unless values.is_a?(Hash) @values = values end |
Instance Method Details
#<(n) ⇒ Object
66 67 68 |
# File 'lib/rust/stats/probabilities.rb', line 66 def <(n) self.so_that { |k| k < n} end |
#<=(n) ⇒ Object
70 71 72 |
# File 'lib/rust/stats/probabilities.rb', line 70 def <=(n) self.so_that { |k| k <= n} end |
#==(n) ⇒ Object
74 75 76 |
# File 'lib/rust/stats/probabilities.rb', line 74 def ==(n) self.so_that { |k| k == n} end |
#>(n) ⇒ Object
58 59 60 |
# File 'lib/rust/stats/probabilities.rb', line 58 def >(n) self.so_that { |k| k > n} end |
#>=(n) ⇒ Object
62 63 64 |
# File 'lib/rust/stats/probabilities.rb', line 62 def >=(n) self.so_that { |k| k >= n} end |
#between(a, b) ⇒ Object
82 83 84 |
# File 'lib/rust/stats/probabilities.rb', line 82 def between(a, b) RandomVariableSlice.new(@values.select { |k, v| k.between? a, b }) end |
#expected ⇒ Object
54 55 56 |
# File 'lib/rust/stats/probabilities.rb', line 54 def expected @values.map { |k, v| k*v }.sum end |
#ml ⇒ Object
50 51 52 |
# File 'lib/rust/stats/probabilities.rb', line 50 def ml @values.max_by { |k, v| v }[0] end |
#probability(v = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rust/stats/probabilities.rb', line 42 def probability(v=nil) unless v return @values.values.sum else return @values[v] end end |
#so_that ⇒ Object
78 79 80 |
# File 'lib/rust/stats/probabilities.rb', line 78 def so_that RandomVariableSlice.new(@values.select { |k, v| yield(k) }) end |