Last active
April 1, 2018 18:22
-
-
Save kris-singh/53b1c6c687ce2b44c0140f87628ea370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SelectLoss: | |
""" | |
Selection based on Loss values of samples. | |
No need of rejection sampling. | |
""" | |
def __init__(self, X, Y, fwd_batch_size, batch_size, _, loss): | |
""" | |
:param loss: loss function | |
:param x_train: training dataN | |
:param y_train: training labels | |
""" | |
self.X = X | |
self.Y = Y | |
self.fwd_batch_size = fwd_batch_size | |
self.batch_size = batch_size | |
self.loss = loss | |
def sample(self, model): | |
""" | |
Sort the loss values of the training samples. | |
Variables | |
""" | |
idx = np.random.choice (np.arange (0, self.X.shape[0]), size=self.fwd_batch_size, replace=False) | |
res = model.predict_proba (self.X[idx]) | |
res = K.get_value (tf.nn.softmax_cross_entropy_with_logits (labels=y_train[idx], logits=res)) | |
res = res / np.sum (res) | |
return np.random.choice (idx, | |
size=self.batch_size, | |
replace=False, | |
p=res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment