if pred == target:
x_adv = potential_adv
self.curr_epsilon /= self.step_adapt
break
else:
self.curr_epsilon *= self.step_adapt
else:
logging.warning("Adversarial example found but not optimal.")
After Change
self.curr_delta /= self.step_adapt
if delta_ratio > 0:
x_advs = np.array(potential_advs)[np.where(satisfied)[0]]
break
else:
logging.warning("Adversarial example found but not optimal.")
return x_adv
// Trust region method to adjust epsilon
for _ in range(self.num_trial):
perturb = np.repeat(np.array([original_sample]), len(x_advs), axis=0) - x_advs
perturb *= self.curr_epsilon
potential_advs = x_advs + perturb
potential_advs = np.clip(potential_advs, clip_min, clip_max)
preds = np.argmax(self.classifier.predict(potential_advs), axis=1)
satisfied = (preds == target)
epsilon_ratio = np.mean(satisfied)
if epsilon_ratio < 0.2:
self.curr_epsilon *= self.step_adapt
elif epsilon_ratio > 0.5: