@Override public INDArray doCreate(long[] shape, INDArray paramsView) { //As per Glorot and Bengio 2010: Uniform distribution U(-s,s) with s = sqrt(6/(fanIn + fanOut)) //Eq 16: http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf double s = Math.sqrt(6.0) / Math.sqrt(fanIn + fanOut); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-s, s)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double scalingFanIn = 3.0 / Math.sqrt(fanIn); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanIn, scalingFanIn)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double a = 1.0 / Math.sqrt(fanIn); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-a, a)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double r = 4.0 * Math.sqrt(6.0 / (fanIn + fanOut)); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-r, r)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double u = Math.sqrt(6.0 / fanIn); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-u, u)); //U(-sqrt(6/fanIn), sqrt(6/fanIn) }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double scalingFanAvg = 3.0 / Math.sqrt((fanIn + fanOut) / 2); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanAvg, scalingFanAvg)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double scalingFanOut = 3.0 / Math.sqrt(fanOut); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanOut, scalingFanOut)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { double b = 3.0 / Math.sqrt(fanIn); return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-b, b)); }
/** * Create a random ndarray with the given shape and array order * * @param order the order of the ndarray to return * @param shape the shape of the ndarray * @return the random ndarray with the specified shape */ public static INDArray rand(char order, int[] shape) { INDArray ret = Nd4j.createUninitialized(shape, order); //INSTANCE.rand(order, shape); logCreationIfNecessary(ret); return rand(ret); }
public static List<Pair<INDArray, String>> get5dPermutedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] createdShape = {shape[1], shape[4], shape[3], shape[2], shape[0]}; INDArray arr = Nd4j.rand(createdShape); INDArray permuted = arr.permute(4, 0, 3, 2, 1); return Collections.singletonList(new Pair<>(permuted, "get5dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
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)")); }
/** * Create a random ndarray with the given shape using * the current time as the seed * * @param shape the shape of the ndarray * @return the random ndarray with the specified shape */ public static INDArray rand(int[] shape) { INDArray ret = createUninitialized(shape, order()); //INSTANCE.rand(shape, Nd4j.getRandom()); logCreationIfNecessary(ret); return rand(ret); }
/** * Create a random ndarray with the given shape using given seed * * @param shape the shape of the ndarray * @param seed the seed to use * @return the random ndarray with the specified shape */ public static INDArray rand(int[] shape, long seed) { INDArray ret = createUninitialized(shape, Nd4j.order());//;INSTANCE.rand(shape, seed); logCreationIfNecessary(ret); return rand(ret, seed); }
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)")); }
/** * Create a random ndarray with the given shape using the given seed * * @param rows the number of rows in the matrix * @param columns the columns of the ndarray * @param seed the seed to use * @return the random ndarray with the specified shape */ public static INDArray rand(int rows, int columns, long seed) { INDArray ret = createUninitialized(new int[] {rows, columns}, Nd4j.order()); logCreationIfNecessary(ret); return rand(ret, seed); }
/** * Create a random ndarray with the given shape using the given rng * * @param rows the number of rows in the matrix * @param columns the number of columns in the matrix * @param rng the random generator to use * @return the random ndarray with the specified shape */ public static INDArray rand(int rows, int columns, org.nd4j.linalg.api.rng.Random rng) { INDArray ret = createUninitialized(new int[] {rows, columns}, order());//INSTANCE.rand(rows, columns, rng); logCreationIfNecessary(ret); return rand(ret, rng); }
public static INDArray rand(long[] shape) { INDArray ret = createUninitialized(shape, order()); //INSTANCE.rand(shape, Nd4j.getRandom()); logCreationIfNecessary(ret); return rand(ret); }
/** * Create a random ndarray with the given shape using * the current time as the seed * * @param shape the shape of the ndarray * @return the random ndarray with the specified shape */ public static IComplexNDArray complexRand(int... shape) { INDArray based = Nd4j.rand(new int[] {1, ArrayUtil.prod(shape) * 2}); IComplexNDArray ret = Nd4j.createComplex(based.data(), shape); logCreationIfNecessary(ret); return ret; }