acoupipe.sampler
Random processes to sample values according to a specified random distribution (random variable).
Sampler Module Purpose
A manipulation of object characteristics according to a certain
random distribution can be achieved by using the BaseSampler
derived classes included in the sampler.py
module.
All BaseSampler
derived classes represent random processes that can be used to manipulate the attributes of Acoular’s objects according to a specified distribution.
A random process is defined by a random variable and a corresponding random state. Both properties are attributes of all BaseSampler
derived classes.
AcouPipe offers a variety of different types of samplers in the sampler.py
module.
The random variable that can be passed to class instances of the sampler module must either be derived from or be part of the scipy.stats
module.
This example illustrates how the RMS value of two white noise signals can be sampled according to a normal distribution. For this purpose, an instance of the BaseSampler
derived NumericAttributeSampler
class is used. The two WNoiseGenerator
objects are given as targets to the sampler object.
New RMS values following a normal distribution are assigned to the WNoiseGenerator
objects each time the sample method of the NumericAttributeSampler
object is evaluated.
import acoular as ac
from acoupipe.sampler import NumericAttributeSampler
from scipy.stats import norm
random_var = norm(loc=1.,scale=.5)
n1 = ac.WNoiseGenerator( sample_freq=24000,
numsamples=24000*5,
rms=1.0,
seed=1 )
n2 = ac.WNoiseGenerator( sample_freq=24000,
numsamples=24000*5,
rms=.5,
seed=2 )
rms_sampler = NumericAttributeSampler(
target=[n1,n2],
attribute='rms',
random_var=random_var,
random_state=10)
rms_sampler.sample()
print(n1.rms, n2.rms)
The output of the example is:
1.6657932520647591 1.3576394871992028
Module Contents
- class acoupipe.sampler.BaseSampler
Bases:
traits.api.HasPrivateTraits
Base class that represents a random process.
This class has no functionality and should not be used in practice. Manipulates attributes of an instance or a list of instances according to a specified random distribution.
- rvs(size=1)
Random variable sampling (for internal use).
- class acoupipe.sampler.NumericAttributeSampler
Bases:
BaseSampler
Samples attributes of numeric type (e.g. int, float).
This class samples attributes of numeric type (e.g. int, float) of an instance or a list of instances according to a specified random distribution. The attribute to be sampled is specified by
attribute
. The sampled values are normalized to the range [0,1] ifnormalize
is set to True. The sampled values are ordered in ascending or descending order for all objects in thetarget
list iforder
is set to “ascending” or “descending”. If no value is set (order
=None), no ordering is performed.- order_samples(samples)
Order drawn values (Internal function).
- sample()
Random sampling of the target instance attribute.
Utilizes
rvs()
function to draw random values fromrandom_var
that are going to be assigned to the target instance attribute via internalset_value()
method.
- class acoupipe.sampler.SetSampler
Bases:
BaseSampler
Draws one or multiple values from a given set of values.
This class draws one or multiple values from a given set of values. The set of values is specified by
set
. The number of samples to be drawn is specified bynumsamples
. The attribute to be sampled is specified byattribute
. A list with sample probabilities can be specified byprobabilities
. The attributereplace
specifies if the same object inset
can be drawn multiple times.- rvs(size=1)
Random variable sampling (for internal use).
- class acoupipe.sampler.SourceSetSampler
Bases:
SetSampler
Draws one or multiple sources of type
acoular.SamplesGenerator
from a given set of sources.From a given set of sources (type
acoular.SamplesGenerator
),SourceSetSampler
draws one or multiple sources from this set and assigns those to one or more SourceMixer instances. The number of sources to be drawn is specified bynsources
. The attribute to be sampled is specified byattribute
.- sample()
Random sampling of sources.
Utilizes
rvs()
function to draw sources fromset
that are going to be assigned to theacoular.SourceMixer
instance.
- class acoupipe.sampler.ContainerSampler
Bases:
BaseSampler
Special case of a Sampler to enable the use of an arbitrary sampling function.
Takes an arbitrary callable with the signature ‘<Signature (numpy.random.RandomState)>’ or ‘<Signature (numpy.random.Generator)>’. The callable is evoked via the
sample()
method of this class. The output of the callable is assigned to thetarget
attribute.- rvs()
Evokes the
random_func
.
- class acoupipe.sampler.LocationSampler
Bases:
BaseSampler
Base class that represents a random process.
This class has no functionality and should not be used in practice. Manipulates attributes of an instance or a list of instances according to a specified random distribution.
- rvs()
Random variable sampling (for internal use).
- sample()
Random sampling of locations.
- class acoupipe.sampler.PointSourceSampler
Bases:
LocationSampler
Random process that samples the locations of one or more instances of type
PointSource
.- sample_loc(target)
Sample a single target location (internal use).
- rvs(size=1)
Random variable sampling (for internal use).
- sample()
Random sampling of
acoular.PointSource
locations.
- class acoupipe.sampler.MicGeomSampler
Bases:
BaseSampler
Random disturbance of microphone positions of a
acoular.MicGeom
object.- rotate()
Rotates the microphone array.
- translate()
Translate the microphone array.
- deviate()
Deviates the individual microphone positions.
- sample()
Random sampling of microphone positions.