Search in sources :

Example 46 with SDVariable

use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.

the class InvertPermutation method doDiff.

@Override
public List<SDVariable> doDiff(List<SDVariable> grad) {
    SDVariable gradient = grad.get(0);
    SDVariable invertedGradient = f().invertPermutation(gradient, false);
    return Arrays.asList(invertedGradient);
}
Also used : SDVariable(org.nd4j.autodiff.samediff.SDVariable)

Example 47 with SDVariable

use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.

the class Cross method doDiff.

@Override
public List<SDVariable> doDiff(List<SDVariable> gradients) {
    /**
     * dL / dx = dL / dCross * dCross / dx
     * dCross(a,b) / da = Cross(1, b)
     * dCross(a,b) / db = Cross(a, 1)
     *
     * return (grad * Cross(1, b), grad * Cross(a, 1)
     */
    SDVariable grad = gradients.get(0);
    SDVariable a = larg();
    SDVariable b = rarg();
    SDVariable ones = sameDiff.onesLike(a);
    SDVariable gradLeft = grad.mul(sameDiff.cross(ones, b));
    SDVariable gradRight = grad.mul(sameDiff.cross(a, ones));
    return Arrays.asList(gradLeft, gradRight);
}
Also used : SDVariable(org.nd4j.autodiff.samediff.SDVariable)

Example 48 with SDVariable

use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.

the class DiagPart method doDiff.

@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
    SDVariable grad = i_v.get(0);
    SDVariable ret = sameDiff.diag(grad);
    return Arrays.asList(ret);
}
Also used : SDVariable(org.nd4j.autodiff.samediff.SDVariable)

Example 49 with SDVariable

use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.

the class ACos method doDiff.

@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
    // dacos(x)/dx = -1 / sqrt(1-x^2)
    SDVariable oneSubSq = f().square(arg()).rsub(1.0);
    SDVariable sqrt = f().sqrt(oneSubSq);
    SDVariable ret = sqrt.rdiv(-1.0).mul(i_v.get(0));
    return Arrays.asList(ret);
}
Also used : SDVariable(org.nd4j.autodiff.samediff.SDVariable)

Example 50 with SDVariable

use of org.nd4j.autodiff.samediff.SDVariable in project nd4j by deeplearning4j.

the class ASin method doDiff.

@Override
public List<SDVariable> doDiff(List<SDVariable> i_v) {
    // d(asin(x))/dx = 1/sqrt(1-x^2)
    SDVariable oneSubSq = sameDiff.square(arg()).rsub(1.0);
    SDVariable ret = sameDiff.sqrt(oneSubSq).rdiv(1.0).mul(i_v.get(0));
    return Arrays.asList(ret);
}
Also used : SDVariable(org.nd4j.autodiff.samediff.SDVariable)

Aggregations

SDVariable (org.nd4j.autodiff.samediff.SDVariable)104 SameDiff (org.nd4j.autodiff.samediff.SameDiff)41 INDArray (org.nd4j.linalg.api.ndarray.INDArray)38 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)18 DynamicCustomOp (org.nd4j.linalg.api.ops.DynamicCustomOp)10 lombok.val (lombok.val)7 LossFunctions (org.nd4j.autodiff.loss.LossFunctions)4 LossInfo (org.nd4j.autodiff.loss.LossInfo)4 BernoulliDistribution (org.nd4j.linalg.api.ops.random.impl.BernoulliDistribution)4 Ignore (org.junit.Ignore)3 DifferentialFunction (org.nd4j.autodiff.functions.DifferentialFunction)3 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)3 Triple (org.nd4j.linalg.primitives.Triple)2 DataOutputStream (java.io.DataOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 NoOpNameFoundException (org.nd4j.imports.NoOpNameFoundException)1 NdIndexIterator (org.nd4j.linalg.api.iter.NdIndexIterator)1 TruncateDivOp (org.nd4j.linalg.api.ops.impl.transforms.arithmetic.TruncateDivOp)1