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

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

本文整理了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

@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));
}

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

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

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

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

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

@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));
}

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

@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)
}

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

@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));
}

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

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

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

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

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

/**
 * 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);
}

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

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)"));
}

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

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)"));
}

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

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)"));
}

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

/**
 * 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);
}

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

/**
 * 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);
}

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

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)"));
}

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

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)"));
}

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

/**
 * 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);
}

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

/**
 * 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);
}

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

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

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

/**
 * 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;
}

相关文章