inferlo.GraphModel

class inferlo.GraphModel[source]

Abstract class representing any graphical model.

__init__(num_variables: int, domain: Domain)[source]
Parameters:
  • num_variables – Number of variables in the model.

  • domain – Default domain of each variable.

Methods

__init__(num_variables, domain)

add_factor(factor)

Adds a factor to the model.

draw_factor_graph(ax)

Draws the factor graph.

evaluate(x)

Returns value of non-normalized pdf in point.

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])

Performs inference.

max_likelihood([algorithm])

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.

abstractmethod add_factor(factor: Factor)[source]

Adds a factor to the model.

draw_factor_graph(ax)[source]

Draws the factor graph.

evaluate(x: ndarray) float[source]

Returns value of non-normalized pdf in point.

In other words, just substitutes values into factors and multiplies them.

get_factor_graph() Tuple[Graph, Dict[int, str]][source]

Builds factor graph for the model.

Factor graph is a bipartite graph with variables in one part and factors in other graph. Edge denotes that factor depends on variable.

abstractmethod get_factors() Iterable[Factor][source]

Returns all factors.

get_max_domain_size()[source]

Returns the biggest domain size over all variables.

get_symbolic_variables() List[FunctionFactor][source]

Prepares variables for usage in expressions.

Returns lists of trivial FunctionFactor s, each of them representing a factor on one variable with identity function. They can be used in mathematical expressions, which will result in another FunctionFactor.

get_variable(idx: int) Variable[source]

Returns variable by its index.

get_variables() List[Variable][source]

Returns all variables.

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

Performs inference.

abstractmethod max_likelihood(algorithm='auto', **kwargs) ndarray[source]

Finds the most probable state.

max_likelihood_bruteforce()[source]

Evaluates most likely state in a very inefficient way.

part_func_bruteforce()[source]

Evaluates partition function in very inefficient way.

sample(num_samples: int, algorithm='auto', **kwargs) ndarray[source]

Generates samples.