factor = factor_product(factor, *[self.factors[i] for i in range(1, len(self.factors))])
return np.sum(factor.values)
def check_model(self):
Check the model for various errors. This method checks for the following
errors. In the same time also updates the cardinalities of all the random
variables.
* Checks if clique potentials are defined for all the cliques or not.
* Check for running intersection property is not done explicitly over
here as it done in the add_edges method.
Returns
-------
check: boolean
True if all the checks are passed
for clique in self.nodes():
if self.get_factors(clique):
pass
else:
raise ValueError("Factors for all the cliques or clusters not"
"defined.")
if len(self.factors) != len(self.nodes()):
raise ValueError("One to one mapping of factor to clique or cluster"
"is not there.")
cardinalities = self.get_cardinality()
for factor in self.factors:
for variable, cardinality in zip(factor.scope(), factor.cardinality):
if (cardinalities[variable] != cardinality):
raise CardinalityError(
"Cardinality of variable %s not matching among factors" % variable)
return True