in online_attacks/datastream/toy_data.py [0:0]
def __init__(self, N: int, max_perms: int = 120, eps: float = 1.0):
self.perms = []
self.noisy_perms = []
total_perms = np.math.factorial(N)
max_perms = np.minimum(max_perms, total_perms)
mean = torch.zeros(N)
std = eps * torch.ones(N)
normal = Normal(mean, std)
for i in range(
max_perms
): # (1) Draw N samples from permutations Universe U (#U = k!)
while True: # (2) Endless loop
perm = np.random.permutation(
N
) # (3) Generate a random permutation form U
key = tuple(perm)
if (
key not in self.perms
): # (4) Check if permutation already has been drawn (hash table)
self.perms.append(key) # (5) Insert into set
noise = normal.rsample()
noisy_key = tuple(perm + noise.numpy())
self.noisy_perms.append(noisy_key)
break
pass