a35efe5121d35160a7f1ff8ca25af2c4eb035b99,pgmpy/models/ClusterGraph.py,ClusterGraph,check_model,#ClusterGraph#,242

Before Change



        for factor in self.factors:
            for variable, cardinality in zip(factor.scope(), factor.cardinality):
                if ((self.cardinalities[variable]) and
                        (self.cardinalities[variable] != cardinality)):
                    raise CardinalityError(
                        "Cardinality of variable %s not matching among factors" % variable)
                else:
                    self.cardinalities[variable] = cardinality

        return True

After Change


            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
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 11

Instances


Project Name: pgmpy/pgmpy
Commit Name: a35efe5121d35160a7f1ff8ca25af2c4eb035b99
Time: 2015-10-15
Author: yashuseth2503@gmail.com
File Name: pgmpy/models/ClusterGraph.py
Class Name: ClusterGraph
Method Name: check_model


Project Name: pgmpy/pgmpy
Commit Name: d33fd8b1c3df6f3336a92d70fc855ccf2260c672
Time: 2015-10-15
Author: yashuseth2503@gmail.com
File Name: pgmpy/models/MarkovModel.py
Class Name: MarkovModel
Method Name: check_model


Project Name: pgmpy/pgmpy
Commit Name: c4c31851ba38fb2428efd625d055aabd9e9c45f9
Time: 2015-10-15
Author: yashuseth2503@gmail.com
File Name: pgmpy/models/FactorGraph.py
Class Name: FactorGraph
Method Name: check_model