Hi everyone,
I assumed that the following two functions would produce exactly the same results, as they’re equivalent to sampling with the concatenated weights as in draw_once
:
def draw_once(seed: int):
torch.manual_seed(seed)
weights = torch.arange(15).reshape(3, 5).float() * 100
return torch.multinomial(torch.vstack([weights, weights, weights]), 1).squeeze(1)
def draw_many(seed: int):
torch.manual_seed(seed)
weights = torch.arange(15).reshape(3, 5).float() * 100
return torch.vstack([torch.multinomial(weights, 1) for _ in range(3)]).squeeze(1)
# draw_once(0)
# tensor([2, 0, 1, 4, 1, 4, 2, 0, 1])
# draw_many(0)
# tensor([2, 0, 1, 3, 3, 0, 4, 1, 3])
once = torch.vstack([draw_once(i) for i in range(100_00)])
many = torch.vstack([draw_many(i) for i in range(100_00)])
once.float().std(axis=0) - many.float().std(axis=0)
once.float().mean(axis=0) - many.float().mean(axis=0)
however, sampling results in different, i.e. means are different beyond 5 sigma everywhere but in the first drawn sample, where the sample is exactly the same every time.
What can be the reason for this? I’ve also tried running with a newly instantiated Generator
, but I get the same results – first drawn sample is the same, others aren’t.