in online_attacks/online_algorithms/stochastic_single_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.k]
if index >= self.threshold:
self.sampling_phase = False
else:
num_picked = len(self.S)
num_left_to_pick = self.k - num_picked
num_samples_left = self.N - index
if num_left_to_pick > 0:
r_value, r_index = self.R[self.r - 1] # 0-based indexing.
if num_samples_left <= num_left_to_pick and self.exhaust:
# Just Pick the last samples to exhaust K
self.S.append([value, index])
elif value > r_value:
# Pick
self.S.append([value, index])