Java Code Examples for org.nd4j.linalg.factory.Nd4j#getRandom()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#getRandom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: A3CThreadDiscrete.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public A3CThreadDiscrete(MDP<OBSERVATION, Integer, DiscreteSpace> mdp, IAsyncGlobal<IActorCritic> asyncGlobal,
                         A3CLearningConfiguration a3cc, int deviceNum, TrainingListenerList listeners,
                         int threadNumber) {
    super(asyncGlobal, mdp, listeners, threadNumber, deviceNum);
    this.configuration = a3cc;
    this.asyncGlobal = asyncGlobal;
    this.threadNumber = threadNumber;

    Long seed = configuration.getSeed();
    rnd = Nd4j.getRandom();
    if (seed != null) {
        rnd.setSeed(seed + threadNumber);
    }

    setUpdateAlgorithm(buildUpdateAlgorithm());
}
 
Example 2
Source File: LargestBlobCropTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param random        Object to use (or null for deterministic)
 * @param mode          Contour retrieval mode
 * @param method        Contour approximation method
 * @param blurWidth     Width of blurring kernel size
 * @param blurHeight    Height of blurring kernel size
 * @param lowerThresh   Lower threshold for either Canny or Threshold
 * @param upperThresh   Upper threshold for either Canny or Threshold
 * @param isCanny       Whether the edge detector is Canny or Threshold
 */
public LargestBlobCropTransform(Random random, int mode, int method, int blurWidth, int blurHeight, int lowerThresh,
                int upperThresh, boolean isCanny) {
    super(random);
    this.rng = Nd4j.getRandom();
    this.mode = mode;
    this.method = method;
    this.blurWidth = blurWidth;
    this.blurHeight = blurHeight;
    this.lowerThresh = lowerThresh;
    this.upperThresh = upperThresh;
    this.isCanny = isCanny;
    this.converter = new OpenCVFrameConverter.ToMat();
}
 
Example 3
Source File: A3CDiscrete.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public A3CDiscrete(MDP<OBSERVATION, Integer, DiscreteSpace> mdp, IActorCritic iActorCritic, A3CLearningConfiguration conf) {
    this.iActorCritic = iActorCritic;
    this.mdp = mdp;
    this.configuration = conf;
    asyncGlobal = new AsyncGlobal<>(iActorCritic, conf);

    Long seed = conf.getSeed();
    Random rnd = Nd4j.getRandom();
    if (seed != null) {
        rnd.setSeed(seed);
    }

    policy = new ACPolicy<>(iActorCritic, rnd);
}
 
Example 4
Source File: RandomTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultithreading2() throws Exception {

    final AtomicInteger cnt = new AtomicInteger(0);
    final CopyOnWriteArrayList<INDArray> list = new CopyOnWriteArrayList<>();

    Thread[] threads = new Thread[10];
    for (int x = 0; x < threads.length; x++) {
        list.add(null);
    }

    for (int x = 0; x < threads.length; x++) {
        threads[x] = new Thread(new Runnable() {
            @Override
            public void run() {
                Random rnd = Nd4j.getRandom();
                rnd.setSeed(119);
                INDArray array = Nd4j.getExecutioner().exec(new UniformDistribution(Nd4j.createUninitialized(25)));

                Nd4j.getExecutioner().commit();

                list.set(cnt.getAndIncrement(), array);
            }
        });
        threads[x].start();
    }

    for (int x = 0; x < threads.length; x++) {
        threads[x].join();

        assertNotEquals(null, list.get(x));

        if (x > 0) {
            assertEquals(list.get(0), list.get(x));
        }
    }
}
 
