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

public abstract class UnitBallSampler extends Object implements SharedStateObjectSampler<double[]>
Since:
1.4
  • Field Details

    • ONE_D

      private static final int ONE_D
      The dimension for 1D sampling.
      See Also:
    • TWO_D

      private static final int TWO_D
      The dimension for 2D sampling.
      See Also:
    • THREE_D

      private static final int THREE_D
      The dimension for 3D sampling.
      See Also:
    • DOUBLE_MULTIPLIER

      private static final double DOUBLE_MULTIPLIER
      The multiplier to convert the least significant 53-bits of a long to a double. 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 interface ObjectSampler<double[]>
      Returns:
      a random Cartesian coordinate within the unit n-ball.
    • withUniformRandomProvider

      public abstract UnitBallSampler 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:
      withUniformRandomProvider in interface SharedStateSampler<SharedStateObjectSampler<double[]>>
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      Returns:
      the sampler
    • of

      public static UnitBallSampler of(UniformRandomProvider rng, int dimension)
      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 - If dimension <= 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