Class: Mjai::Manue::HoraPointsEstimate::ProbablisticFan
- Inherits:
-
Object
- Object
- Mjai::Manue::HoraPointsEstimate::ProbablisticFan
- Defined in:
- lib/mjai/manue/hora_points_estimate.rb
Instance Attribute Summary collapse
-
#probs ⇒ Object
readonly
Returns the value of attribute probs.
Class Method Summary collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #apply(other, &block) ⇒ Object
- #expected ⇒ Object
-
#initialize(arg) ⇒ ProbablisticFan
constructor
A new instance of ProbablisticFan.
- #max(other) ⇒ Object
Constructor Details
#initialize(arg) ⇒ ProbablisticFan
Returns a new instance of ProbablisticFan.
41 42 43 44 45 46 47 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 41 def initialize(arg) if arg.is_a?(Integer) @probs = {arg => 1.0} else @probs = arg end end |
Instance Attribute Details
#probs ⇒ Object (readonly)
Returns the value of attribute probs.
49 50 51 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 49 def probs @probs end |
Class Method Details
.prob_average(pfans) ⇒ Object
27 28 29 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 27 def self.prob_average(pfans) return prob_weighted_average(pfans.map(){ |pf| [pf, 1.0 / pfans.size] }) end |
.prob_weighted_average(weighted_pfans) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 31 def self.prob_weighted_average(weighted_pfans) new_probs = Hash.new(0.0) for pfan, weight in weighted_pfans for fan, prob in pfan.probs new_probs[fan] += prob * weight end end return ProbablisticFan.new(new_probs) end |
Instance Method Details
#*(other) ⇒ Object
55 56 57 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 55 def *(other) return apply(other){ |f1, f2| f1 * f2 } end |
#+(other) ⇒ Object
51 52 53 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 51 def +(other) return apply(other){ |f1, f2| f1 + f2 } end |
#apply(other, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 67 def apply(other, &block) new_probs = Hash.new(0.0) for f1, p1 in @probs for f2, p2 in other.probs new_probs[block.call(f1, f2)] += p1 * p2 if p1 * p2 > 0.0 end end return ProbablisticFan.new(new_probs) end |
#expected ⇒ Object
63 64 65 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 63 def expected @probs.map(){ |f, pr| f * pr }.inject(0.0, :+) end |
#max(other) ⇒ Object
59 60 61 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 59 def max(other) return apply(other){ |f1, f2| [f1, f2].max } end |