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.
- name : str, 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.
Read in a serialized FactorGraph and return the appropriate instance.
- s: str
A JSON formatted string containing the file.
- model: object
A properly instantiated and baked model.
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.
- marginals : array-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.
- **kwargs : any
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.
- data : dict 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_iterations : int, optional
The number of iterations with which to do loopy belief propagation. Usually requires only 1.
- check_input : bool, optional
Check to make sure that the observed symbol is a valid symbol for that distribution to produce.
- probabilities : array-like, shape (n_nodes)
An array of univariate distribution objects showing the probabilities of each variable.
Serialize the model to JSON
- separators: tuple, optional
The two separators to pass to the json.dumps function for formatting.
- indent: int, optional
The indentation to use at each level. Passed to json.dumps for formatting.