Example 5
Source File: RandomTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultithreading1() throws Exception {

    final AtomicInteger cnt = new AtomicInteger(0);
    final CopyOnWriteArrayList<float[]> list = new CopyOnWriteArrayList<>();

    Thread[] threads = new Thread[10];
    for (int x = 0; x < threads.length; x++) {
        list.add(null);
    }

    for (int x = 0; x < threads.length; x++) {
        threads[x] = new Thread(new Runnable() {
            @Override
            public void run() {
                Random rnd = Nd4j.getRandom();
                rnd.setSeed(119);
                float[] array = new float[10];

                for (int e = 0; e < array.length; e++) {
                    array[e] = rnd.nextFloat();
                }
                list.set(cnt.getAndIncrement(), array);
            }
        });
        threads[x].start();
    }

    // we want all threads finished before comparing arrays
    for (int x = 0; x < threads.length; x++)
        threads[x].join();

    for (int x = 0; x < threads.length; x++) {
        assertNotEquals(null, list.get(x));

        if (x > 0) {
            assertArrayEquals(list.get(0), list.get(x), 1e-5f);
        }
    }
}
 
Example 6
Source File: RandomCropTransform.java    From DataVec with Apache License 2.0 5 votes vote down vote up
public RandomCropTransform(Random random, long seed, int height, int width) {
    super(random);
    this.outputHeight = height;
    this.outputWidth = width;
    this.rng = Nd4j.getRandom();
    this.rng.setSeed(seed);
    this.converter = new OpenCVFrameConverter.ToMat();
}
 
Example 7
Source File: RandomProjection.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public RandomProjection(double eps){
    this(eps, Nd4j.getRandom());
}
 
Example 8
Source File: OrthogonalDistribution.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public OrthogonalDistribution(double gain) {
    this.gain = gain;
    this.random = Nd4j.getRandom();
}
 
Example 9
Source File: RandomProjection.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public RandomProjection(int components){
    this(components, Nd4j.getRandom());
}
 
Example 10
Source File: BaseDistribution.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public BaseDistribution() {
    this(Nd4j.getRandom());
}
 
Example 11
Source File: ConstantDistribution.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public ConstantDistribution(double value) {
    this.value = value;
    this.random = Nd4j.getRandom();
}
 
Example 12
Source File: CartpoleEnvironment.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CartpoleEnvironment() {
    this(Nd4j.getRandom());
}
 
Example 13
Source File: LogNormalDistribution.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public LogNormalDistribution(INDArray mean, double std) {
    this.means = mean;
    this.standardDeviation = std;
    this.random = Nd4j.getRandom();
}
 
Example 14
Source File: TruncatedNormalDistribution.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public TruncatedNormalDistribution(INDArray mean, double std) {
    this.means = mean;
    this.standardDeviation = std;
    this.random = Nd4j.getRandom();
}
 
Example 15
Source File: DiscreteSpace.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public DiscreteSpace(int size) {
    this(size, Nd4j.getRandom());
}
 
Example 16
Source File: ACPolicy.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public ACPolicy(IActorCritic actorCritic) {
    this(actorCritic, Nd4j.getRandom());
}
 
Example 17
Source File: RandomProjection.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public RandomProjection(int components){
    this(components, Nd4j.getRandom());
}
 
Example 18
Source File: NormalDistribution.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public NormalDistribution(INDArray mean, double std) {
    this.means = mean;
    this.standardDeviation = std;
    this.random = Nd4j.getRandom();
}
 
Example 19
Source File: UniformDistribution.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Create a uniform real distribution using the given lower and upper
 * bounds.
 *
 * @param lower Lower bound of this distribution (inclusive).
 * @param upper Upper bound of this distribution (exclusive).
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public UniformDistribution(double lower, double upper) throws NumberIsTooLargeException {
    this(Nd4j.getRandom(), lower, upper);
}
 
Example 20
Source File: TruncatedNormalDistribution.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Create a normal distribution using the given mean, standard deviation and
 * inverse cumulative distribution accuracy.
 *
 * @param mean               Mean for this distribution.
 * @param sd                 Standard deviation for this distribution.
 * @param inverseCumAccuracy Inverse cumulative probability accuracy.
 * @throws NotStrictlyPositiveException if {@code sd <= 0}.
 * @since 2.1
 */
public TruncatedNormalDistribution(double mean, double sd, double inverseCumAccuracy) throws NotStrictlyPositiveException {
    this(Nd4j.getRandom(), mean, sd, inverseCumAccuracy);
}