ca09dcecea454e6552a7f30e57aef1dc4f2f295e,pgmpy/estimators/StructureScore.py,BDeuScore,local_score,#BDeuScore#Any#Any#,178

Before Change


        state_counts = self.state_counts(variable, parents)
        num_parents_states = float(len(state_counts.columns))

        score = 0
        for (
            parents_state
        ) in state_counts:  // iterate over df columns (only 1 if no parents)
            conditional_sample_size = sum(state_counts[parents_state])

            score += lgamma(self.equivalent_sample_size / num_parents_states) - lgamma(
                conditional_sample_size
                + self.equivalent_sample_size / num_parents_states
            )

            for state in var_states:
                if state_counts[parents_state][state] > 0:
                    score += lgamma(
                        state_counts[parents_state][state]
                        + self.equivalent_sample_size
                        / (num_parents_states * var_cardinality)
                    ) - lgamma(
                        self.equivalent_sample_size
                        / (num_parents_states * var_cardinality)
                    )
        return score


class BicScore(StructureScore):

After Change


        var_states = self.state_names[variable]
        var_cardinality = len(var_states)
        state_counts = self.state_counts(variable, parents)
        num_parents_states = float(state_counts.shape[1])

        counts = np.asarray(state_counts)
        log_gamma_counts = np.zeros_like(counts, dtype=np.float_)

        alpha = self.equivalent_sample_size / num_parents_states
        beta = self.equivalent_sample_size / counts.size

        // Compute log(gamma(counts + beta))
        gammaln(counts + beta, out=log_gamma_counts)

        // Compute the log-gamma conditional sample size
        log_gamma_conds = np.sum(counts, axis=0, dtype=np.float_)
        gammaln(log_gamma_conds + alpha, out=log_gamma_conds)

        score = (
            np.sum(log_gamma_counts)
            - np.sum(log_gamma_conds)
            + num_parents_states * lgamma(alpha)
            - counts.size * lgamma(beta)
        )

        return score

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 27

Instances


Project Name: pgmpy/pgmpy
Commit Name: ca09dcecea454e6552a7f30e57aef1dc4f2f295e
Time: 2020-08-11
Author: tristandeleu@users.noreply.github.com
File Name: pgmpy/estimators/StructureScore.py
Class Name: BDeuScore
Method Name: local_score


Project Name: pgmpy/pgmpy
Commit Name: ca09dcecea454e6552a7f30e57aef1dc4f2f295e
Time: 2020-08-11
Author: tristandeleu@users.noreply.github.com
File Name: pgmpy/estimators/StructureScore.py
Class Name: BicScore
Method Name: local_score


Project Name: pgmpy/pgmpy
Commit Name: ca09dcecea454e6552a7f30e57aef1dc4f2f295e
Time: 2020-08-11
Author: tristandeleu@users.noreply.github.com
File Name: pgmpy/estimators/StructureScore.py
Class Name: BDeuScore
Method Name: local_score


Project Name: pgmpy/pgmpy
Commit Name: ca09dcecea454e6552a7f30e57aef1dc4f2f295e
Time: 2020-08-11
Author: tristandeleu@users.noreply.github.com
File Name: pgmpy/estimators/StructureScore.py
Class Name: K2Score
Method Name: local_score