File size: 708 Bytes
0de1d17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()