Class LineSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.shape.LineSampler
-
- All Implemented Interfaces:
ObjectSampler<double[]>,SharedStateObjectSampler<double[]>,SharedStateSampler<SharedStateObjectSampler<double[]>>
- Direct Known Subclasses:
LineSampler.LineSampler1D,LineSampler.LineSampler2D,LineSampler.LineSampler3D,LineSampler.LineSamplerND
public abstract class LineSampler extends java.lang.Object implements SharedStateObjectSampler<double[]>
Generate points uniformly distributed on a line.Sampling uses:
- Since:
- 1.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLineSampler.LineSampler1DSample uniformly from a line in 1D.private static classLineSampler.LineSampler2DSample uniformly from a line in 2D.private static classLineSampler.LineSampler3DSample uniformly from a line in 3D.private static classLineSampler.LineSamplerNDSample uniformly from a line in ND.
-
Field Summary
Fields Modifier and Type Field Description private static intONE_DThe dimension for 1D sampling.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 LineSampler(UniformRandomProvider rng)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract double[]createSample(double p1mu, double u)Creates the sample given the random variateuin the interval[0, 1].static LineSamplerof(UniformRandomProvider rng, double[] a, double[] b)Create a line sampler with verticesaandb.double[]sample()Create an object sample.abstract LineSamplerwithUniformRandomProvider(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
-
ONE_D
private static final int ONE_D
The dimension for 1D sampling.- See Also:
- Constant Field Values
-
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
-
LineSampler
LineSampler(UniformRandomProvider rng)
- Parameters:
rng- Source of randomness.
-
-
Method Detail
-
sample
public double[] sample()
Description copied from interface:ObjectSamplerCreate an object sample.- Specified by:
samplein interfaceObjectSampler<double[]>- Returns:
- a random Cartesian coordinate on the line.
-
createSample
protected abstract double[] createSample(double p1mu, double u)Creates the sample given the random variateuin the interval[0, 1]. The sum1 - uis provided. The sample can be obtained from the line ab using:p = a(1 - u) + ub
- Parameters:
p1mu- plus 1 minus u (1 - u)u- the variate u- Returns:
- the sample
-
withUniformRandomProvider
public abstract LineSampler 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 LineSampler of(UniformRandomProvider rng, double[] a, double[] b)
Create a line sampler with verticesaandb. Sampled points are uniformly distributed on the line segmentab.Sampling is supported in dimensions of 1 or above.
- Parameters:
rng- Source of randomness.a- The first vertex.b- The second vertex.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException- If the vertices do not have the same dimension; the dimension is less than 1; or vertices have non-finite coordinates.
-
-