Class NumpyRandomState

java.lang.Object
jline.opt.solver.de.NumpyRandomState

public class NumpyRandomState extends Object
Bit-exact port of the subset of numpy.random.RandomState consumed by scipy's differential_evolution. Backed by MT19937.

Implements random_sample, uniform, the default-dtype randint (32-bit masked rejection), and shuffle/ permutation (Fisher-Yates driven by random_interval), each reproducing numpy's exact draw sequence and word consumption. This lets the differential-evolution optimizer follow the identical trajectory to the native-Python line-opt for a given integer seed.

Java 8 compatible.

  • Constructor Summary

    Constructors
    Constructor
    Description
    NumpyRandomState(long seed)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    int[]
    permutation(int n)
    numpy permutation(range(n)): shuffled copy of [0, 1, ..., n-1].
    long
    randint(long high)
    Convenience: randint(0, high).
    long
    randint(long low, long high)
    numpy randint(low, high) with the default integer dtype: a uniform integer in [low, high) via 32-bit masked rejection (one word per rejection iteration), matching numpy's word consumption exactly.
    long
    randomInterval(long max)
    numpy random_interval(max): a uniform integer in [0, max] inclusive via 32-bit masked rejection.
    double
    numpy random_sample(): a 53-bit double in [0, 1) from two 32-bit words.
    double[]
    randomSample(int n)
    numpy random_sample(size): C-order fill of length n.
    void
    shuffle(int[] arr)
    numpy shuffle: in-place Fisher-Yates using random_interval.
    double
    uniform(double low, double high)
    numpy uniform(low, high): scalar draw.
    double[]
    uniform(double low, double high, int n)
    numpy uniform(low, high, size=n): C-order fill of length n.
    double[]
    uniform(int n)
    numpy uniform(size=n) == uniform(0, 1, n).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NumpyRandomState

      public NumpyRandomState(long seed)
    • NumpyRandomState

      public NumpyRandomState(MT19937 mt)
  • Method Details

    • getGenerator

      public MT19937 getGenerator()
    • randomSample

      public double randomSample()
      numpy random_sample(): a 53-bit double in [0, 1) from two 32-bit words.
    • randomSample

      public double[] randomSample(int n)
      numpy random_sample(size): C-order fill of length n.
    • uniform

      public double uniform(double low, double high)
      numpy uniform(low, high): scalar draw.
    • uniform

      public double[] uniform(double low, double high, int n)
      numpy uniform(low, high, size=n): C-order fill of length n.
    • uniform

      public double[] uniform(int n)
      numpy uniform(size=n) == uniform(0, 1, n).
    • randint

      public long randint(long low, long high)
      numpy randint(low, high) with the default integer dtype: a uniform integer in [low, high) via 32-bit masked rejection (one word per rejection iteration), matching numpy's word consumption exactly.
    • randint

      public long randint(long high)
      Convenience: randint(0, high).
    • randomInterval

      public long randomInterval(long max)
      numpy random_interval(max): a uniform integer in [0, max] inclusive via 32-bit masked rejection. Used by shuffle/permutation.
    • shuffle

      public void shuffle(int[] arr)
      numpy shuffle: in-place Fisher-Yates using random_interval.
    • permutation

      public int[] permutation(int n)
      numpy permutation(range(n)): shuffled copy of [0, 1, ..., n-1].