oasis.stratification.Strata

class oasis.stratification.Strata(allocations)

Represents a collection of strata and facilitates sampling from them

This class takes an array of prescribed stratum allocations for a finite pool and stores the information in a form that is convenient for sampling. The items in the pool are referred to uniquely by their location in the input array. An item may be sampled from the strata (according to an arbitrary distribution over the strata) using the sample method.

Parameters
allocationsarray-like, shape=(n_items,)

ordered array of ints or strs which specifies the name/identifier of the allocated stratum for each item in the pool.

Attributes
allocations_list of numpy.ndarrays, length n_strata

represents the items contained within each stratum using a list of arrays. Each array in the list refers to a particular stratum, and stores the items contained within that stratum. Items are referred to by their location in the input array.

n_strata_int

number of strata

n_items_int

number of items in the pool (i.e. in all of the strata)

names_numpy.ndarray, shape=(n_strata,)

array containing names/identifiers for each stratum

indices_numpy.ndarray, shape=(n_strata,)

array containing unique indices for each stratum

sizes_numpy.ndarray, shape=(n_strata,)

array specifying how many items are contained with each stratum

weights_numpy.ndarray, shape=(n_strata,)

array specifying the stratum weights (sizes/n_items)

Methods

intra_mean(values)

Calculate the mean of a quantity within strata

reset()

Reset the instance to begin sampling from scratch

sample([pmf, replace])

Sample an item from the strata

__init__(allocations)

Initialize self. See help(type(self)) for accurate signature.