Module: PGM::Bidirectional
- Included in:
- BayesianNet
- Defined in:
- lib/pgm/bidirectional.rb
Overview
describe bidirectionally function to Graph
Instance Method Summary collapse
-
#create_link(u, v) ⇒ Object
assign link from u to v.
-
#create_var(name, states, parents: [], type: PGM::DiscreateVariable) ⇒ Object
Create variable.
-
#has_var?(name) ⇒ Boolean
Check if model has the variable named as input.
-
#initialize(edgelist_class = Set, *other_graphs) ⇒ Object
Instantiate DiscreateVariable.
-
#initialize_copy(orig) ⇒ Object
Copy internal vertices_dict.
-
#var(name = nil) ⇒ PGM::Variable
Return variable with the name.
Instance Method Details
#create_link(u, v) ⇒ Object
assign link from u to v
72 73 74 75 76 |
# File 'lib/pgm/bidirectional.rb', line 72 def create_link(u, v) if has_var?(u) && has_var?(v) var(v).to(var(u)) end end |
#create_var(name, states, parents: [], type: PGM::DiscreateVariable) ⇒ Object
Create variable
55 56 57 58 |
# File 'lib/pgm/bidirectional.rb', line 55 def create_var(name, states, parents: [], type: PGM::DiscreateVariable) add_vertex(name) @variables[name.to_sym] = type.new(self, name, states, parents: parents) end |
#has_var?(name) ⇒ Boolean
Check if model has the variable named as input
64 65 66 |
# File 'lib/pgm/bidirectional.rb', line 64 def has_var?(name) return @variables.has_key?(name.to_sym) end |
#initialize(edgelist_class = Set, *other_graphs) ⇒ Object
Instantiate DiscreateVariable
19 20 21 22 23 |
# File 'lib/pgm/bidirectional.rb', line 19 def initialize(edgelist_class = Set, *other_graphs) @vertices_rev_dict = Hash.new @variables = Hash.new super end |
#initialize_copy(orig) ⇒ Object
Copy internal vertices_dict
28 29 30 31 32 33 34 35 |
# File 'lib/pgm/bidirectional.rb', line 28 def initialize_copy(orig) super @vertices_rev_dict = orig.instance_eval { @vertices_rev_dict }.dup @vertices_rev_dict.keys.each do |v| @vertices_rev_dict[v] = @vertices_rev_dict[v].dup end @variables = orig.instance_eval { @variables }.dup end |
#var(name = nil) ⇒ PGM::Variable
Return variable with the name
41 42 43 44 45 46 47 |
# File 'lib/pgm/bidirectional.rb', line 41 def var(name=nil) if nil return @variables else return @variables[name.to_sym] end end |