本文整理了Java中org.nd4j.linalg.factory.Nd4j.getDistributions()
方法的一些代码示例,展示了Nd4j.getDistributions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.getDistributions()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:getDistributions
[英]Get the primary distributions factory
[中]获取主分发工厂
代码示例来源: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 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 b = 3.0 / Math.sqrt(fanIn);
return Nd4j.rand(shape, Nd4j.getDistributions().createUniform(-b, b));
}
代码示例来源: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 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 rand(long[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
//ensure shapes that wind up being scalar end up with the write shape
if (shape.length == 1 && shape[0] == 0) {
shape = new long[] {1, 1};
}
return Nd4j.getDistributions().createUniform(min, max).sample(shape);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Generates a random matrix between min and max
*
* @param shape the number of rows of the matrix
* @param min the minimum number
* @param max the maximum number
* @param rng the rng to use
* @return a random matrix of the specified shape and range
*/
@Override
public INDArray rand(int[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
//ensure shapes that wind up being scalar end up with the write shape
if (shape.length == 1 && shape[0] == 0) {
shape = new int[] {1, 1};
}
return Nd4j.getDistributions().createUniform(min, max).sample(shape);
}
代码示例来源:origin: deeplearning4j/nd4j
@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);
}
代码示例来源:origin: deeplearning4j/nd4j
@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);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Create an ndarray
* of
* @param seed
* @param rank
* @param numShapes
* @return
*/
public static int[][] getRandomBroadCastShape(long seed, int rank, int numShapes) {
Nd4j.getRandom().setSeed(seed);
INDArray coinFlip = Nd4j.getDistributions().createBinomial(1, 0.5).sample(new int[] {numShapes, rank});
int[][] ret = new int[(int) coinFlip.rows()][(int) coinFlip.columns()];
for (int i = 0; i < coinFlip.rows(); i++) {
for (int j = 0; j < coinFlip.columns(); j++) {
int set = coinFlip.getInt(i, j);
if (set > 0)
ret[i][j] = set;
else {
//anything from 0 to 9
ret[i][j] = Nd4j.getRandom().nextInt(9) + 1;
}
}
}
return ret;
}
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Generates a random matrix between min and max
*
* @param shape the number of rows of the matrix
* @param min the minimum number
* @param max the maximum number
* @param rng the rng to use
* @return a random matrix of the specified shape and range
*/
@Override
public INDArray rand(int[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
//ensure shapes that wind up being scalar end up with the write shape
if (shape.length == 1 && shape[0] == 0) {
shape = new int[] {1, 1};
}
return Nd4j.getDistributions().createUniform(min, max).sample(shape);
}
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
@Override
public INDArray preProcess(INDArray input, int miniBatchSize) {
return Nd4j.getDistributions().createBinomial(1, input).sample(input.shape());
}
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
public static org.nd4j.linalg.api.rng.distribution.Distribution createDistribution(Distribution dist) {
if (dist == null)
return null;
if (dist instanceof NormalDistribution) {
NormalDistribution nd = (NormalDistribution) dist;
return Nd4j.getDistributions().createNormal(nd.getMean(), nd.getStd());
}
if (dist instanceof GaussianDistribution) {
GaussianDistribution nd = (GaussianDistribution) dist;
return Nd4j.getDistributions().createNormal(nd.getMean(), nd.getStd());
}
if (dist instanceof UniformDistribution) {
UniformDistribution ud = (UniformDistribution) dist;
return Nd4j.getDistributions().createUniform(ud.getLower(), ud.getUpper());
}
if (dist instanceof BinomialDistribution) {
BinomialDistribution bd = (BinomialDistribution) dist;
return Nd4j.getDistributions().createBinomial(bd.getNumberOfTrials(), bd.getProbabilityOfSuccess());
}
throw new RuntimeException("unknown distribution type: " + dist.getClass());
}
}
代码示例来源:origin: org.deeplearning4j/deeplearning4j-nn
/**
* Corrupts the given input by doing a binomial sampling
* given the corruption level
* @param x the input to corrupt
* @param corruptionLevel the corruption value
* @return the binomial sampled corrupted input
*/
public INDArray getCorruptedInput(INDArray x, double corruptionLevel) {
INDArray corrupted = Nd4j.getDistributions().createBinomial(1, 1 - corruptionLevel).sample(x.shape());
corrupted.muli(x);
return corrupted;
}
代码示例来源:origin: org.nd4j/nd4j-api
@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);
}
代码示例来源:origin: org.nd4j/canova-nd4j-image
public static void drawMnist(DataSet mnist,INDArray reconstruct) throws InterruptedException {
for(int j = 0; j < mnist.numExamples(); j++) {
INDArray draw1 = mnist.get(j).getFeatureMatrix().mul(255);
INDArray reconstructed2 = reconstruct.getRow(j);
INDArray draw2 = Nd4j.getDistributions().createBinomial(1,reconstructed2).sample(reconstructed2.shape()).mul(255);
DrawReconstruction d = new DrawReconstruction(draw1);
d.title = "REAL";
d.draw();
DrawReconstruction d2 = new DrawReconstruction(draw2,1000,1000);
d2.title = "TEST";
d2.draw();
Thread.sleep(1000);
d.frame.dispose();
d2.frame.dispose();
}
}
代码示例来源:origin: org.datavec/datavec-data-image
public static void drawMnist(DataSet mnist, INDArray reconstruct) throws InterruptedException {
for (int j = 0; j < mnist.numExamples(); j++) {
INDArray draw1 = mnist.get(j).getFeatureMatrix().mul(255);
INDArray reconstructed2 = reconstruct.getRow(j);
INDArray draw2 = Nd4j.getDistributions().createBinomial(1, reconstructed2).sample(reconstructed2.shape())
.mul(255);
DrawReconstruction d = new DrawReconstruction(draw1);
d.title = "REAL";
d.draw();
DrawReconstruction d2 = new DrawReconstruction(draw2, 1000, 1000);
d2.title = "TEST";
d2.draw();
Thread.sleep(1000);
d.frame.dispose();
d2.frame.dispose();
}
}
内容来源于网络,如有侵权,请联系作者删除!