Automatic Differentiation¶
Compute the gradient of a scalar-valued function w.r.t. the input at index argnum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction[I, Tensor]
|
A NumericalFunction with one or more inputs and a scalar output. |
required |
argnum
|
int
|
Index of the input to differentiate w.r.t. (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
NumericalFunction[I, Tensor]
|
A NumericalFunction computing the gradient (same shape as input[argnum]). |
Compute the Jacobian of fn w.r.t. the input at index argnum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction[I, Tensor]
|
A NumericalFunction with one or more inputs and a single 1D output. |
required |
argnum
|
int
|
Index of the input to differentiate w.r.t. (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
NumericalFunction[I, Tensor]
|
A NumericalFunction computing the Jacobian matrix (output_dim, input_dim). |
Compute the sparse Jacobian of fn w.r.t. the input at index argnum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction[I, Tensor]
|
A NumericalFunction with one or more inputs and a single 1D output. |
required |
argnum
|
int
|
Index of the input to differentiate w.r.t. (default 0). |
0
|
unroll
|
bool
|
If True, unroll the JVP loop (useful for small problems). |
False
|
sep_uncompression
|
bool
|
If True, separate the uncompression step (often faster). |
True
|
symmetric
|
bool
|
If True, use star coloring for symmetric matrices (e.g., Hessians). |
False
|
Returns:
| Type | Description |
|---|---|
SparseNumericalFunction[I]
|
A SparseNumericalFunction computing the Jacobian data in CSC order. |
Compute the Hessian of a scalar-valued function w.r.t. the input at index argnum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction[I, Tensor]
|
A NumericalFunction with one or more inputs and a scalar output. |
required |
argnum
|
int
|
Index of the input to differentiate w.r.t. (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
NumericalFunction[I, Tensor]
|
A NumericalFunction computing the Hessian matrix (input_dim, input_dim). |
Compute the sparse Hessian of a scalar-valued function w.r.t. the input at index argnum.
The returned sparse matrix is upper-triangular in CSC format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction[I, Tensor]
|
A NumericalFunction with one or more inputs and a scalar output. |
required |
argnum
|
int
|
Index of the input to differentiate w.r.t. (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
SparseNumericalFunction[I]
|
A SparseNumericalFunction computing the upper-triangular Hessian data in CSC order. |