from_dense
from_dense(hessian, output_shape)Factors of any per-example output Hessian, through its eigendecomposition.
With H = Q diag(lambda) Q^T, factor e is sqrt(|lambda_e|) q_e with sign sign(lambda_e) (+1 for a zero eigenvalue), so indefinite Hessians work too.
The factors keep the graph of hessian, through torch.linalg.eigh. Its gradient is not defined at repeated or zero eigenvalues; pass hessian.detach() when the factors need no gradient.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| hessian | Tensor | [N, K, K], symmetric, with K = prod(output_shape). |
required |
| output_shape | tuple[int, …] | The shape of one example’s output. | required |
Returns
| Name | Type | Description |
|---|---|---|
| OutputFactors | Factors [K, N, *output_shape] with signs [K, N]. |
Raises
| Name | Type | Description |
|---|---|---|
| FactorError | hessian is not [N, K, K] or K does not match output_shape. |