public final class CompositeSamplers extends Object
The composite sampler is constructed using a builder
for the type of samplers
that will form the composite. Each sampler has a weight in the composition.
Samples are returned using a 2 step algorithm:
The weights used for each sampler create a discrete probability distribution. This is sampled using a discrete probability distribution sampler. The builder provides methods to change the default implementation.
The following example will create a sampler to uniformly sample the border of a triangle using the line segment lengths as weights:
UniformRandomProvider rng = RandomSource.KISS.create(); double[] a = {1.23, 4.56}; double[] b = {6.78, 9.01}; double[] c = {3.45, 2.34}; ObjectSampler<double[]> sampler = CompositeSamplers.<double[]>newObjectSamplerBuilder() .add(LineSampler.of(rng, a, b), Math.hypot(a[0] - b[0], a[1] - b[1])) .add(LineSampler.of(rng, b, c), Math.hypot(b[0] - c[0], b[1] - c[1])) .add(LineSampler.of(rng, c, a), Math.hypot(c[0] - a[0], c[1] - a[1])) .build(rng);
Modifier and Type | Class and Description |
---|---|
static interface |
CompositeSamplers.Builder<S>
Builds a composite sampler.
|
static class |
CompositeSamplers.DiscreteProbabilitySampler
The DiscreteProbabilitySampler class defines implementations that sample from a user-defined
discrete probability distribution.
|
static interface |
CompositeSamplers.DiscreteProbabilitySamplerFactory
A factory for creating a sampler of a user-defined
discrete probability distribution.
|
public static <T> CompositeSamplers.Builder<ObjectSampler<T>> newObjectSamplerBuilder()
ObjectSampler
.
Note: If the compiler cannot infer the type parameter of the sampler it can be specified
within the diamond operator <T>
preceding the call to
newObjectSamplerBuilder()
, for example:
CompositeSamplers.<double[]>newObjectSamplerBuilder()
T
- Type of the sample.public static <T> CompositeSamplers.Builder<SharedStateObjectSampler<T>> newSharedStateObjectSamplerBuilder()
SharedStateObjectSampler
.
Note: If the compiler cannot infer the type parameter of the sampler it can be specified
within the diamond operator <T>
preceding the call to
newSharedStateObjectSamplerBuilder()
, for example:
CompositeSamplers.<double[]>newSharedStateObjectSamplerBuilder()
T
- Type of the sample.public static CompositeSamplers.Builder<DiscreteSampler> newDiscreteSamplerBuilder()
DiscreteSampler
.public static CompositeSamplers.Builder<SharedStateDiscreteSampler> newSharedStateDiscreteSamplerBuilder()
SharedStateDiscreteSampler
.public static CompositeSamplers.Builder<ContinuousSampler> newContinuousSamplerBuilder()
ContinuousSampler
.public static CompositeSamplers.Builder<SharedStateContinuousSampler> newSharedStateContinuousSamplerBuilder()
SharedStateContinuousSampler
.public static CompositeSamplers.Builder<LongSampler> newLongSamplerBuilder()
LongSampler
.public static CompositeSamplers.Builder<SharedStateLongSampler> newSharedStateLongSamplerBuilder()
SharedStateLongSampler
.Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.