TorchLean API

NN.API.Autograd.Complex

Real losses on complex parameters #

An Objective returns a real scalar while retaining complex parameter tensors. Forward-mode seeding differentiates both coordinates, including nonholomorphic operations such as conjugation and squared magnitude. No complex-linear reverse rule is assumed. The gradient is represented as dL/dre + i*dL/dim; multiplying it by a real learning rate gives the ordinary Euclidean update on the two coordinates. In the convention with a factor of one half in Wirtinger derivatives, this is twice the conjugate Wirtinger derivative.

grad evaluates two directional passes per complex parameter entry. This reference algorithm is useful for small models and checking specialized backward implementations, not a claim of an efficient large-model reverse pass. Objectives must be deterministic across those evaluations. Scalar branch conventions still apply at nonsmooth points and complex branch cuts.

@[reducible, inline]

A deterministic, real-valued objective on shape-indexed complex model state.

Instances For
    def TorchLean.autograd.complex.jvp {shapes : List Shape} (objective : Objective shapes) {α : Type} [Storage α] [Context α] [Atan2 α] (state direction : nn.State (Complex α) shapes) :
    IO (α × α)

    Evaluate a real objective and its directional derivative in one forward-mode pass.

    Both coordinates of direction are seeded independently; the tangent is the real scalar pairing sum (dL/dre * direction.re + dL/dim * direction.im).

    Instances For
      def TorchLean.autograd.complex.grad {shapes : List Shape} (objective : Objective shapes) {α : Type} [Storage α] [Context α] [Atan2 α] (state : nn.State (Complex α) shapes) (value : Bool := false) :
      IO (if value = true then nn.State (Complex α) shapes × α else nn.State (Complex α) shapes)

      Differentiate a real objective with respect to every complex parameter coordinate.

      The returned state contains dL/dre and dL/dim, not a complex analytic derivative. Set value := true to also return the real objective value. Empty tensors remain empty; the value form still evaluates the objective when there are no parameters.

      Instances For