MCPcopy Create free account
hub / github.com/modAL-python/modAL / max_entropy

Function max_entropy

examples/deep_bayesian_active_learning.py:57–67  ·  view source on GitHub ↗
(learner, X, n_instances=1, T=100)

Source from the content-addressed store, hash-verified

55"""
56
57def max_entropy(learner, X, n_instances=1, T=100):
58 random_subset = np.random.choice(X.shape[0], 2000, replace=False)
59 MC_output = K.function([learner.estimator.model.layers[0].input, K.learning_phase()],
60 [learner.estimator.model.layers[-1].output])
61 learning_phase = True
62 MC_samples = [MC_output([X[random_subset], learning_phase])[0] for _ in range(T)]
63 MC_samples = np.array(MC_samples) # [#samples x batch size x #classes]
64 expected_p = np.mean(MC_samples, axis=0)
65 acquisition = - np.sum(expected_p * np.log(expected_p + 1e-10), axis=-1) # [batch size]
66 idx = (-acquisition).argsort()[:n_instances]
67 return random_subset[idx]
68
69def uniform(learner, X, n_instances=1):
70 return np.random.choice(range(len(X)), size=n_instances, replace=False)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…