BinaryOpElementwise Type

Defines a new op implementing an elementwise binary function and its derivatives. Instances of this class are used with the Tensor.Op method to define a new differentiable tensor function that supports forward, reverse, and nested differentiation.

This type is specialized to elementwise ops. It requires the user to specify only (1) the RawTensor operation and (2) the derivative of the function with respect to each argument. The corresponding derivative propagation rules for the forward and reverse differentiation modes are automatically generated.

If you are implementing a complex op that is not elementwise, you can use the generic type BinaryOp, which allows you to define the full derivative propagation rules.

Example

 { new BinaryOpElementwise("pow") with
     member _.fRaw(a,b) = a.PowTT(b)
     member _.dfda(a,b,f) = b * f / a
     member _.dfdb(a,b,f) = f * a.log()
 }

 { new BinaryOpElementwise("mul") with
     member _.fRaw(a,b) = a.MulTT(b)
     member _.dfda(a,b,f) = b
     member _.dfdb(a,b,f) = a
 }

Constructors

Constructor Description

BinaryOpElementwise(name)

Full Usage: BinaryOpElementwise(name)

Parameters:
    name : string

Returns: BinaryOpElementwise
name : string
Returns: BinaryOpElementwise

Instance members

Instance member Description

this.dfda (a, b, f)

Full Usage: this.dfda (a, b, f)

Parameters:
    a : Tensor - The first argument \( a \)
    b : Tensor - The second argument \( b \)
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor The tensor corresponding to \( \frac{\partial f(a, b)}{\partial a} \).
Modifiers: abstract

Derivative of the function with respect to its first argument, \( \frac{\partial f(a, b)}{\partial a} \).

a : Tensor

The first argument \( a \)

b : Tensor

The second argument \( b \)

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor

The tensor corresponding to \( \frac{\partial f(a, b)}{\partial a} \).

this.dfdb (a, b, f)

Full Usage: this.dfdb (a, b, f)

Parameters:
    a : Tensor - The first argument \( a \)
    b : Tensor - The second argument \( b \)
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor The tensor corresponding to \( \frac{\partial f(a, b)}{\partial b} \).
Modifiers: abstract

Derivative of the function with respect to its second argument, \( \frac{\partial f(a, b)}{\partial b} \).

a : Tensor

The first argument \( a \)

b : Tensor

The second argument \( b \)

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor

The tensor corresponding to \( \frac{\partial f(a, b)}{\partial b} \).

Inherited members

Inherited from BinaryOp

Instance members

Instance member Description

this.ad_dfda (a, ad, b, f)

Full Usage: this.ad_dfda (a, ad, b, f)

