- class pomegranate.FactorGraph.FactorGraph¶
A Factor Graph model.
A bipartite graph where conditional probability tables are on one side, and marginals for each of the variables involved are on the other side.
- namestr, optional
The name of the model. Default is None.
Finalize the topology of the model.
Assign a numerical index to every state and create the underlying arrays corresponding to the states and edges between the states. This method must be called before any of the probability-calculating methods. This is the same as the HMM bake, except that at the end it sets current state information.
Deserialize this object from a dictionary of parameters.
Return the marginal probabilities of each variable in the graph.
This is equivalent to a pass of belief propagation on a graph where no data has been given. This will calculate the probability of each variable being in each possible emission when nothing is known.
- marginalsarray-like, shape (n_nodes)
An array of univariate distribution objects showing the marginal probabilities of that variable.
Draw this model’s graph using NetworkX and matplotlib.
Note that this relies on networkx’s built-in graphing capabilities (and not Graphviz) and thus can’t draw self-loops.
See networkx.draw_networkx() for the keywords you can pass in.
The arguments to pass into networkx.draw_networkx()
Returns the probabilities of each variable in the graph given evidence.
This calculates the marginal probability distributions for each state given the evidence provided through loopy belief propagation. Loopy belief propagation is an approximate algorithm which is exact for certain graph structures.
- datadict or array-like, shape <= n_nodes, optional
The evidence supplied to the graph. This can either be a dictionary with keys being state names and values being the observed values (either the emissions or a distribution over the emissions) or an array with the values being ordered according to the nodes incorporation in the graph (the order fed into .add_states/add_nodes) and None for variables which are unknown. If nothing is fed in then calculate the marginal of the graph.
- max_iterationsint, optional
The number of iterations with which to do loopy belief propagation. Usually requires only 1.
- check_inputbool, optional
Check to make sure that the observed symbol is a valid symbol for that distribution to produce.
- probabilitiesarray-like, shape (n_nodes)
An array of univariate distribution objects showing the probabilities of each variable.
Serialize this object to a dictionary of parameters.