static INDArray invert(INDArray arr1) { return booleanOp(arr1, Conditions.equals(0)); }
private static INDArray filteredStd(DistributionStats stats) { /* To avoid division by zero when the std deviation is zero, replace zeros by one */ INDArray stdCopy = stats.getStd(); BooleanIndexing.replaceWhere(stdCopy, 1.0, Conditions.equals(0)); return stdCopy; } }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { // no support in ELU native to override alpha if (alpha != 1.00) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new ELUDerivative(in.dup())); dLdz.muli(alpha); BooleanIndexing.replaceWhere(dLdz, 1, Conditions.equals(alpha)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); } else { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new ELUDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); } }
private static INDArray filteredStd(DistributionStats stats) { /* To avoid division by zero when the std deviation is zero, replace zeros by one */ INDArray stdCopy = stats.getStd(); BooleanIndexing.replaceWhere(stdCopy, 1.0, Conditions.equals(0)); return stdCopy; } }
@Override public DoubleTensor setWithMaskInPlace(DoubleTensor mask, Double value) { if (this.getLength() != mask.getLength()) { throw new IllegalArgumentException("The lengths of the tensor and mask must match, but got tensor length: " + this.getLength() + ", mask length: " + mask.getLength()); } INDArray maskDup = unsafeGetNd4J(mask).dup(); double trueValue = 1.0; if (value == 0.0) { trueValue = 1.0 - trueValue; maskDup.negi().addi(1); } double falseValue = 1.0 - trueValue; Nd4j.getExecutioner().exec( new CompareAndSet(maskDup, value, Conditions.equals(trueValue)) ); Nd4j.getExecutioner().exec( new CompareAndSet(tensor, maskDup, Conditions.notEquals(falseValue)) ); return this; }
@Override public IntegerTensor setWithMaskInPlace(IntegerTensor mask, Integer value) { if (this.getLength() != mask.getLength()) { throw new IllegalArgumentException("The lengths of the tensor and mask must match, but got tensor length: " + this.getLength() + ", mask length: " + mask.getLength()); } INDArray maskDup = unsafeGetNd4J(mask).dup(); if (value == 0.0) { INDArray swapOnesForZeros = maskDup.rsubi(1.0); tensor.muli(swapOnesForZeros); } else { Nd4j.getExecutioner().exec( new CompareAndSet(maskDup, value, Conditions.equals(1.0)) ); Nd4j.getExecutioner().exec( new CompareAndSet(tensor, maskDup, Conditions.notEquals(0.0)) ); } return this; }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { // no support in ELU native to override alpha if (alpha != 1.00) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new ELUDerivative(in.dup())); dLdz.muli(alpha); BooleanIndexing.replaceWhere(dLdz, 1, Conditions.equals(alpha)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); } else { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new ELU(in).derivative()); dLdz.muli(epsilon); return new Pair<>(dLdz, null); } }
BooleanIndexing.replaceWhere(negInfMask, Double.NEGATIVE_INFINITY, Conditions.equals(1.0));
BooleanIndexing.replaceWhere(negInfMask, Double.NEGATIVE_INFINITY, Conditions.equals(1.0));
MatchCondition condition = new MatchCondition(totalCountBins, Conditions.equals(0)); int numZeroBins = Nd4j.getExecutioner().exec(condition, Integer.MAX_VALUE).getInt(0); if (numZeroBins != 0) {
BooleanIndexing.replaceWhere(negInfMask, Double.NEGATIVE_INFINITY, Conditions.equals(1.0));
BooleanIndexing.replaceWhere(negInfMask, Double.NEGATIVE_INFINITY, Conditions.equals(1.0));