Class UnitBallSampler
java.lang.Object
org.apache.commons.rng.sampling.shape.UnitBallSampler
- All Implemented Interfaces:
ObjectSampler<double[]>
,SharedStateObjectSampler<double[]>
,SharedStateSampler<SharedStateObjectSampler<double[]>>
- Direct Known Subclasses:
UnitBallSampler.UnitBallSampler1D
,UnitBallSampler.UnitBallSampler2D
,UnitBallSampler.UnitBallSampler3D
,UnitBallSampler.UnitBallSamplerND
Generate coordinates
uniformly distributed within the unit n-ball.
Sampling uses:
UniformRandomProvider.nextLong()
UniformRandomProvider.nextDouble()
(only for dimensions above 2)
- Since:
- 1.4
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Sample uniformly from a 1D unit line.private static class
Sample uniformly from a 2D unit disk.private static class
Sample uniformly from a 3D unit ball.private static class
Sample using ball point picking. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
The multiplier to convert the least significant 53-bits of along
to adouble
.private static final int
The dimension for 1D sampling.private static final int
The dimension for 3D sampling.private static final int
The dimension for 2D sampling. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static double
makeSignedDouble
(long bits) Creates a signed double in the range[-1, 1)
.static UnitBallSampler
of
(UniformRandomProvider rng, int dimension) Create a unit n-ball sampler for the given dimension.abstract double[]
sample()
Create an object sample.abstract UnitBallSampler
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 Details
-
ONE_D
private static final int ONE_DThe dimension for 1D sampling.- See Also:
-
TWO_D
private static final int TWO_DThe dimension for 2D sampling.- See Also:
-
THREE_D
private static final int THREE_DThe dimension for 3D sampling.- See Also:
-
DOUBLE_MULTIPLIER
private static final double DOUBLE_MULTIPLIERThe multiplier to convert the least significant 53-bits of along
to adouble
. Taken from o.a.c.rng.core.utils.NumberFactory.This is equivalent to 1.0 / (1L invalid input: '<'invalid input: '<' 53).
- See Also:
-
-
Constructor Details
-
UnitBallSampler
public UnitBallSampler()
-
-
Method Details
-
sample
public abstract double[] sample()Description copied from interface:ObjectSampler
Create an object sample.- Specified by:
sample
in interfaceObjectSampler<double[]>
- Returns:
- a random Cartesian coordinate within the unit n-ball.
-
withUniformRandomProvider
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:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateObjectSampler<double[]>>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
Create a unit n-ball sampler for the given dimension. Sampled points are uniformly distributed within the unit n-ball.Sampling is supported in dimensions of 1 or above.
- Parameters:
rng
- Source of randomness.dimension
- Space dimension.- Returns:
- the sampler
- Throws:
IllegalArgumentException
- Ifdimension <= 0
-
makeSignedDouble
private static double makeSignedDouble(long bits) Creates a signed double in the range[-1, 1)
. The magnitude is sampled evenly from the 254 dyadic rationals in the range.Note: This method will not return samples for both -0.0 and 0.0.
- Parameters:
bits
- the bits- Returns:
- the double
-