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.
Checks that model is built.
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.
Returns edge-variable graph.
get_factor_graph
()Builds factor graph for the model.
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.
- 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.