org.nd4j.linalg.factory.Nd4j.rand()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.nd4j.linalg.factory.Nd4j.rand()方法的一些代码示例,展示了Nd4j.rand()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.rand()方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:rand

Nd4j.rand介绍

[英]Create a random ndarray with the given shape and output order
[中]用给定的形状和输出顺序创建一个随机数组

代码示例

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. //As per Glorot and Bengio 2010: Uniform distribution U(-s,s) with s = sqrt(6/(fanIn + fanOut))
  4. //Eq 16: http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf
  5. double s = Math.sqrt(6.0) / Math.sqrt(fanIn + fanOut);
  6. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-s, s));
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double scalingFanIn = 3.0 / Math.sqrt(fanIn);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanIn, scalingFanIn));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double a = 1.0 / Math.sqrt(fanIn);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-a, a));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double r = 4.0 * Math.sqrt(6.0 / (fanIn + fanOut));
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-r, r));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double u = Math.sqrt(6.0 / fanIn);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-u, u)); //U(-sqrt(6/fanIn), sqrt(6/fanIn)
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double scalingFanAvg = 3.0 / Math.sqrt((fanIn + fanOut) / 2);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanAvg, scalingFanAvg));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double scalingFanOut = 3.0 / Math.sqrt(fanOut);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-scalingFanOut, scalingFanOut));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. double b = 3.0 / Math.sqrt(fanIn);
  4. return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-b, b));
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape and array order
  3. *
  4. * @param order the order of the ndarray to return
  5. * @param shape the shape of the ndarray
  6. * @return the random ndarray with the specified shape
  7. */
  8. public static INDArray rand(char order, int[] shape) {
  9. INDArray ret = Nd4j.createUninitialized(shape, order); //INSTANCE.rand(order, shape);
  10. logCreationIfNecessary(ret);
  11. return rand(ret);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static List<Pair<INDArray, String>> get5dPermutedWithShape(int seed, int... shape) {
  2. Nd4j.getRandom().setSeed(seed);
  3. int[] createdShape = {shape[1], shape[4], shape[3], shape[2], shape[0]};
  4. INDArray arr = Nd4j.rand(createdShape);
  5. INDArray permuted = arr.permute(4, 0, 3, 2, 1);
  6. return Collections.singletonList(new Pair<>(permuted,
  7. "get5dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)"));
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static List<Pair<INDArray, String>> get4dPermutedWithShape(int seed, int... shape) {
  2. Nd4j.getRandom().setSeed(seed);
  3. int[] createdShape = {shape[1], shape[3], shape[2], shape[0]};
  4. INDArray arr = Nd4j.rand(createdShape);
  5. INDArray permuted = arr.permute(3, 0, 2, 1);
  6. return Collections.singletonList(new Pair<>(permuted,
  7. "get4dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)"));
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static List<Pair<INDArray, String>> get6dPermutedWithShape(int seed, int... shape) {
  2. Nd4j.getRandom().setSeed(seed);
  3. int[] createdShape = {shape[1], shape[4], shape[5], shape[3], shape[2], shape[0]};
  4. INDArray arr = Nd4j.rand(createdShape);
  5. INDArray permuted = arr.permute(5, 0, 4, 3, 1, 2);
  6. return Collections.singletonList(new Pair<>(permuted,
  7. "get6dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)"));
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape using
  3. * the current time as the seed
  4. *
  5. * @param shape the shape of the ndarray
  6. * @return the random ndarray with the specified shape
  7. */
  8. public static INDArray rand(int[] shape) {
  9. INDArray ret = createUninitialized(shape, order()); //INSTANCE.rand(shape, Nd4j.getRandom());
  10. logCreationIfNecessary(ret);
  11. return rand(ret);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape using given seed
  3. *
  4. * @param shape the shape of the ndarray
  5. * @param seed the seed to use
  6. * @return the random ndarray with the specified shape
  7. */
  8. public static INDArray rand(int[] shape, long seed) {
  9. INDArray ret = createUninitialized(shape, Nd4j.order());//;INSTANCE.rand(shape, seed);
  10. logCreationIfNecessary(ret);
  11. return rand(ret, seed);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static List<Pair<INDArray, String>> get4dReshapedWithShape(int seed, int... shape) {
  2. Nd4j.getRandom().setSeed(seed);
  3. int[] shape2d = {shape[0] * shape[2], shape[1] * shape[3]};
  4. INDArray array2d = Nd4j.rand(shape2d);
  5. INDArray array3d = array2d.reshape(ArrayUtil.toLongArray(shape));
  6. return Collections.singletonList(new Pair<>(array3d,
  7. "get4dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)"));
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static List<Pair<INDArray, String>> get5dReshapedWithShape(int seed, int... shape) {
  2. Nd4j.getRandom().setSeed(seed);
  3. int[] shape2d = {shape[0] * shape[2], shape[4], shape[1] * shape[3]};
  4. INDArray array3d = Nd4j.rand(shape2d);
  5. INDArray array5d = array3d.reshape(ArrayUtil.toLongArray(shape));
  6. return Collections.singletonList(new Pair<>(array5d,
  7. "get5dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)"));
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape using the given seed
  3. *
  4. * @param rows the number of rows in the matrix
  5. * @param columns the columns of the ndarray
  6. * @param seed the seed to use
  7. * @return the random ndarray with the specified shape
  8. */
  9. public static INDArray rand(int rows, int columns, long seed) {
  10. INDArray ret = createUninitialized(new int[] {rows, columns}, Nd4j.order());
  11. logCreationIfNecessary(ret);
  12. return rand(ret, seed);
  13. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape using the given rng
  3. *
  4. * @param rows the number of rows in the matrix
  5. * @param columns the number of columns in the matrix
  6. * @param rng the random generator to use
  7. * @return the random ndarray with the specified shape
  8. */
  9. public static INDArray rand(int rows, int columns, org.nd4j.linalg.api.rng.Random rng) {
  10. INDArray ret = createUninitialized(new int[] {rows, columns}, order());//INSTANCE.rand(rows, columns, rng);
  11. logCreationIfNecessary(ret);
  12. return rand(ret, rng);
  13. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public static INDArray rand(long[] shape) {
  2. INDArray ret = createUninitialized(shape, order()); //INSTANCE.rand(shape, Nd4j.getRandom());
  3. logCreationIfNecessary(ret);
  4. return rand(ret);
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Create a random ndarray with the given shape using
  3. * the current time as the seed
  4. *
  5. * @param shape the shape of the ndarray
  6. * @return the random ndarray with the specified shape
  7. */
  8. public static IComplexNDArray complexRand(int... shape) {
  9. INDArray based = Nd4j.rand(new int[] {1, ArrayUtil.prod(shape) * 2});
  10. IComplexNDArray ret = Nd4j.createComplex(based.data(), shape);
  11. logCreationIfNecessary(ret);
  12. return ret;
  13. }

相关文章