class MiniPGM::Node

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 }

Attributes

cpd[RW]
incoming_edges[R]
label[R]
outgoing_edges[R]

Public Class Methods

new(label) click to toggle source
# File lib/mini_pgm/node.rb, line 22
def initialize(label)
  @label = label
  @incoming_edges = Set.new
  @outgoing_edges = Set.new
end

Public Instance Methods

to_s() click to toggle source
# 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) click to toggle source
# File lib/mini_pgm/node.rb, line 32
def write_set(set)
  set.empty? ? '{ }' : "{ #{set.to_a.sort.join(', ')} }"
end