inferlo.DiscreteFactor
- class inferlo.DiscreteFactor[source]
A factor of several discrete variables.
- __init__(model: GraphModel, var_idx: List[int], values: np.ndarray)[source]
- Parameters:
model – Graphical model this factor belongs to.
var_idx – Indices of variables in the model, on which this factor depends.
Methods
__init__
(model, var_idx, values)clone
(new_model)Creates the same factor, but pointing to new model.
from_factor
(factor)Converts arbitrary factor to DiscreteFactor.
from_flat_values
(model, var_idx, values_flat)Creates factor specified by list of values.
get_name
()Name of this factor.
is_discrete
()Whether all variables in the factor are discrete.
marginal
(new_var_idx)Marginalizes factor on subset of variables.
max_marginal
(new_var_idx)Marginalizes factor on subset of variables, using MAX-PROD.
restrict
(variable_id, fixed_value)Fixes value of one variable.
value
(x)Value of function inside this factor in given point.
- static from_factor(factor: Factor) DiscreteFactor [source]
Converts arbitrary factor to DiscreteFactor.
Returns None if some variables of the factor are not discrete.
- static from_flat_values(model: GraphModel, var_idx: List[int], values_flat: np.ndarray)[source]
Creates factor specified by list of values.
- Parameters:
model – GM to which this factor belongs.
var_idx – Indices of variables.
values_flat – 1D list of values. Last variable is “least significant”.
- marginal(new_var_idx: List[int]) DiscreteFactor [source]
Marginalizes factor on subset of variables.
- max_marginal(new_var_idx: List[int]) DiscreteFactor [source]
Marginalizes factor on subset of variables, using MAX-PROD.
- restrict(variable_id, fixed_value) DiscreteFactor [source]
Fixes value of one variable.
Returns new factor which is equivalent to original factor, but with value of one variable fixed.