in online_attacks/online_algorithms/stochastic_virtual_ref.py [0:0]
def action(self, value: float, index: int):
if self.sampling_phase:
self.R.append([value, index])
self.R.sort(key=lambda tup: tup[0], reverse=True) # sorts in place
# self.R = self.R[:self.l]
self.R = self.R[: self.k]
if index >= self.threshold:
self.sampling_phase = False
else:
l_value, l_index = self.R[self.l]
num_picked = len(self.S)
num_left_to_pick = self.k - num_picked
num_samples_left = self.N - index
if (
num_samples_left <= num_left_to_pick
and self.exhaust
and num_left_to_pick > 0
):
# Just Pick the last samples to exhaust K
self.S.append([value, index])
elif value > l_value and num_left_to_pick > 0:
# Update and pick
self.S.append([value, index])
self.R.append([value, index])
self.R.sort(key=lambda tup: tup[0], reverse=True) # sorts in place
self.R = self.R[: self.k]
# Update L
self.l = min(self.k - 1, self.l + 1)