use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.
the class Erfc method doDiff.
@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
// erfc(z) = 1 - erf(z)
// Derivative of erf(z) is 2 / sqrt(pi) * e^(-z^2), so have to multiply by -1.
SDVariable gradient = i_v.get(0);
SDVariable constant = sameDiff.onesLike(gradient).mul(-2).div(Math.sqrt(Math.PI));
SDVariable ret = constant.mul(sameDiff.exp(gradient.mul(gradient).mul(-1)));
return Arrays.asList(ret);
}
use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.
the class OldAddOp method doDiff.
@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
SDVariable gradWrtX = f().div(i_v.get(0), rarg());
SDVariable gradWrtY = f().mul(f().neg(gradWrtX), f().div(larg(), rarg()));
List<SDVariable> ret = new ArrayList<>(2);
ret.add(gradWrtX);
ret.add(gradWrtY);
return ret;
}
use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.
the class OldSubOp method doDiff.
@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
SDVariable gradWrtX = f().div(i_v.get(0), rarg());
SDVariable gradWrtY = f().mul(f().neg(gradWrtX), f().div(larg(), rarg()));
List<SDVariable> ret = new ArrayList<>(2);
ret.add(gradWrtX);
ret.add(gradWrtY);
return ret;
}
use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.
the class ClipByValue method doDiff.
@Override
public List<SDVariable> doDiff(List<SDVariable> grad) {
// dOut/dIn is 0 if clipped, 1 otherwise
SDVariable out = outputVariables()[0];
SDVariable notClippedLower = f().gt(arg(), clipValueMin);
SDVariable notClippedUpper = f().lt(arg(), clipValueMax);
SDVariable ret = notClippedLower.mul(notClippedUpper).mul(grad.get(0));
return Arrays.asList(ret);
}
use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.
the class Set method doDiff.
@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
val shape = outputVariables()[0].getShape();
SDVariable ym1 = f().rsub(rarg(), f().one(shape));
SDVariable ret = f().mul(f().mul(rarg(), f().pow(larg(), 2.0)), larg());
return Arrays.asList(ret);
}
Aggregations