Class: Newral::Probability

Inherits:
Object
  • Object
show all
Defined in:
lib/newral/probability.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aprioriObject

Returns the value of attribute apriori.



4
5
6
# File 'lib/newral/probability.rb', line 4

def apriori
  @apriori
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/newral/probability.rb', line 4

def key
  @key
end

#probabilityObject (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