Class: Newral::Probability
- Inherits:
-
Object
- Object
- Newral::Probability
- Defined in:
- lib/newral/probability.rb
Instance Attribute Summary collapse
-
#apriori ⇒ Object
Returns the value of attribute apriori.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#probability ⇒ Object
readonly
Returns the value of attribute probability.
Instance Method Summary collapse
- #! ⇒ Object
- #*(other_probability) ⇒ Object
- #+(other_probability) ⇒ Object
- #/(other_probability) ⇒ Object
- #and(other_probability) ⇒ Object
-
#initialize(key, probability, apriori: nil) ⇒ Probability
constructor
A new instance of Probability.
- #or(other_probability) ⇒ Object
Constructor Details
#initialize(key, probability, apriori: nil) ⇒ Probability
Returns a new instance of Probability.
5 6 7 8 9 10 |
# File 'lib/newral/probability.rb', line 5 def initialize( key, probability, apriori:nil ) @key = key @probability = probability @apriori = apriori @key = "#{key}|#{apriori}" if apriori end |
Instance Attribute Details
#apriori ⇒ Object
Returns the value of attribute apriori.
4 5 6 |
# File 'lib/newral/probability.rb', line 4 def apriori @apriori end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/newral/probability.rb', line 4 def key @key end |
#probability ⇒ Object (readonly)
Returns the value of attribute probability.
4 5 6 |
# File 'lib/newral/probability.rb', line 4 def probability @probability end |
Instance Method Details
#! ⇒ Object
20 21 22 |
# File 'lib/newral/probability.rb', line 20 def ! Probability.new("!#{key}",1-probability) end |
#*(other_probability) ⇒ Object
12 13 14 |
# File 'lib/newral/probability.rb', line 12 def *( other_probability ) Probability.new("#{self.key}*#{other_probability.key}",self.probability*other_probability.probability) end |
#+(other_probability) ⇒ Object
24 25 26 |
# File 'lib/newral/probability.rb', line 24 def+(other_probability) Probability.new("#{self.key}+#{other_probability.key}",self.probability+other_probability.probability) end |
#/(other_probability) ⇒ Object
16 17 18 |
# File 'lib/newral/probability.rb', line 16 def /( other_probability ) Probability.new("#{self.key}/#{other_probability.key}",self.probability/other_probability.probability) end |
#and(other_probability) ⇒ Object
32 33 34 |
# File 'lib/newral/probability.rb', line 32 def and( other_probability ) Probability.new("#{self.key}^#{other_probability.key}",self.probability*other_probability.probability) end |
#or(other_probability) ⇒ Object
36 37 38 |
# File 'lib/newral/probability.rb', line 36 def or( other_probability ) Probability.new("#{self.key}*#{other_probability.key}",self.probability*other_probability.probability) end |