/** * {@inheritDoc} */ @Override public void reseedRandomGenerator(long seed) { random.setSeed(seed); }
public static List<Pair<INDArray, String>> get4dPermutedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] createdShape = {shape[1], shape[3], shape[2], shape[0]}; INDArray arr = Nd4j.rand(createdShape); INDArray permuted = arr.permute(3, 0, 2, 1); return Collections.singletonList(new Pair<>(permuted, "get4dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get6dPermutedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] createdShape = {shape[1], shape[4], shape[5], shape[3], shape[2], shape[0]}; INDArray arr = Nd4j.rand(createdShape); INDArray permuted = arr.permute(5, 0, 4, 3, 1, 2); return Collections.singletonList(new Pair<>(permuted, "get6dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get6dReshapedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] shape3d = {shape[0] * shape[2], shape[4] * shape[5], shape[1] * shape[3]}; INDArray array3d = Nd4j.rand(shape3d); INDArray array6d = array3d.reshape(ArrayUtil.toLongArray(shape)); return Collections.singletonList(new Pair<>(array6d, "get6dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
@Override public INDArray rand(long rows, long columns, double min, double max, org.nd4j.linalg.api.rng.Random rng) { Nd4j.getRandom().setSeed(rng.getSeed()); return rand(new long[] {rows, columns}, min, max, rng); }
/** * Random normal using the specified seed * * @param rows the number of rows in the matrix * @param columns the number of columns in the matrix * @return */ @Override public INDArray randn(long rows, long columns, long seed) { Nd4j.getRandom().setSeed(seed); return randn(new long[] {rows, columns}, Nd4j.getRandom()); }
@Override public INDArray rand(long[] shape, long seed) { Nd4j.getRandom().setSeed(seed); return rand(shape, Nd4j.getRandom()); }
public static List<Pair<INDArray, String>> get4dReshapedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] shape2d = {shape[0] * shape[2], shape[1] * shape[3]}; INDArray array2d = Nd4j.rand(shape2d); INDArray array3d = array2d.reshape(ArrayUtil.toLongArray(shape)); return Collections.singletonList(new Pair<>(array3d, "get4dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get5dReshapedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] shape2d = {shape[0] * shape[2], shape[4], shape[1] * shape[3]}; INDArray array3d = Nd4j.rand(shape2d); INDArray array5d = array3d.reshape(ArrayUtil.toLongArray(shape)); return Collections.singletonList(new Pair<>(array5d, "get5dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
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; }
/** * Create a random ndarray with the given shape using the given rng * * @param shape the shape of the ndarray * @param seed the seed to use * @return the random ndarray with the specified shape */ @Override public INDArray rand(int[] shape, long seed) { Nd4j.getRandom().setSeed(seed); return rand(shape, Nd4j.getRandom()); }
public static List<Pair<INDArray, String>> get3dPermutedWithShape(long seed, long... shape) { Nd4j.getRandom().setSeed(seed); long[] createdShape = {shape[1], shape[2], shape[0]}; int lencreatedShape = ArrayUtil.prod(createdShape); INDArray arr = Nd4j.linspace(1, lencreatedShape, lencreatedShape).reshape(createdShape); INDArray permuted = arr.permute(2, 0, 1); return Collections.singletonList(new Pair<>(permuted, "get3dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get3dReshapedWithShape(long seed, long... shape) { Nd4j.getRandom().setSeed(seed); long[] shape2d = {shape[0] * shape[2], shape[1]}; int lenshape2d = ArrayUtil.prod(shape2d); INDArray array2d = Nd4j.linspace(1, lenshape2d, lenshape2d).reshape(shape2d); INDArray array3d = array2d.reshape(shape); return Collections.singletonList(new Pair<>(array3d, "get3dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static Pair<INDArray, String> getTransposedMatrixWithShape(long rows, long cols, long seed) { Nd4j.getRandom().setSeed(seed); INDArray out = Nd4j.linspace(1, rows * cols, rows * cols).reshape(cols, rows); return new Pair<>(out.transpose(), "getTransposedMatrixWithShape(" + rows + "," + cols + "," + seed + ")"); }
public static Pair<INDArray, String> getTransposedMatrixWithShape(char ordering, int rows, int cols, int seed) { Nd4j.getRandom().setSeed(seed); INDArray out = Nd4j.linspace(1, rows * cols, rows * cols).reshape(ordering, cols, rows); return new Pair<>(out.transpose(), "getTransposedMatrixWithShape(" + rows + "," + cols + "," + seed + ")"); }
public static Pair<INDArray, String> getPermutedWithShape(char ordering, long rows, long cols, long seed) { Nd4j.getRandom().setSeed(seed); long len = rows * cols; INDArray arr = Nd4j.linspace(1, len, len).reshape(cols, rows); return new Pair<>(arr.permute(1, 0), "getPermutedWithShape(" + rows + "," + cols + "," + seed + ")"); }
@Override public INDArray rand(int[] shape, double min, double max, org.nd4j.linalg.api.rng.Random rng) { Nd4j.getRandom().setSeed(rng.getSeed()); return Nd4j.getDistributions().createUniform(min, max).sample(shape); }
/** * Fill the given ndarray with random numbers drawn from a normal distribution * * @param target target array * @return the given target array */ public static INDArray randn(INDArray target, long seed) { Nd4j.getRandom().setSeed(seed); return getExecutioner().exec(new GaussianDistribution(target), Nd4j.getRandom()); }
@Override public INDArray rand(long[] shape, double min, double max, org.nd4j.linalg.api.rng.Random rng) { Nd4j.getRandom().setSeed(rng.getSeed()); return Nd4j.getDistributions().createUniform(min, max).sample(shape); }
/** * Fill the given ndarray with random numbers drawn from a uniform distribution * * @param target target array * @param seed the seed to use * @return the given target array */ public static INDArray rand(INDArray target, long seed) { Nd4j.getRandom().setSeed(seed); return getExecutioner().exec(new UniformDistribution(target), Nd4j.getRandom()); }