API Reference

Graphical models

Classes representing different kinds of graphical models.

inferlo.GaussianModel

Gaussian graphical model

inferlo.GenericGraphModel

Graphical model in the most general form.

inferlo.GraphModel

Abstract class representing any graphical model.

inferlo.NormalFactorGraphModel

Normal Factor Graph model.

inferlo.PairWiseFiniteModel

Pairwise finite graphical model.

Auxiliary classes

Classes representing elementary concepts, such as variables and factors. Also contains data classes representing results of computations.

inferlo.DiscreteDomain

Domain consisting of finite set of numbers.

inferlo.Domain

Describes set of values which a variable can take.

inferlo.Factor

Abstract factor - function of one or more random variables.

inferlo.DiscreteFactor

A factor of several discrete variables.

inferlo.FunctionFactor

A factor given explicitly by function.

inferlo.InferenceResult

Inference result for discrete graphical model.

inferlo.RealDomain

Domain consisting of all real values.

inferlo.Variable

Random variable.

Algorithms on graphical models

All algorithms are available through methods on graphical models. To invoke specific algorithm, you should pass its name as “algorithm” argument to corresponding methods. That’s why algorithms are not exported in top-level package.

However, we list all algorithms here for reference. Some algorithms may take additional parameters (such as number of iterations for iterative algorithm), which should be passed as keyword arguments. Use references below to get information on algorithm-specific parameters.

Inference algorithms

inferlo.forney.edge_elimination.infer_edge_elimination(model)

Calculates partition function using Edge Elimination.

inferlo.generic.libdai_bp.BP

Belief propagation algorithm, equivalent to dai::BP.

inferlo.generic.inference.inference

inferlo.generic.inference.BackwardBucketElimination

Backward Bucket Elimination algorithm.

inferlo.gaussian.inference.gaussian_belief_propagation.gaussian_BP(model)

Inference with Gaussian Belief Propagation.

inferlo.pairwise.bruteforce.infer_bruteforce(model)

Inference by summing up all states.

inferlo.pairwise.junction_tree.infer_junction_tree(model)

Performs inference using Junction Tree decomposition.

inferlo.pairwise.inference.mean_field.infer_mean_field(model)

Inference with Naive Mean Field.

inferlo.pairwise.inference.message_passing.infer_message_passing(model)

Inference with Message Passing.

inferlo.pairwise.inference.path_dp.infer_path_dp(model)

Inference using DP on path decomposition.

inferlo.pairwise.inference.tree_dp.infer_tree_dp(model)

Inference using DP on tree.

Optimization algorithms

inferlo.forney.optimization.nfg_map_lp.map_lp(model)

LP relaxation of MAP problem for NFG model.

inferlo.pairwise.bruteforce.max_lh_bruteforce(model)

Finds max likelihood for pairwise model by checking all states.

inferlo.pairwise.junction_tree.max_likelihood_junction_tree(model)

Finds most probable state using Junction Tree decomposition.

inferlo.pairwise.optimization.convex_bounds.lp_relaxation(model)

Max Likelihood for pairwise model by solving LP relaxation.

inferlo.pairwise.optimization.convex_hierarchies.lasserre(model)

This is an implementation of Lasserre hierarchy.

inferlo.pairwise.optimization.convex_hierarchies.sherali_adams(model)

This is an implementation of Sherali-Adams hierarchy, also called lift-and-project method.

inferlo.pairwise.optimization.map_lp.map_lp(model)

LP relaxation of MAP problem for pairwise model.

inferlo.pairwise.optimization.path_dp.max_lh_path_dp(model)

Max Likelihood for pairwise model with DP on path decomposition.

inferlo.pairwise.optimization.tree_dp.max_likelihood_tree_dp(model)

Max Likelihood for the pairwise model.

Sampling algorithms

inferlo.pairwise.bruteforce.sample_bruteforce(...)

Samples from Pairwise Finite model.

inferlo.pairwise.junction_tree.sample_junction_tree(...)

IID sampling using Junction Tree decomposition.

inferlo.pairwise.sampling.tree_dp.sample_tree_dp(...)

Draws iid samples with dynamic programming on tree.

Model conversion algorithms

inferlo.pairwise.junction_tree.to_junction_tree_model(...)

Builds equivalent model on a junction tree.

Algorithm on graphs

In most cases we use NetworkX to represent and manipulate graphs. However, in some cases, if the algorithm is too specific and is not available in NetworkX, or if we need it to be faster than in NetworkX, we implement it in our library. Those implementations are collected in this section. They are intended for internal usage by other algorithms rather than to be used directly by library users.

inferlo.graphs.fast_dfs(vert_num, edges)

Depth-first search.

inferlo.graphs.path_decomposition(graph)

Path decomposition of a graph.

Model generators

These function generate random models of certain structure. They are useful for testing and benchmarking.

inferlo.testing.clique_potts_model([...])

Generates random PairWiseFinteModel on a clique.

inferlo.testing.grid_potts_model(height, width)

Generates random PairWiseFinteModel on a grid.

inferlo.testing.ising_model_on_graph(graph)

Builds random Ising model on given graph.

inferlo.testing.pairwise_model_on_graph(graph)

Builds random pairwise model with given interaction graph.

inferlo.testing.line_potts_model([gr_size, ...])

Generates random PairWiseFinteModel on a line graph.

inferlo.testing.random_generic_model([...])

Generates random discrete graphical model of arbitrary structure.

inferlo.testing.tree_potts_model([gr_size, ...])

Generates random PairWiseFinteModel on a random tree.

Interoperation

These classes are repossible for interoperation with other GM libraries.

inferlo.interop.LibDaiInterop

Interoperation with libDAI.

Datasets

Helpers to load public datasets with graphical models.

inferlo.datasets.Dataset

Dataset containing GM and true answers.

inferlo.datasets.DatasetLoader

Loads graphical models from named datasets.

inferlo.datasets.UaiReader

Reads files in UAI format.