Skip to content

Commit bdf7252

Browse files
committed
fixed max_entropy function
1 parent 274f974 commit bdf7252

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/deep_bayesian_active_learning.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ def create_keras_model():
5454
"""
5555

5656
def max_entropy(learner, X, n_instances=1, T=100):
57-
subset = X[np.random.choice(range(len(X)), size=2000, replace=False)]
57+
random_subset = np.random.choice(X.shape[0], 2000, replace=False)
5858
MC_output = K.function([learner.estimator.model.layers[0].input, K.learning_phase()],
5959
[learner.estimator.model.layers[-1].output])
6060
learning_phase = True
61-
MC_samples = [MC_output([subset, learning_phase])[0] for _ in range(T)]
61+
MC_samples = [MC_output([X[random_subset], learning_phase])[0] for _ in range(T)]
6262
MC_samples = np.array(MC_samples) # [#samples x batch size x #classes]
6363
expected_p = np.mean(MC_samples, axis=0)
6464
acquisition = - np.sum(expected_p * np.log(expected_p + 1e-10), axis=-1) # [batch size]
65-
query_idx = (-acquisition).argsort()[:n_instances]
65+
idx = (-acquisition).argsort()[:n_instances]
66+
query_idx = random_subset[idx]
6667
return query_idx, X[query_idx]
6768

6869
def uniform(learner, X, n_instances=1):

0 commit comments

Comments
 (0)