Learning a complex affine map from a real loss #
Fit z ↦ (2-i)*z + (1/2+3i/4) at four points on the unit circle. The model, parameters,
predictions, and checkpoint remain complex; only the squared-residual objective is real.
autograd.complex.grad differentiates both coordinates and nn.sgdStep updates them together.
This small example uses the coordinate-forward reference algorithm, not a complex reverse engine.
An ordinary linear builder, evaluated with complex scalar arithmetic.
Instances For
def
NN.Examples.Models.Operators.ComplexRegression.objective
{α : Type}
[TorchLean.Storage α]
[Context α]
[Atan2 α]
(state : TorchLean.nn.State (TorchLean.Complex α) (Runtime.Autograd.Model.Layers.Seq.stateShapes model))
:
IO α
Half the mean squared complex residual, returned in the real component type.
Instances For
def
NN.Examples.Models.Operators.ComplexRegression.run
(steps : ℕ := 50)
(checkpoint : Option System.FilePath := none)
:
Train both complex components, optionally persisting the exact final state.