Sampler¶
Contains Sampler-classes.
- class Sampler(*args, **kwargs)[source]¶
Base class Sampler that implements algebra of Samplers.
- sample(size)[source]¶
Sampling method of a sampler.
- Parameters
size (int) – lentgh of sample to be generated.
- Returns
Array of size (len, Sampler’s dimension).
- Return type
np.ndarray
- apply(transform)[source]¶
Apply a transformation to the sampler. Build new sampler, which sampling function is given by transform(self.sample(size))`.
- Parameters
transform (callable) – function, that takes ndarray of shape (size, dim_sampler) and produces ndarray of shape (size, new_dim_sampler).
- Returns
instance of class Sampler with redefined method sample.
- Return type
- truncate(high=None, low=None, expr=None, prob=0.5, max_iters=None, sample_anyways=False)[source]¶
Truncate a sampler. Resulting sampler produces points satisfying
low <= pts <= high
. Ifexpr
is suplied, the condition islow <= expr(pts) <= high
.Uses while-loop to obtain a sample from the region of interest of needed size. The behaviour of the while loop is controlled by parameters
max_iters
andsample_anyways
-parameters.- Parameters
expr (callable, optional.) – Some vectorized function. Accepts points of sampler, returns either bool or float. In case of float, either high or low should also be supplied.
prob (float, optional) – estimate of P(truncation-condtion is satisfied). When supplied, can improve the performance of sampling-method of truncated sampler.
max_iters (float, optional) – if the number of iterations needed for obtaining the sample exceeds this number, either a warning or error is raised. By default is set to 1e7 (constant of TruncateSampler-class).
sample_anyways (bool, optional) – If set to True, when exceeding self.max_iters number of iterations the procedure throws a warning but continues. If set to False, the error is raised.
- Returns
new Sampler-instance, truncated version of self.
- Return type
- class OrSampler(left, right, *args, **kwargs)[source]¶
Class for implementing | (mixture) operation on Sampler-instances.
- class AndSampler(left, right, *args, **kwargs)[source]¶
Class for implementing & (coordinates stacking) operation on Sampler-instances.
- class ApplySampler(sampler, transform, *args, **kwargs)[source]¶
Class for implementing apply (adding transform) operation on Sampler-instances.
- class TruncateSampler(sampler, high=None, low=None, expr=None, prob=0.5, max_iters=None, sample_anyways=False, *args, **kwargs)[source]¶
Class for implementing truncate (truncation by a condition) operation on Sampler-instances.
- max_iters = 10000000.0¶
- class BaseOperationSampler(left, right, *args, **kwargs)[source]¶
Base class for implementing all arithmetic operations on Sampler-instances.
- operation = None¶
- class ConstantSampler(constant, **kwargs)[source]¶
Sampler of a constant.
- Parameters
constant (int, str, float, list) – constant, associated with the Sampler. Can be multidimensional, e.g. list or np.ndarray.
- constant¶
vectorized constant, associated with the Sampler.
- Type
np.array
- class NumpySampler(name, seed=None, **kwargs)[source]¶
Sampler based on a distribution from numpy random.
- Parameters
- state¶
a random number generator
- class ScipySampler(name, seed=None, **kwargs)[source]¶
Sampler based on a distribution from scipy.stats.
- Parameters
- state¶
a random number generator
- distr¶
a distribution class
- class HistoSampler(histo=None, edges=None, seed=None, **kwargs)[source]¶
Sampler based on a histogram, output of np.histogramdd.
- Parameters
- bins¶
bins of base-histogram (see np.histogramdd).
- Type
np.ndarray
Notes
The sampler should be based on unnormalized histogram. if histo-arg is supplied, it is used for histo-initilization. Otherwise, edges should be supplied. In this case all bins are empty.