Calculates the max disagreement for the Committee. First it computes the class probabilties of X for each learner in the Committee, then calculates the consensus probability distribution by averaging the individual class probabilities for each learner. Then each learner's class probabil
(committee: BaseCommittee, X: modALinput, **predict_proba_kwargs)
| 70 | |
| 71 | |
| 72 | def KL_max_disagreement(committee: BaseCommittee, X: modALinput, **predict_proba_kwargs) -> np.ndarray: |
| 73 | """ |
| 74 | Calculates the max disagreement for the Committee. First it computes the class probabilties of X for each learner in |
| 75 | the Committee, then calculates the consensus probability distribution by averaging the individual class |
| 76 | probabilities for each learner. Then each learner's class probabilities are compared to the consensus distribution |
| 77 | in the sense of Kullback-Leibler divergence. The max disagreement for a given sample is the argmax of the KL |
| 78 | divergences of the learners from the consensus probability. |
| 79 | |
| 80 | Args: |
| 81 | committee: The :class:`modAL.models.BaseCommittee` instance for which the max disagreement is to be calculated. |
| 82 | X: The data for which the max disagreement is to be calculated. |
| 83 | **predict_proba_kwargs: Keyword arguments for the :meth:`predict_proba` of the Committee. |
| 84 | |
| 85 | Returns: |
| 86 | Max disagreement of the Committee for the samples in X. |
| 87 | """ |
| 88 | try: |
| 89 | p_vote = committee.vote_proba(X, **predict_proba_kwargs) |
| 90 | except NotFittedError: |
| 91 | return np.zeros(shape=(X.shape[0],)) |
| 92 | |
| 93 | p_consensus = np.mean(p_vote, axis=1) |
| 94 | |
| 95 | learner_KL_div = np.zeros(shape=(X.shape[0], len(committee))) |
| 96 | for learner_idx, _ in enumerate(committee): |
| 97 | learner_KL_div[:, learner_idx] = entropy(np.transpose(p_vote[:, learner_idx, :]), qk=np.transpose(p_consensus)) |
| 98 | |
| 99 | return np.max(learner_KL_div, axis=1) |
| 100 | |
| 101 | |
| 102 | def vote_entropy_sampling(committee: BaseCommittee, X: modALinput, |
no test coverage detected
searching dependent graphs…