inferlo.NormalFactorGraphModel

class inferlo.NormalFactorGraphModel[source]

Normal Factor Graph model.

Also known as Forney-style or Edge-Variable graphical model.

Variables correspond to edges of a graph, factors correspond to vertices of a graph.

Every variable appears in exactly two factors.

__init__(num_variables: int, domain: Domain)[source]

Initializes Normal Factor Graph model.

Parameters:
  • num_variables – Number of variables in the model.

  • domain – Default domain of each variable.

Methods

__init__(num_variables, domain)

Initializes Normal Factor Graph model.

add_factor(factor)

Add a factor.

build()

Validates the model and makes it immutable.

check_built()

Checks that model is built.

draw_edge_variable_graph(ax)

Draws edge-variable graph.

draw_factor_graph(ax)

Draws the factor graph.

evaluate(x)

Returns value of non-normalized pdf in point.

from_model(original_model)

Constructs NFG model which is equivalent to given model.

get_edge_variable_graph()

Returns edge-variable graph.

get_factor_graph()

Builds factor graph for the model.

get_factors()

Returns all factors.

get_max_domain_size()

Returns the biggest domain size over all variables.

get_symbolic_variables()

Prepares variables for usage in expressions.

get_variable(idx)

Returns variable by its index.

get_variables()

Returns all variables.

infer([algorithm])

Calculates partition function.

max_likelihood(algorithm, **kwargs)

Finds the most probable state.

max_likelihood_bruteforce()

Evaluates most likely state in a very inefficient way.

part_func_bruteforce()

Evaluates partition function in very inefficient way.

sample(num_samples[, algorithm])

Generates samples.

add_factor(factor: Factor)[source]

Add a factor.

build()[source]

Validates the model and makes it immutable.

check_built()[source]

Checks that model is built.

draw_edge_variable_graph(ax)[source]

Draws edge-variable graph.

static from_model(original_model: GraphModel)[source]

Constructs NFG model which is equivalent to given model.

If necessary, clones variables and adds factors.

Guarantees that first N variables in new model will correspond to variables in original model, where N is number of variables in original model.

get_edge_variable_graph() Graph[source]

Returns edge-variable graph.

get_factors() Iterable[Factor][source]

Returns all factors.

infer(algorithm='auto', **kwargs)[source]

Calculates partition function.

Available algorithms
  • auto - Automatic.

  • edge_elimination - Edge elimination.

Parameters:

algorithm – Which algorithm to use. String.

Returns:

Partition function.

max_likelihood(algorithm, **kwargs) ndarray[source]

Finds the most probable state.