Class UnitBallSampler

    • Field Detail

      • THREE_D

        private static final int THREE_D
        The dimension for 3D sampling.
        See Also:
        Constant Field Values
      • 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 << 53).

        See Also:
        Constant Field Values
    • Constructor Detail

      • UnitBallSampler

        public UnitBallSampler()
        Create an instance.
    • Method Detail

      • 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.
      • 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:
        java.lang.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