Module: PGM::Bidirectional

Included in:
BayesianNet
Defined in:
lib/pgm/bidirectional.rb

Overview

describe bidirectionally function to Graph

Instance Method Summary collapse

Instance Method Details

assign link from u to v

Parameters:



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

Parameters:

  • name (String, Symbol)

    Name of variable

  • states (Array<String, Symbol>)

    List of variable states

  • parents (Array<PGM::Variable>) (defaults to: [])

    List of parent variable

  • type (PGM::Variable) (defaults to: PGM::DiscreateVariable)

    type of 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

Parameters:

  • name (String, Symbol)

    Name of variable

Returns:

  • (Boolean)

    if model has the variable



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

Parameters:

  • edgelist_class (Object) (defaults to: Set)

    Object to store edge class

  • other_graphs (PGM::BayesianNet)

    List of variable states



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

Parameters:



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

Parameters:

  • name (String, Symbol) (defaults to: nil)

    The name of variable

Returns:



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