UnaryOp Type

Defines a new op implementing a unary 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 represents the most generic definition of a new op representing a unary function, allowing the specification of: (1) the RawTensor operation, (2) the derivative propagation rule for the forward differentiation mode and (3) the derivative propagation rule for the reverse differentiation mode.

In general, if you are implementing a simple elementwise op, you should prefer using the UnaryOpElementwise type, which is much simpler to use.

Example

 { new UnaryOp("transpose") with
     member _.fRaw(a) = a.TransposeT2()
     member _.ad_dfda(a,ad,f) = ad.transpose()
     member _.fd_dfda(a,f,fd) = fd.transpose()
 }

Constructors

Constructor Description

UnaryOp(name)

Full Usage: UnaryOp(name)

Parameters:
    name : string

Returns: UnaryOp
name : string
Returns: UnaryOp

Instance members

Instance member Description

this.ad_dfda (a, ad, f)

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

Parameters:
    a : Tensor - The argument \( a \).
    ad : Tensor - The argument's derivative \( \frac{\partial a}{\partial x} \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a) \), 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)}{\partial x} = \frac{\partial a}{\partial x} \frac{\partial f(a)}{\partial a} \).
Modifiers: abstract

Derivative propagation rule for forward differentiation mode. This represents the derivative of \( f(a) \) with respect a value \( x \) earlier in the computation graph than the function's argument \( a \). In other words, it computes \( \frac{\partial f(a)}{\partial x} = \frac{\partial a}{\partial x} \frac{\partial f(a)}{\partial a} \).

a : Tensor

The argument \( a \).

ad : Tensor

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

f : Tensor

The function's pre-computed primal evaluation result \( f(a) \), 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)}{\partial x} = \frac{\partial a}{\partial x} \frac{\partial f(a)}{\partial a} \).

this.fRaw a

Full Usage: this.fRaw a

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

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

a : RawTensor

The argument \( a \).

Returns: RawTensor

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

this.fd_dfda (a, f, fd)

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

Parameters:
    a : Tensor - The argument \( a \).
    f : Tensor - The function's pre-computed primal evaluation result \( f(a) \), 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)} \).

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

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

a : Tensor

The argument \( a \).

f : Tensor

The function's pre-computed primal evaluation result \( f(a) \), 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)} \).

Returns: Tensor

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

this.name

Full Usage: this.name

Returns: string

Name of the op.

Returns: string

© Copyright 2021, DiffSharp Contributors.