/** * Reverse division (in-place) * * @param other the other ndarray to subtract * @param result the result ndarray * @return the ndarray with the operation applied */ @Override public INDArray rdivi(INDArray other, INDArray result) { return other.divi(this, result); }
/** * Reverse division (in-place) * * @param other the other ndarray to subtract * @param result the result ndarray * @return the ndarray with the operation applied */ @Override public IComplexNDArray rdivi(INDArray other, INDArray result) { return (IComplexNDArray) other.divi(this, result); }
@Override public void preProcess(org.nd4j.linalg.dataset.api.DataSet toPreProcess) { toPreProcess.getFeatures().divi(255); //[0,255] -> [0,1] for input pixel values } }
@Override public IComplexNDArray div(IComplexNumber n, IComplexNDArray result) { return dup().divi(n, result); }
@Override public IComplexNDArray div(IComplexNumber n) { return dup().divi(n); }
@Override public INDArray computeScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask) { INDArray scoreArr = super.computeScoreArray(labels, preOutput, activationFn, mask); scoreArr.divi(scoreArr.size(1)); return scoreArr; }
public void preProcess(INDArray features) { features.divi(this.maxPixelVal); //Scaled to 0->1 if (this.maxRange - this.minRange != 1) features.muli(this.maxRange - this.minRange); //Scaled to minRange -> maxRange if (this.minRange != 0) features.addi(this.minRange); //Offset by minRange }
@Override public void revertFeatures(INDArray features) { if (minRange != 0) { features.subi(minRange); } if (maxRange - minRange != 1.0) { features.divi(maxRange - minRange); } features.muli(this.maxPixelVal); }
@Override public INDArray computeGradient(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask) { INDArray gradients = super.computeGradient(labels, preOutput, activationFn, mask); return gradients.divi(labels.size(1)); }
@Override public void revertFeatures(INDArray[] features) { for( int i=0; i<featureIndices.length; i++ ){ INDArray f = features[featureIndices[i]]; if (minRange != 0) { f.subi(minRange); } if (maxRange - minRange != 1.0) { f.divi(maxRange - minRange); } f.muli(this.maxPixelVal); } }
@Override public INDArray computeGradient(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask) { INDArray gradients = super.computeGradient(labels, preOutput, activationFn, mask); gradients.divi(labels.size(1)); return gradients; }
@Override public INDArray computeScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask) { INDArray scoreArr = super.computeScoreArray(labels, preOutput, activationFn, mask); return scoreArr.divi(labels.size(1)); }
@Override public void divideBy(int num) { getFeatures().divi(Nd4j.scalar(num)); }
@Override public void preProcess(MultiDataSet multiDataSet) { for( int i=0; i<featureIndices.length; i++ ){ INDArray f = multiDataSet.getFeatures(featureIndices[i]); f.divi(this.maxPixelVal); //Scaled to 0->1 if (this.maxRange - this.minRange != 1) f.muli(this.maxRange - this.minRange); //Scaled to minRange -> maxRange if (this.minRange != 0) f.addi(this.minRange); //Offset by minRange } }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { return Nd4j.randn(order(), shape).divi(FastMath.sqrt(fanIn)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { return Nd4j.randn(order(), shape).divi(FastMath.sqrt(fanIn)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { return Nd4j.randn(order(), shape).divi(FastMath.sqrt((fanIn + fanOut) / 2)); }
@Override public INDArray doCreate(long[] shape, INDArray paramsView) { return Nd4j.randn(order(), shape).divi(FastMath.sqrt(fanOut)); }
/** * Divides each row by its max * * @param toScale the matrix to divide by its row maxes */ public static void scaleByMax(INDArray toScale) { INDArray scale = toScale.max(1); for (int i = 0; i < toScale.rows(); i++) { double scaleBy = scale.getDouble(i); toScale.putRow(i, toScale.getRow(i).divi(scaleBy)); } }
@Override public void applyUpdater(INDArray gradient, int iteration, int epoch) { if (lastGradient == null) throw new IllegalStateException("Updater has not been initialized with view state"); double learningRate = config.getLearningRate(iteration, epoch); double rmsDecay = config.getRmsDecay(); double epsilon = config.getEpsilon(); lastGradient.muli(rmsDecay).addi(gradient.mul(gradient).muli(1 - rmsDecay)); // lr * gradient / (sqrt(cache) + 1e-8) gradient.muli(learningRate).divi(Transforms.sqrt(lastGradient.dup(gradientReshapeOrder), false).addi(epsilon)); } }