S
- Type of samplerpublic static interface CompositeSamplers.Builder<S>
A composite sampler is a combination of multiple samplers that all return the same sample type. Each sampler has a weighting in the composition. Samples are returned using a 2 step algorithm:
Step 1 requires a discrete sampler constructed from a discrete probability distribution. The probability for each sampler is the sampler weight divided by the sum of the weights:
p(i) = w(i) / sum(w)
The builder provides a method to set the factory used to generate the discrete sampler.
Modifier and Type | Method and Description |
---|---|
CompositeSamplers.Builder<S> |
add(S sampler,
double weight)
Adds the sampler to the composite.
|
S |
build(UniformRandomProvider rng)
Builds the composite sampler.
|
CompositeSamplers.Builder<S> |
setFactory(CompositeSamplers.DiscreteProbabilitySamplerFactory factory)
Sets the factory to use to generate the composite's discrete sampler from the sampler
weights.
|
int |
size()
Return the number of samplers in the composite.
|
int size()
build
method can create a sampler.CompositeSamplers.Builder<S> add(S sampler, double weight)
sampler
- Sampler.weight
- Weight for the composition.IllegalArgumentException
- if weight
is negative, infinite or NaN
.NullPointerException
- if sampler
is null.CompositeSamplers.Builder<S> setFactory(CompositeSamplers.DiscreteProbabilitySamplerFactory factory)
Note: If the factory is not explicitly set then a default will be used.
factory
- Factory.NullPointerException
- if factory
is null.S build(UniformRandomProvider rng)
rng
is the source of randomness for selecting
which sampler to use for each sample.
Note: When the sampler is created the builder is reset to an empty state. This prevents building multiple composite samplers with the same samplers and their identical underlying source of randomness.
rng
- Generator of uniformly distributed random numbers.IllegalStateException
- if no samplers have been added to create a composite.size()
Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.