Class: MiniPGM::Node
- Inherits:
-
Object
- Object
- MiniPGM::Node
- Defined in:
- lib/mini_pgm/node.rb
Overview
Represents an individual node, or random variable, in a model
Example string representation for a node with two incoming edges, and no outgoing edges:
{ Pollution, Smoker } -> Cancer -> { }
Or for nodes with no incoming edges and only outgoing edges:
{ } -> Pollution -> { Cancer }
{ } -> Smoker -> { Cancer }
Instance Attribute Summary collapse
-
#cpd ⇒ Object
Returns the value of attribute cpd.
-
#incoming_edges ⇒ Object
readonly
Returns the value of attribute incoming_edges.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#outgoing_edges ⇒ Object
readonly
Returns the value of attribute outgoing_edges.
Instance Method Summary collapse
-
#initialize(label) ⇒ Node
constructor
A new instance of Node.
- #to_s ⇒ Object
- #write_set(set) ⇒ Object
Constructor Details
#initialize(label) ⇒ Node
Returns a new instance of Node.
22 23 24 25 26 |
# File 'lib/mini_pgm/node.rb', line 22 def initialize(label) @label = label @incoming_edges = Set.new @outgoing_edges = Set.new end |
Instance Attribute Details
#cpd ⇒ Object
Returns the value of attribute cpd.
19 20 21 |
# File 'lib/mini_pgm/node.rb', line 19 def cpd @cpd end |
#incoming_edges ⇒ Object (readonly)
Returns the value of attribute incoming_edges.
20 21 22 |
# File 'lib/mini_pgm/node.rb', line 20 def incoming_edges @incoming_edges end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
20 21 22 |
# File 'lib/mini_pgm/node.rb', line 20 def label @label end |
#outgoing_edges ⇒ Object (readonly)
Returns the value of attribute outgoing_edges.
20 21 22 |
# File 'lib/mini_pgm/node.rb', line 20 def outgoing_edges @outgoing_edges end |
Instance Method Details
#to_s ⇒ Object
28 29 30 |
# File 'lib/mini_pgm/node.rb', line 28 def to_s [write_set(@incoming_edges), @label, write_set(@outgoing_edges)].join(' -> ') end |
#write_set(set) ⇒ Object
32 33 34 |
# File 'lib/mini_pgm/node.rb', line 32 def write_set(set) set.empty? ? '{ }' : "{ #{set.to_a.sort.join(', ')} }" end |