Undirected Graphical Model
pyagrum.MarkovRandomField is the main class for representing and manipulating Markov random
fields in pyAgrum. It stores the undirected graph structure and the potential functions (tensors) over
its cliques.
- class pyagrum.MarkovRandomField(*args)
MarkovRandomField represents a Markov random field.
- MarkovRandomField(name=’’) -> MarkovRandomField
- Parameters:
name (str) – the name of the Bayes Net
- MarkovRandomField(source) -> MarkovRandomField
- Parameters:
source (
pyagrum.MarkovRandomField) – the Markov random field to copy
Scientific notes
A Markov random field represents a distribution as a normalized product of non negative factors,
each factor \(\phi_f\) being defined on a set of variables \(x_f\) (at most one factor per set). The graph of the model links two variables iff they appear in a common factor; by the Hammersley-Clifford theorem, the positive distributions that factorize over the cliques of an undirected graph are exactly those that satisfy its Markov properties [1]. The factors are not normalized and have no probabilistic meaning of their own.
fromBN uses the conditional probability tables of a Bayesian network as factors (then \(Z = 1\)), so that the
graph is the moral graph of the Bayesian network [2]; toDotAsFactorGraph draws the model
as a factor graph, a bipartite graph between the variables and the factors [3].
Methods
Add a variable to the |
|
Add a factor from a list or a set of id or str. |
|
Add the listeners in parameters to the list of existing ones. |
|
Add a list of variable in the form of ‘fast’ syntax. |
|
adjacency matrix from a graph/graphical models |
|
Begin a sequence of structural modifications (factor additions/deletions). |
|
change the label of the variable associated to nodeId to the new value. |
|
Changes a variable’s name in the |
|
Clear the whole MarkovRandomField |
|
Give an instantiation over all the variables of the model |
|
Return the connected components of the undirected model. |
|
number of connected components |
|
connected components as a dict of sets |
|
Return the dimension (total number of free parameters) of the Markov random field. |
|
Check if there are some variables in the model. |
|
Ends a sequence of insertions/deletions of factors started with |
|
Remove a variable from the |
|
Remove the factor that covers a given set of variables. |
|
Check if a node with this name or id exists |
|
Check whether an edge exists between two nodes. |
|
Check whether a property key exists in the model’s metadata. |
|
Returns the factor of a set of variables (if existing). |
|
Return the table of all factors in the Markov random field. |
|
Return the family of a node: the node and its parents. |
|
Create a Markov random field with a modified dot-like syntax which specifies: |
|
Create a Markov random field from a Bayesian network. |
|
Randomly generate factor parameters for a given factor in a given structure. |
|
Randomly generates factors parameters for a given structure. |
|
Return the underlying undirected graph. |
|
Check whether this model has the same undirected structure as another UGmodel. |
|
Return the node id of a variable given its name. |
|
List of ids for a list of names of variables in the model |
|
The ids of nodes given by their names, in a container of the same type. |
|
check if nodes X and nodes Y are independent given nodes Z |
|
Load a jgum (JSON) or bgum (binary/msgpack) file. |
|
Deserialize a MarkovRandomField from a jgum JSON string. |
|
Load an UAI file. |
|
returns the log10 of the domain size of the model defined as the product of the domain sizes of the variables in the model. |
|
Return the largest parameter different from 1 in the factors. |
|
Return the maximum parameter value across all factors. |
|
Return the maximum domain size among all variables in the model. |
|
Return the minimum non-zero parameter value across all factors. |
|
Return the minimum parameter value across all factors. |
|
Return a minimal conditioning set of a target given source nodes in the MRF. |
|
Set of names of variables in the model |
|
The names of nodes given by their ids, in a container of the same type. |
|
Return the set of neighbours of a node. |
|
Return the node id of a variable. |
|
Return the set of node ids in the model. |
|
Set of ids for a list of names of variables in the model |
|
Return the keys of all metadata properties of the model. |
|
Save the Markov random field as a .jgum (text) or .bgum (binary) file. |
|
Save the Markov random field as a jgum string. |
|
Save the MarkovRandomField in an UAI file. |
|
Return the number of nodes (variables) in the graphical model. |
|
Return the number of edges in the model. |
|
Return the id set of the smallest factor that contains the given node. |
|
Return a human-readable string summarising the space complexity of a graphical model. |
|
Return a Graphviz dot representation of the Markov random field. |
|
Return a Graphviz dot representation of the Markov random field as a factor graph. |
|
Export the Markov random field in fast syntax (the structure and the variables, not the parameters), read back by |
|
Update the model’s built-in metadata (version, creation date, last modification date). |
|
Return the variable associated with a given node id. |
|
Return the variable with the given name. |
|
Return the variables of the model: all of them, or those corresponding to a list of names or to a set of node ids. |