pgmpy.factors.factor_sum_product#

pgmpy.factors.factor_sum_product(output_vars, factors)[source]#

For a given set of factors: args returns the … result of $ \sum_{var \not \in output_vars} \prod \textit{args} $.

Parameters:
output_vars: list, iterable

List of variable names on which the output factor is to be defined. Variable which are present in any of the factors but not in output_vars will be marginalized out.

factors: list, iterable

List of DiscreteFactor objects on which to perform the sum product operation.

Returns:
pgmpy.factor.discrete.DiscreteFactor: A DiscreteFactor object on output_vars.

Examples

>>> from pgmpy.factors import factor_sum_product
>>> from pgmpy.example_models import load_model
>>> model = load_model("bnlearn/asia")
>>> factors = [cpd.to_factor() for cpd in model.cpds]
>>> factor_sum_product(output_vars=["lung"], factors=factors)
<DiscreteFactor representing phi(lung:2) at 0x...>