Skip to content

random

random_sampler(conditions, n)

Uniform random sampling without replacement from a pool of conditions.

Parameters:

Name Type Description Default
conditions Union[Iterable, Sequence]

Pool of conditions

required
n int

number of samples to collect

required
Source code in autora/experimentalist/sampler/random.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def random_sampler(conditions: Union[Iterable, Sequence], n: int):
    """
    Uniform random sampling without replacement from a pool of conditions.
    Args:
        conditions: Pool of conditions
        n: number of samples to collect

    Returns: Sampled pool

    """

    if isinstance(conditions, Iterable):
        conditions = list(conditions)
    random.shuffle(conditions)
    samples = conditions[0:n]

    return samples