Class: ParentAccessor
- Inherits:
-
Object
- Object
- ParentAccessor
- Defined in:
- lib/fathom/archive/conditional_probability_matrix.rb
Instance Attribute Summary collapse
-
#child_indices ⇒ Object
readonly
Returns the value of attribute child_indices.
-
#child_labels ⇒ Object
readonly
Returns the value of attribute child_labels.
-
#cpm ⇒ Object
readonly
Returns the value of attribute cpm.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(cpm, child_labels) ⇒ ParentAccessor
constructor
A new instance of ParentAccessor.
- #is(*labels) ⇒ Object
- #is_not(*labels) ⇒ Object
Constructor Details
#initialize(cpm, child_labels) ⇒ ParentAccessor
Returns a new instance of ParentAccessor.
39 40 41 42 43 44 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 39 def initialize(cpm, child_labels) @cpm = cpm @child_labels = child_labels @node = cpm.parent @child_indices = child_labels.map {|label| @cpm.child.labels.index(label)} end |
Instance Attribute Details
#child_indices ⇒ Object (readonly)
Returns the value of attribute child_indices.
38 39 40 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 38 def child_indices @child_indices end |
#child_labels ⇒ Object (readonly)
Returns the value of attribute child_labels.
38 39 40 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 38 def child_labels @child_labels end |
#cpm ⇒ Object (readonly)
Returns the value of attribute cpm.
38 39 40 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 38 def cpm @cpm end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
38 39 40 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 38 def node @node end |
Instance Method Details
#is(*labels) ⇒ Object
46 47 48 49 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 46 def is(*labels) indices = labels.map {|label| get_index(label) } sum_probabilities(indices) end |
#is_not(*labels) ⇒ Object
51 52 53 54 55 |
# File 'lib/fathom/archive/conditional_probability_matrix.rb', line 51 def is_not(*labels) not_indices = labels.map {|label| get_index(label) } indices = (0..node.labels.size).to_a - not_indices sum_probabilities(indices) end |