(cls, predict_matrices)
return score
Calculate the average Kullback-Leibler (KL) divergence for measuring the
        level of disagreement in QBC.

        Parameters
        ----------
        predict_matrices: list
            The prediction matrix for each committee.
            Each committee predict matrix should have the shape [n_samples, n_classes] for probabilistic output
            or [n_samples] for class output.

        Returns
        -------
        score: list
            Score for each instance. Shape [n_samples]

        References
        ----------
        [1] A. McCallum and K. Nigam. Employing EM in pool-based active learning for
            text classification. In Proceedings of the International Conference on Machine
            Learning (ICML), pages 359-367. Morgan Kaufmann, 1998.
Calculate the average Kullback-Leibler (KL) divergence for measuring the
        level of disagreement in QBC.
Calculate the average Kullback - Leibler ( KL ) divergence for measuring the level of disagreement in QBC .
def calc_avg_KL_divergence(cls, predict_matrices):
        """Calculate the average Kullback-Leibler (KL) divergence for measuring the
        level of disagreement in QBC.

        Parameters
        ----------
        predict_matrices: list
            The prediction matrix for each committee.
            Each committee predict matrix should have the shape [n_samples, n_classes] for probabilistic output
            or [n_samples] for class output.

        Returns
        -------
        score: list
            Score for each instance. Shape [n_samples]

        References
        ----------
        [1] A. McCallum and K. Nigam. Employing EM in pool-based active learning for
            text classification. In Proceedings of the International Conference on Machine
            Learning (ICML), pages 359-367. Morgan Kaufmann, 1998.
        """
        score = []
        input_shape, committee_size = cls()._check_committee_results(predict_matrices)
        if len(input_shape) == 2:
            label_num = input_shape[1]
            # calc kl div for each instance
            for i in range(input_shape[0]):
                instance_mat = np.array([X[i, :] for X in predict_matrices if X is not None])
                tmp = 0
                # calc each label
                for lab in range(label_num):
                    committee_consensus = np.sum(instance_mat[:, lab]) / committee_size + 1e-9
                    for committee in range(committee_size):
                        tmp += instance_mat[committee, lab] * np.log((instance_mat[committee, lab]+1e-9) / committee_consensus)
                score.append(tmp)
        else:
            raise Exception(
                "A 2D probabilistic prediction matrix must be provided, with the shape like [n_samples, n_class]")
        return score
def calc_avg_KL_divergence ( cls , predict_matrices ) : score = [ ] input_shape , committee_size = cls ( ) . _check_committee_results ( predict_matrices ) if len ( input_shape ) == 2 : label_num = input_shape [ 1 ] # calc kl div for each instance for i in range ( input_shape [ 0 ] ) : instance_mat = np . array ( [ X [ i , : ] for X in predict_matrices if X is not None ] ) tmp = 0 # calc each label for lab in range ( label_num ) : committee_consensus = np . sum ( instance_mat [ : , lab ] ) / committee_size + 1e-9 for committee in range ( committee_size ) : tmp += instance_mat [ committee , lab ] * np . log ( ( instance_mat [ committee , lab ] + 1e-9 ) / committee_consensus ) score . append ( tmp ) else : raise Exception ( "A 2D probabilistic prediction matrix must be provided, with the shape like [n_samples, n_class]" ) return score