Class BoxSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.shape.BoxSampler
-
- All Implemented Interfaces:
ObjectSampler<double[]>,SharedStateObjectSampler<double[]>,SharedStateSampler<SharedStateObjectSampler<double[]>>
- Direct Known Subclasses:
BoxSampler.BoxSampler2D,BoxSampler.BoxSampler3D,BoxSampler.BoxSamplerND
public abstract class BoxSampler extends java.lang.Object implements SharedStateObjectSampler<double[]>
Generate points uniformly distributed within a n-dimension box (hyperrectangle).Sampling uses:
- Since:
- 1.4
- See Also:
- Hyperrectangle (Wikipedia)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBoxSampler.BoxSampler2DSample uniformly from a box in 2D.private static classBoxSampler.BoxSampler3DSample uniformly from a box in 3D.private static classBoxSampler.BoxSamplerNDSample uniformly from a box in ND.
-
Field Summary
Fields Modifier and Type Field Description private UniformRandomProviderrngThe source of randomness.private static intTHREE_DThe dimension for 3D sampling.private static intTWO_DThe dimension for 2D sampling.
-
Constructor Summary
Constructors Constructor Description BoxSampler(UniformRandomProvider rng)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) doublecreateSample(double a, double b)Creates the sample between bound a and b.static BoxSamplerof(UniformRandomProvider rng, double[] a, double[] b)Create a box sampler with boundsaandb.abstract double[]sample()Create an object sample.abstract BoxSamplerwithUniformRandomProvider(UniformRandomProvider rng)Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.rng.sampling.ObjectSampler
samples, samples
-
-
-
-
Field Detail
-
TWO_D
private static final int TWO_D
The dimension for 2D sampling.- See Also:
- Constant Field Values
-
THREE_D
private static final int THREE_D
The dimension for 3D sampling.- See Also:
- Constant Field Values
-
rng
private final UniformRandomProvider rng
The source of randomness.
-
-
Constructor Detail
-
BoxSampler
BoxSampler(UniformRandomProvider rng)
- Parameters:
rng- Source of randomness.
-
-
Method Detail
-
sample
public abstract double[] sample()
Description copied from interface:ObjectSamplerCreate an object sample.- Specified by:
samplein interfaceObjectSampler<double[]>- Returns:
- a random Cartesian coordinate within the box.
-
createSample
double createSample(double a, double b)Creates the sample between bound a and b.- Parameters:
a- Bound ab- Bound b- Returns:
- the sample
-
withUniformRandomProvider
public abstract BoxSampler withUniformRandomProvider(UniformRandomProvider rng)
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateObjectSampler<double[]>>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
public static BoxSampler of(UniformRandomProvider rng, double[] a, double[] b)
Create a box sampler with boundsaandb. Sampled points are uniformly distributed within the box defined by the bounds.Sampling is supported in dimensions of 2 or above. Single dimension sampling can be performed using a
LineSampler.Note: There is no requirement that
a <= b. The samples will be uniformly distributed in the rangeatobfor each dimension.- Parameters:
rng- Source of randomness.a- Bound a.b- Bound b.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException- If the bounds do not have the same dimension; the dimension is less than 2; or bounds have non-finite coordinates.
-
-