rahulnair23's picture
test commit
0de1d17
raw
history blame contribute delete
708 Bytes
import numpy as np
def systematic_sampling(l: list, n: int) -> list:
"""
l - (ordered) list to be sampled from
n - number of samples to fetch
returns a list of samples (far apart)
"""
skip = len(l)/n
s = np.random.uniform(0, skip)
out = []
for _ in range(n):
out.append(l[np.floor(s).astype(int)])
s += skip
return out
def close_sampling(l:list, n: int) -> list:
"""
returns a sampled list (close together)
"""
w = np.floor(n/2 + 2).astype(int)
s = np.floor(np.random.uniform(w, len(l) - w)).astype(int)
subset = [l[i] for i in range(s-w, s+w)]
return np.random.choice(subset, n, replace=False).tolist()