@staticmethod<EOL><INDENT>def reservoir(xs, n, rng):<DEDENT>
pool = []<EOL>for i, x in enumerate(xs):<EOL><INDENT>if len(pool) < n:<EOL><INDENT>pool.append(x / np.linalg.norm(x))<EOL>continue<EOL><DEDENT>j = rng.randint(i + <NUM_LIT:1>)<EOL>if j < n:<EOL><INDENT>pool[j] = x / np.linalg.norm(x)<EOL><DEDENT><DEDENT>L = len(pool)<EOL>S = np.std(pool, axis=<NUM_LIT:0>)<EOL>while len(pool) < n:<EOL><INDENT>x = pool[rng.randint(L)]<EOL>pool.append(x + S * rng.randn(*x.shape))<EOL><DEDENT>return np.array(pool, dtype=pool[<NUM_LIT:0>].dtype)<EOL>
Select a random sample of n items from xs.