Package org.apache.commons.rng.sampling
Class UnitSphereSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.UnitSphereSampler
-
- All Implemented Interfaces:
ObjectSampler<double[]>,SharedStateObjectSampler<double[]>,SharedStateSampler<SharedStateObjectSampler<double[]>>
public class UnitSphereSampler extends Object implements SharedStateObjectSampler<double[]>
Generate vectors isotropically located on the surface of a sphere.Sampling in 2 or more dimensions uses:
Sampling in 1D uses the sign bit from
UniformRandomProvider.nextInt()to set the direction of the vector.- Since:
- 1.1
-
-
Constructor Summary
Constructors Constructor Description UnitSphereSampler(int dimension, UniformRandomProvider rng)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description double[]nextVector()Deprecated.Usesample().static UnitSphereSamplerof(UniformRandomProvider rng, int dimension)Create a unit sphere sampler for the given dimension.double[]sample()Create an object sample.UnitSphereSamplerwithUniformRandomProvider(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
-
-
-
-
Constructor Detail
-
UnitSphereSampler
@Deprecated public UnitSphereSampler(int dimension, UniformRandomProvider rng)
Deprecated.This instance delegates sampling. Use the factory methodof(UniformRandomProvider, int)to create an optimal sampler.- Parameters:
dimension- Space dimension.rng- Generator for the individual components of the vectors. A shallow copy will be stored in this instance.- Throws:
IllegalArgumentException- Ifdimension <= 0
-
-
Method Detail
-
sample
public double[] sample()
Description copied from interface:ObjectSamplerCreate an object sample.- Specified by:
samplein interfaceObjectSampler<double[]>- Returns:
- a random normalized Cartesian vector.
- Since:
- 1.4
-
nextVector
@Deprecated public double[] nextVector()
Deprecated.Usesample().- Returns:
- a random normalized Cartesian vector.
-
withUniformRandomProvider
public UnitSphereSampler 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
- Since:
- 1.3
-
of
public static UnitSphereSampler of(UniformRandomProvider rng, int dimension)
Create a unit sphere sampler for the given dimension.- Parameters:
rng- Generator for the individual components of the vectors. A shallow copy will be stored in the sampler.dimension- Space dimension.- Returns:
- the sampler
- Throws:
IllegalArgumentException- Ifdimension <= 0- Since:
- 1.4
-
-