cbp.graph¶
cbp.graph.base_graph¶
-
class
cbp.graph.base_graph.
BaseGraph
(silent=True, epsilon=1, coef_policy=<function bp_policy>, config=BaseConfig())[source]¶ Bases:
object
-
add_factornode
(factornode)[source]¶ add one factor node to the graph Do the following tasks
add node to the recorders
set connections
set parent relation
- Parameters
factornode (FactorNode) – one factor node
- Returns
name of factor node
- Return type
-
copy_bp_initialization
(another_graph)[source]¶ copy message setup from the another graph has same structure
- Parameters
another_graph (BaseGraph) – another graph which close to the optimal point
-
delete_node
(name_str)[source]¶ delete node from graph, needs to check following
judge type, Factor or Variable
delete from the various recorders
clear connections
- Parameters
name_str ([type]) – [description]
- Raises
RuntimeError – [description]
-
export_convergence_marginals
()[source]¶ export the marginal for variable nodes and factor nodes
- Returns
{node.key:node.marginal}
- Return type
-
export_marginals
()[source]¶ export the marginal for variable nodes
- Returns
{node.key:node.marginal}
- Return type
-
plot
(png_name='file.png')[source]¶ plot the graph through graphviz
red: constrained variable node
blue: free variable node
green: factor
- Parameters
png_name (str, optional) – name of figure, defaults to ‘file.png’
- Raises
ValueError – [description]
-
pmf
()[source]¶ output the probability mass matrix through brutal-force methods
- Returns
joint probability mass matrix
- Return type
ndarray
-
set_node
(node_name, potential=None, isconstrained=None)[source]¶ change node property 1. check whether or not in recorder 2. change potential easily[this may a duplicate function] 3. change isconstrained if possible, delete from recorder
- Parameters
- Raises
RuntimeError – [description]
-
tree_bp
()[source]¶ run classical belief propagation on a tree graph, only need forward and backward
add attr: is_send_forward: begin send forward false, after forward
before backward true, after backward false
- Raises
RuntimeError – Only works for the tree graph, loopy graph does
not work, root node not decided
-