Calculates the vote entropy for the Committee. First it computes the predictions of X for each learner in the Committee, then calculates the probability distribution of the votes. The entropy of this distribution is the vote entropy of the Committee, which is returned. Args:
(committee: BaseCommittee, X: modALinput, **predict_proba_kwargs)
| 14 | |
| 15 | |
| 16 | def vote_entropy(committee: BaseCommittee, X: modALinput, **predict_proba_kwargs) -> np.ndarray: |
| 17 | """ |
| 18 | Calculates the vote entropy for the Committee. First it computes the predictions of X for each learner in the |
| 19 | Committee, then calculates the probability distribution of the votes. The entropy of this distribution is the vote |
| 20 | entropy of the Committee, which is returned. |
| 21 | |
| 22 | Args: |
| 23 | committee: The :class:`modAL.models.BaseCommittee` instance for which the vote entropy is to be calculated. |
| 24 | X: The data for which the vote entropy is to be calculated. |
| 25 | **predict_proba_kwargs: Keyword arguments for the :meth:`predict_proba` of the Committee. |
| 26 | |
| 27 | Returns: |
| 28 | Vote entropy of the Committee for the samples in X. |
| 29 | """ |
| 30 | n_learners = len(committee) |
| 31 | try: |
| 32 | votes = committee.vote(X, **predict_proba_kwargs) |
| 33 | except NotFittedError: |
| 34 | return np.zeros(shape=(X.shape[0],)) |
| 35 | |
| 36 | p_vote = np.zeros(shape=(X.shape[0], len(committee.classes_))) |
| 37 | |
| 38 | for vote_idx, vote in enumerate(votes): |
| 39 | vote_counter = Counter(vote) |
| 40 | |
| 41 | for class_idx, class_label in enumerate(committee.classes_): |
| 42 | p_vote[vote_idx, class_idx] = vote_counter[class_label]/n_learners |
| 43 | |
| 44 | entr = entropy(p_vote, axis=1) |
| 45 | return entr |
| 46 | |
| 47 | |
| 48 | def consensus_entropy(committee: BaseCommittee, X: modALinput, **predict_proba_kwargs) -> np.ndarray: |
no test coverage detected
searching dependent graphs…