/** * Create a random ndarray with the given shape using the given rng * * @param shape the shape of the ndarray * @param r the random generator to use * @return the random ndarray with the specified shape */ @Override public INDArray rand(int[] shape, org.nd4j.linalg.api.rng.Random r) { INDArray ret = r.nextDouble(shape); return ret; }
/** * {@inheritDoc} */ @Override public void reseedRandomGenerator(long seed) { random.setSeed(seed); }
/** * Random normal using the given rng * * @param shape the shape of the ndarray * @param r the random generator to use * @return */ @Override public INDArray randn(int[] shape, org.nd4j.linalg.api.rng.Random r) { return r.nextGaussian(shape); }
public static long[] broadcastToShape(long[] inputShapeWithOnes, long seed) { Nd4j.getRandom().setSeed(seed); val shape = new long[inputShapeWithOnes.length]; for (int i = 0; i < shape.length; i++) { if (inputShapeWithOnes[i] == 1) { shape[i] = Nd4j.getRandom().nextInt(9) + 1; } else shape[i] = inputShapeWithOnes[i]; } return shape; }
/** * {@inheritDoc} * <p/> * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method. * </a> */ @Override public double sample() { return inverseCumulativeProbability(random.nextDouble()); }
@Override public void setSeed(int seed) { this.seed = (long) seed; getRandomGenerator().setSeed(seed); }
/** * Identical to setSeed(seed); * * @param seed */ @Override public void reSeed(long seed) { setSeed(seed); } }
/** * Identical to setSeed(System.currentTimeMillis()); */ @Override public void reSeed() { reSeed(System.currentTimeMillis()); }
@Override public INDArray rand(long[] shape, org.nd4j.linalg.api.rng.Random r) { INDArray ret = r.nextDouble(shape); return ret; }
@Override public INDArray randn(long[] shape, org.nd4j.linalg.api.rng.Random r) { return r.nextGaussian(shape); }
@Override public void setSeed(long seed) { this.seed = seed; getRandomGenerator().setSeed(seed); }
/** * {@inheritDoc} */ @Override public double sample() { final double u = random.nextDouble(); return u * upper + (1 - u) * lower; }
/** * {@inheritDoc} */ @Override public double sample() { if (means != null) throw new IllegalStateException("Unable to sample from more than one mean"); return standardDeviation * random.nextGaussian() + mean; }
@Override public boolean nextBoolean() { return getRandomGenerator().nextBoolean(); }
/** * Create a random ndarray with the given shape and order * * @param shape the shape of the ndarray * @return the random ndarray with the specified shape */ @Override public INDArray rand(char order, int[] shape) { return Nd4j.getRandom().nextDouble(order, shape); }
/** * {@inheritDoc} */ @Override public double sample() { if (means != null) throw new IllegalStateException("Unable to sample from more than one mean"); return standardDeviation * random.nextGaussian() + mean; }
/** * Create a random (uniform 0-1) NDArray with the specified shape and order * @param order Order ('c' or 'f') of the output array * @param rows Number of rows of the output array * @param columns Number of columns of the output array */ @Override public INDArray rand(char order, long rows, long columns) { return Nd4j.getRandom().nextDouble(order, new long[] {rows, columns}); }
/** * {@inheritDoc} */ @Override public double sample() { if (means != null) throw new IllegalStateException("Unable to sample from more than one mean"); return standardDeviation * random.nextGaussian() + mean; }
/** * Generate a random normal N(0,1) with the specified order and shape * @param order Order of the output array * @param rows the number of rows in the matrix * @param columns the number of columns in the matrix * @return */ @Override public INDArray randn(char order, long rows, long columns) { return Nd4j.getRandom().nextGaussian(order, new long[] {rows, columns}); }
/** * Random normal using the current time stamp * as the seed * * @param shape the shape of the ndarray * @return */ @Override public INDArray randn(char order, int[] shape) { return Nd4j.getRandom().nextGaussian(order, shape); }