Parameters:
    a : Tensor - The first argument \( a \).
    ad : Tensor - The first argument's derivative \( \frac{\partial a}{\partial x} \).
    b : Tensor - The second argument \( b \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor The tensor corresponding to \( \frac{\partial a}{\partial x} \frac{\partial f(a, b)}{\partial a} \).
Modifiers: abstract

Derivative propagation rule for forward differentiation mode for the partial derivative with respect to the first argument of the function. This represents the contribution of the function's first argument \( a \) to the derivative of \( f(a, b) \) with respect a value \( x \) earlier in the computation graph than the function's arguments. In other words, it computes the first term in the right-hand side of the equation \( \frac{\partial f(a, b)}{\partial x} = \frac{\partial a}{\partial x} \frac{\partial f(a, b)}{\partial a} + \frac{\partial b}{\partial x} \frac{\partial f(a, b)}{\partial b} \).

a : Tensor

The first argument \( a \).

ad : Tensor

The first argument's derivative \( \frac{\partial a}{\partial x} \).

b : Tensor

The second argument \( b \).

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor

The tensor corresponding to \( \frac{\partial a}{\partial x} \frac{\partial f(a, b)}{\partial a} \).

this.bd_dfdb (a, b, bd, f)

Full Usage: this.bd_dfdb (a, b, bd, f)

Parameters:
    a : Tensor - The first argument \( a \).
    b : Tensor - The second argument \( b \).
    bd : Tensor - The second argument's derivative \( \frac{\partial b}{\partial x} \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor The tensor corresponding to \( \frac{\partial b}{\partial x} \frac{\partial f(a, b)}{\partial b} \).
Modifiers: abstract

Derivative propagation rule for forward differentiation mode for the partial derivative with respect to the second argument of the function. This represents the contribution of the function's second argument \( b \) to the derivative of \( f(a, b) \) with respect a value \( x \) earlier in the computation graph than the function's arguments. In other words, it computes the second term in the right-hand side of the equation \( \frac{\partial f(a, b)}{\partial x} = \frac{\partial a}{\partial x} \frac{\partial f(a, b)}{\partial a} + \frac{\partial b}{\partial x} \frac{\partial f(a, b)}{\partial b} \).

a : Tensor

The first argument \( a \).

b : Tensor

The second argument \( b \).

bd : Tensor

The second argument's derivative \( \frac{\partial b}{\partial x} \).

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

Returns: Tensor

The tensor corresponding to \( \frac{\partial b}{\partial x} \frac{\partial f(a, b)}{\partial b} \).

this.fRaw (a, b)

Full Usage: this.fRaw (a, b)

Parameters:
    a : RawTensor - The first argument \( a \).
    b : RawTensor - The second argument \( b \).

Returns: RawTensor The function's value \( f(a, b) \).
Modifiers: abstract

RawTensor operation \( f(a, b) \) performing the op.

a : RawTensor

The first argument \( a \).

b : RawTensor

The second argument \( b \).

Returns: RawTensor

The function's value \( f(a, b) \).

this.fd_dfda (a, b, f, fd)

Full Usage: this.fd_dfda (a, b, f, fd)

Parameters:
    a : Tensor - The first argument \( a \).
    b : Tensor - The second argument \( b \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.
    fd : Tensor - The derivative with respect to the function's output \( \frac{\partial y}{\partial f(a, b)} \).

Returns: Tensor The tensor corresponding to \( \frac{\partial y}{\partial a} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial a} \).
Modifiers: abstract

Derivative propagation rule for reverse differentiation mode for the partial derivative with respect to the first argument of the function. This represents the derivative of a value \( y \), which comes later in the computation graph than the function's value \( f(a, b) \), with respect to the function's first argument \( a \). In other words, it computes \( \frac{\partial y}{\partial a} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial a} \).

a : Tensor

The first argument \( a \).

b : Tensor

The second argument \( b \).

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

fd : Tensor

The derivative with respect to the function's output \( \frac{\partial y}{\partial f(a, b)} \).

Returns: Tensor

The tensor corresponding to \( \frac{\partial y}{\partial a} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial a} \).

this.fd_dfdb (a, b, f, fd)

Full Usage: this.fd_dfdb (a, b, f, fd)

Parameters:
    a : Tensor - The first argument \( a \).
    b : Tensor - The second argument \( b \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.
    fd : Tensor - The derivative with respect to the function's output \( \frac{\partial y}{\partial f(a, b)} \).

Returns: Tensor The tensor corresponding to \( \frac{\partial y}{\partial b} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial b} \).
Modifiers: abstract

Derivative propagation rule for reverse differentiation mode for the partial derivative with respect to the second argument of the function. This represents the derivative of a value \( y \), which comes later in the computation graph than the function's value \( f(a, b) \), with respect to the function's second argument \( b \). In other words, it computes \( \frac{\partial y}{\partial b} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial b} \).

a : Tensor

The first argument \( a \).

b : Tensor

The second argument \( b \).

f : Tensor

The function's pre-computed primal evaluation result \( f(a, b) \), which can be one of the terms involved in the derivative computation (e.g., the derivative of the exponential function) and be used without the need to recompute it.

fd : Tensor

The derivative with respect to the function's output \( \frac{\partial y}{\partial f(a, b)} \).

Returns: Tensor

The tensor corresponding to \( \frac{\partial y}{\partial b} = \frac{\partial y}{\partial f(a, b)} \frac{\partial f(a, b)}{\partial b} \).

this.name

Full Usage: this.name

Returns: string

Name of the op.

Returns: string

© Copyright 2021, DiffSharp and dfx Contributors.