class Rust::RandomVariableSlice

Public Class Methods

new(values) click to toggle source
# File lib/rust-probabilities.rb, line 36
def initialize(values)
    raise TypeError, "Expected Hash" unless values.is_a?(Hash)
    
    @values = values
end

Public Instance Methods

<(n) click to toggle source
# File lib/rust-probabilities.rb, line 66
def <(n)
    self.so_that { |k| k < n}
end
<=(n) click to toggle source
# File lib/rust-probabilities.rb, line 70
def <=(n)
    self.so_that { |k| k <= n}
end
==(n) click to toggle source
# File lib/rust-probabilities.rb, line 74
def ==(n)
    self.so_that { |k| k == n}
end
>(n) click to toggle source
# File lib/rust-probabilities.rb, line 58
def >(n)
    self.so_that { |k| k > n}
end
>=(n) click to toggle source
# File lib/rust-probabilities.rb, line 62
def >=(n)
    self.so_that { |k| k >= n}
end
between(a, b) click to toggle source
# File lib/rust-probabilities.rb, line 82
def between(a, b)
    RandomVariableSlice.new(@values.select { |k, v| k.between? a, b })
end
expected() click to toggle source
# File lib/rust-probabilities.rb, line 54
def expected
    @values.map { |k, v| k*v }.sum
end
ml() click to toggle source
# File lib/rust-probabilities.rb, line 50
def ml
    @values.max_by { |k, v| v }[0]
end
probability(v=nil) click to toggle source
# File lib/rust-probabilities.rb, line 42
def probability(v=nil)
    unless v
        return @values.values.sum
    else
        return @values[v]
    end
end
so_that() { |k| ... } click to toggle source
# File lib/rust-probabilities.rb, line 78
def so_that
    RandomVariableSlice.new(@values.select { |k, v| yield(k) })
end