Optimizer Methods API
The optimizer methods, with their states and caches: the first-order methods on manifolds, Newton, and the quasi-Newton methods BFGS and DFP.
GeometricOptimizers.AdamFamily — Type
Adam and the methods that build their direction from a pair of bias-corrected moment averages as it does. What the union selects for is that shared character and not a shared implementation: the direction is a moving average that is deliberately allowed not to descend on an individual step, which is what default_linesearch's fixed Static and the ensure_descent! exemption in FirstOrderMethodWithState are about.
The implementation is shared by only some of them, so do not read the union as a promise about the cache:
AdamWithEuclideanDecaydiffers only in how the direction is finished off, so it reusesAdamCacheandAdamStateoutright andOptimizerState(AdamWithEuclideanDecay(), x)returns anAdamState.ScalarMomentAdamhas neither, because its second moment is a number rather than an element of𝔤ʰᵒʳand its recursion is therefore notAdam's. It carriesScalarMomentAdamCacheandScalarMomentAdamStateof its own.DirectScalarMomentAdamandFactoredStiefelAdamstep in the tangent space of aStiefelManifoldand not in𝔤ʰᵒʳ, and carry caches and states of their own.
GeometricOptimizers.DirectStiefelMethod — Type
The three methods that step a StiefelManifold in its tangent space, with cayley_direct! and a vector transport: DirectMomentum, DirectScalarMomentAdam and FactoredStiefelAdam. Their caches, their states and the workspace a TrainingOptimizer builds for them hold $O(Mk + k^2)$ numbers.
GeometricOptimizers.FirstOrderMethod — Type
FirstOrderMethodThe methods that build their direction from the gradient alone: GradientMethod and the FirstOrderMethodWithState. These are the methods a TrainingOptimizer takes, alone or two of them in a CompositeMethod, and the methods whose update!(cache, state, gradient, method, x) takes the method rather than a SimpleSolvers.Hessian, except the members of GeometricOptimizers.DirectStiefelMethod, which have no update!.
GeometricOptimizers.FirstOrderMethodWithState — Type
The methods whose update! needs the method rather than a SimpleSolvers.Hessian, because they carry state of their own out of which the direction is built — a momentum or a pair of moments. The (quasi-)Newton methods are the complement: their direction comes from the Hessian and the method object holds nothing.
GradientMethod has no Hessian and no state; with these methods it forms the FirstOrderMethods, whose update! takes the method. The three members of GeometricOptimizers.DirectStiefelMethod have no update!: the training step of TrainingOptimizer builds their direction from the method, the cache and the state.
ensure_descent! has a no-op method for these. It must not apply to them: a momentum and a moment average are deliberately allowed not to descend on an individual step, and the decay of AdamWithEuclideanDecay tilts the direction further away from the gradient still.
That exemption is about the direction before the search, and not about the restart after it — see linesearch_rejected. Declining to overrule the direction is not the same as taking the longest step along it, which is what a rejected search hands back.
GeometricOptimizers.Adam — Type
Adam(; β₁, β₂, δ)The Adam optimizer, with the defaults of the experiments in [15]. [34] and [35, Algorithm 8.7] suggest $\beta_2 = 0.999$. The moments below are taken of the gradient $\nabla{}L$ of GradientMethod.
The cache consists of a first and a second moment, stored in bias-corrected form, i.e. updated in the $t$-th iteration (counted from $t = 1$) as
\[m_1 \gets \frac{\beta_1 - \beta_1^t}{1 - \beta_1^t}m_1 + \frac{1 - \beta_1}{1 - \beta_1^t}\nabla{}L,\]
\[m_2 \gets \frac{\beta_2 - \beta_2^t}{1 - \beta_2^t}m_2 + \frac{1 - \beta_2}{1 - \beta_2^t}\nabla{}L\odot\nabla{}L,\]
from which the direction is computed as $-m_1/(\sqrt{m_2} + \delta)$.
The coefficients carry no element type of the parameters: Optimizer and TrainingOptimizer convert them once, with change_precision, to the element type of the parameters they are given. Adam() optimizes Float32 and Float64 parameters alike.
Because the direction has magnitude $\approx{}1$ per component whatever the gradient is, a step that does not shrink leaves Adam circling the minimiser at that distance rather than settling on it. A searching line search does not fix that — it picks each step from the merit and has no reason to drive the sequence to zero — it only sets the length of each step: on the two-sphere problem of test/integration/manifold_linesearch_tests.jl the searching options need 251–331 iterations where GradientMethod and MomentumMethod need 9–64. DecayingStatic is the setting under which Adam terminates on a criterion by construction, because its schedule drives the step to zero itself.
Adam only produces a direction, of magnitude $\approx{}1$ per component; the learning rate $\eta$ is the line search's α, i.e. it is passed as linesearch = η or linesearch = Static(η), and default_linesearch is the default. β₁, β₂ and δ are keyword arguments, so that a positional Adam(1e-3) meant as a learning rate fails instead of setting β₁.
The moments are taken of the lift in $\mathfrak{g}^\mathrm{hor}$, and the section $\lambda(Y)$ that defines the lift is unique only up to $\lambda\mapsto\lambda{}h$ with $h$ in the isotropy group, under which the lift goes to $h^{-1}Bh$. $m_1$ transforms the same way, but the entrywise $\nabla{}L\odot\nabla{}L$, $\sqrt{m_2}$ and the division do not, so the direction and the path depend on the section. This holds on every manifold of this package, where those of GradientMethod and MomentumMethod at a fixed step size do not. Only an $h$ that permutes coordinates and flips their signs leaves Adam alone, which is all a Stiefel point with at most one complementary column ($N - n \leq 1$) admits; a full-width point of the SymplecticStiefelManifold ($n = N$) has an empty completion and a trivial isotropy group. On a Grassmann point the isotropy group also rotates the representative, $Y\mapsto{}YQ$, and for $n \geq 2$ that moves Adam for $N - n = 1$ too; for $n = 1$ the rotation is a sign (scripts/adam_section_exceptions.jl). On a StiefelManifold and a GrassmannManifold, global_section draws the completion at random from the global RNG, so for $N - n \geq 2$ the iterates of Adam depend on that draw (A5 in KNOWN_ISSUES.md). On a SymplecticStiefelManifold below full width, global_section is deterministic, but the iterates of Adam still depend on the completion it chooses and on the transported section (K57). Euclidean parameters are not affected. Which section Adam should take is open; Weights on Manifolds has the measurement on the Stiefel manifold.
GeometricOptimizers.AdamWithEuclideanDecay — Type
AdamWithEuclideanDecay(; β₁, β₂, δ, λ)Adam with the decoupled weight decay of [38], which is the Euclidean $\lambda{}x$ and therefore acts on the unconstrained weights only.
The moments are the ones of Adam — this method shares its cache and its state — and the decay is applied to the direction instead of to the gradient, i.e. the direction is
\[-\left(\frac{m_1}{\sqrt{m_2} + \delta} + \lambda{}x\right)\]
so that a step with learning rate $\eta$ (see below) is
\[x \gets x - \eta\frac{m_1}{\sqrt{m_2} + \delta} - \eta\lambda{}x.\]
That is what decoupled means: $\lambda{}x$ never enters $m_1$ or $m_2$, so the amount by which a weight is shrunk does not depend on the size of its gradient. Adding $\lambda{}x$ to the gradient instead — $L^2$ regularization, which is what plain Adam on a penalized objective does — is not the same thing, because the second moment then rescales the penalty away.
Why the name says Euclidean
$\lambda{}x$ is the gradient of $\frac{\lambda}{2}||x||^2$, which is constant on the StiefelManifold and the GrassmannManifold — both are compact, with $||Y||_F^2 = \mathrm{tr}(Y^TY) = n$ — so its Riemannian gradient $\mathtt{rgrad}(Y, \lambda{}Y)$ vanishes identically and the decay does nothing at all to a manifold weight. The method therefore decays the ordinary arrays of a NamedTuple of parameters and leaves the Manifolds in it alone — which is the case it exists for, a network that keeps Stiefel weights next to unconstrained ones — and on a bare Manifold it is Adam, for every $\lambda$. Passing a nonzero λ together with parameters that are entirely manifolds is therefore warned about rather than silently ignored.
The derivation and the Grassmann case are in the Weight Decay on Manifolds page. Whether a Riemannian decay is called for is an open question.
Arguments
As for Adam, the coefficients carry no element type of the parameters, and the learning rate $\eta$ is not stored here: it is the α of the line search, i.e. linesearch = η, and default_linesearch is the default. λ is hence multiplied by $\eta$, exactly as in [38], where the two are decoupled from each other but the decay is still scaled by the schedule.
The merit the line search minimizes is the bare objective $f$ and not $f + \frac{\lambda}{2}||x||^2$: the penalty is never assembled anywhere, which is what decoupled means. So the search picks its $\alpha$ to undo the decay's contribution to $f$ as far as it can. The decay per step is $\alpha\lambda$, so an $\alpha$ that varies from step to step makes the effective regularization strength whatever the search picked on that step. This holds in addition to what the docstring of Adam says about searching along its direction.
A fixed Static(η) — the default — is the setting in which $\lambda$ means what [38] says it means. DecayingStatic is also well defined and is the analogue of AdamW's schedule: it shrinks the decay along with the step, so $\lambda$ keeps its interpretation relative to $\eta$ while both go to zero.
GeometricOptimizers.BFGS — Type
BFGSThe Broyden–Fletcher–Goldfarb–Shanno method, from [37], and the default algorithm of Optimizer. The direction is $-Q\nabla{}f(x)$ for an approximate inverse Hessian $Q$, updated from the secant pair $\delta = x^{(k)} - x^{(k-1)}$, $\gamma = \nabla{}f^{(k)} - \nabla{}f^{(k-1)}$ by
\[Q \gets Q - \frac{\delta\gamma^TQ + Q\gamma\delta^T - \left(1 + \frac{\gamma^TQ\gamma}{\delta^T\gamma}\right)\delta\delta^T}{\delta^T\gamma}\]
Its state is BFGSState and the update itself lives in QuasiNewtonCache, which skips the update when the secant pair fails curvature_is_usable — the condition that keeps $Q$ positive definite. restart!(::BFGSState) discards $Q$ when a line search reports that it could not decrease the merit.
Unlike Newton this builds its curvature up over the iterations rather than evaluating a Hessian, so it takes more of them; unlike DFP it produces a direction already scaled like a Newton step, and accepts $\alpha = 1$ on most of them. Both run on an AbstractVector, a NamedTuple of parameters and a bare Manifold alike: $Q$ is sized by the intrinsic dimension and the secant pair is taken in the horizontal lift, so nothing in the update needs a vector-valued point.
Takes no parameters: like every OptimizerMethod it only produces a direction, and how far the optimizer travels along it is the line search's business.
GeometricOptimizers.CompositeMethod — Type
CompositeMethod(; manifold, array)Two FirstOrderMethods for a parameter set whose leaves are not all of one kind: manifold steps every Manifold leaf, and array every other leaf.
ScalarMomentAdam is the case that needs it: it steps a single StiefelManifold, because a scalar second moment pooled across a set means nothing. So a network with Stiefel weights beside ordinary Matrix and Vector leaves has no single method that covers it:
CompositeMethod(; manifold = ScalarMomentAdam(), array = Adam())The split is by Manifold and not by StiefelManifold, so a GrassmannManifold leaf under ScalarMomentAdam is a MethodError when its cache is built. Any other method, or a composite, in either place is a MethodError at construction.
A composite is for TrainingOptimizer on a parameter set. Every leaf gets a cache and a state of its own method, in the element type of the set, and moves exactly as it would under a TrainingOptimizer of its own; nothing is pooled across leaves. The leaves share the step size of each step. A composite is not an OptimizerMethod, so Optimizer and solve!, whose line search finds one step length for the direction of the whole set, do not take it.
GeometricOptimizers.DFP — Type
DFPThe Davidon–Fletcher–Powell method, from [37]: the direction is $-Q\nabla{}f(x)$ for an approximate inverse Hessian $Q$, updated from the secant pair $\delta = x^{(k)} - x^{(k-1)}$, $\gamma = \nabla{}f^{(k)} - \nabla{}f^{(k-1)}$ by
\[Q \gets Q - \frac{Q\gamma\gamma^TQ}{\gamma^TQ\gamma} + \frac{\delta\delta^T}{\delta^T\gamma}\]
(equation 6.15 there). Its state is BFGSState, under the alias DFPState, and the update itself lives in QuasiNewtonCache, which symmetrizes $Q\gamma\gamma^TQ$ explicitly and skips the update when the secant pair fails curvature_is_usable.
BFGS is the default algorithm of Optimizer. DFP is here because it is the other classical member of the family and because the two differ in exactly the way that shows what the line search is doing: DFP's direction is systematically under-scaled, so it wants a median $\alpha$ well above 1 and is starved by a search that cannot exceed it. See default_linesearch: DFP converges under the default expanding Backtracking, and StrongWolfe(T; c₂ = 0.1) is the explicit choice for a DFP-heavy workload.
Takes no parameters: like every OptimizerMethod it only produces a direction, and how far the optimizer travels along it is the line search's business.
GeometricOptimizers.DirectMomentum — Type
DirectMomentum(; α = DEFAULT_MOMENTUM_α, metric = CanonicalMetric(), transport = ProjectionTransport())Riemannian gradient descent with momentum on a StiefelManifold, in the tangent space $T_Y\mathrm{St}(k, M)$ itself: no GlobalSection, no $M\times{}M$ matrix and no orthogonal complement of $Y$.
With $G_\mathcal{R} = \mathtt{rgrad}(Y, G, \mathtt{metric})$ for the Euclidean gradient $G$ and the step size $\eta$ of the line search, a step is
\[p \gets \alpha\,\mathcal{T}(p) + G_\mathcal{R}, \qquad \Delta = -\eta{}p, \qquad Y \gets \mathtt{cayley\_direct}(Y, \Delta),\]
where $\mathcal{T}$ is the vector transport transport (ProjectionTransport or DifferentiatedCayleyTransport) that carries the momentum of the previous step to the tangent space at $Y$. metric is CanonicalMetric or EuclideanMetric.
α satisfies $0 \le \alpha < 1$; another value is an ArgumentError. As for MomentumMethod, it carries no element type of the parameters, and the step size is not stored here: TrainingOptimizer converts α once, with change_precision, and takes $\eta$ as its linesearch. Only a single StiefelManifold is a leaf of this method, and only TrainingOptimizer steps it, with the retraction cayley_direct!.
The step has no cap. A finite gradient whose step has $\lVert\Delta\rVert_F$ above about $\sqrt{\mathrm{floatmax}(T)}$, $1.8\cdot10^{19}$ in Float32, makes the factorization of cayley_direct! overflow, and the step raises ArgumentError: matrix contains Infs or NaNs, as a step of MomentumMethod does. The momentum $p$ and the point are written only after the retraction, with the iteration number, so they stay as they were.
GeometricOptimizers.DirectScalarMomentAdam — Type
DirectScalarMomentAdam(; β₁ = 9.0e-1, β₂ = 9.9e-1, δ = 1.0e-8, α_max = 1.0, metric = CanonicalMetric(), transport = ProjectionTransport())Cayley ADAM of [16], with a scalar second moment, in the tangent space $T_Y\mathrm{St}(k, M)$ of a StiefelManifold itself. Where ScalarMomentAdam steps in $\mathfrak{g}^\mathrm{hor}$ through a GlobalSection, this method needs no $M\times{}M$ matrix and no orthogonal complement of $Y$.
With $G_\mathcal{R} = \mathtt{rgrad}(Y, G, \mathtt{metric})$, the step size $\alpha$ of the line search and the iteration $t$, the moments are stored in bias-corrected form, as Adam's are:
\[B_1 \gets \frac{\beta_1 - \beta_1^t}{1 - \beta_1^t}\mathcal{T}(B_1) + \frac{1 - \beta_1}{1 - \beta_1^t}G_\mathcal{R}, \qquad v \gets \frac{\beta_2 - \beta_2^t}{1 - \beta_2^t}v + \frac{1 - \beta_2}{1 - \beta_2^t}\lVert{}G_\mathcal{R}\rVert_F^2,\]
and the step is
\[D = \frac{B_1}{\sqrt{v} + \delta}, \qquad \Delta = -\min\Bigl(\alpha, \frac{\alpha_\mathrm{max}}{\lVert{}D\rVert_F + \delta}\Bigr)D, \qquad Y \gets \mathtt{cayley\_direct}(Y, \Delta).\]
$\mathcal{T}$ is the vector transport transport that carries $B_1$ from the previous point. The $\delta$ is outside the square root, as in Adam and FactoredStiefelAdam; ScalarMomentAdam puts it inside. The cap $\alpha_\mathrm{max}$ bounds the Frobenius norm of the step.
$0 \le \beta_1, \beta_2 < 1$, $\delta > 0$ and $\alpha_\mathrm{max} > 0$; another value is an ArgumentError, also where the conversion of a coefficient to the element type of the parameters takes it out of its range. The coefficients carry no element type of the parameters, and the learning rate is the linesearch of TrainingOptimizer, which is the only optimizer that steps this method. Only a single StiefelManifold is a leaf of it.
$\lVert{}D\rVert_F \approx 1$, so at the step size of Adam, whose direction has $\lVert{}D\rVert_F \approx \sqrt{Mk}$, a step is about $\sqrt{Mk}$ times shorter, as for ScalarMomentAdam. Scale the learning rate before comparing this method with Adam.
The second moment holds the squares of the gradient in the element type T of the parameters, so a gradient with $\lVert{}G_\mathcal{R}\rVert_F$ above about $\sqrt{\mathrm{floatmax}(T)}$, $1.8\cdot10^{19}$ in Float32, makes it infinite. For $\beta_2 > 0$ it stays infinite, so that step and every later step are zero.
GeometricOptimizers.FactoredStiefelAdam — Type
FactoredStiefelAdam(; β₁ = 9.0e-1, β₂ = 9.9e-1, δ = 1.0e-8, α_max = 1.0, metric = CanonicalMetric(), transport = ProjectionTransport())Adam on a StiefelManifold with one adaptive learning rate per mode, in the tangent space $T_Y\mathrm{St}(k, M)$ itself: no GlobalSection, no $M\times{}M$ matrix and no orthogonal complement of $Y$.
A tangent vector $X$ at $Y$ splits into a vertical part $P_V(Y)X = Y\cdot\tfrac{1}{2}(Y^TX - X^TY)$ and a horizontal part $P_H(Y)X = X - Y(Y^TX)$. The first moment $B_1$ is a tangent vector. The second moment is a $k\times{}k$ matrix $V_W$ for the vertical part, and a vector $v_K \in \mathbb{R}^k$ of the squared column norms of the horizontal part. With $G_\mathcal{R} = \mathtt{rgrad}(Y, G, \mathtt{metric})$, the step size $\alpha$ of the line search, the iteration $t$ and the weights $c_{i1} = (\beta_i - \beta_i^t)/(1 - \beta_i^t)$, $c_{i2} = (1 - \beta_i)/(1 - \beta_i^t)$ of the bias-corrected form of Adam, a step is
\[\begin{aligned} B_1 &\gets c_{11}\mathcal{T}_s(B_1) + c_{12}G_\mathcal{R}, & A &= \tfrac{1}{2}(Y^TG_\mathcal{R} - G_\mathcal{R}^TY), & K &= P_H(Y)G_\mathcal{R}, \\ V_W &\gets c_{21}V_W + c_{22}A\odot{}A, & (v_K)_j &\gets c_{21}(v_K)_j + c_{22}\lVert{}K_{:,j}\rVert_2^2, & \varepsilon &= \sqrt{\mathrm{eps}(T)} \Bigl(\textstyle\sum_{ij}(V_W)_{ij} + \sum_j(v_K)_j\Bigr)^{1/2}, \\ \tilde{A} &= \tfrac{1}{2}(Y^TB_1 - B_1^TY) \oslash (\sqrt{V_W} + \delta + \varepsilon), & \tilde{K}_{:,j} &= \frac{(P_H(Y)B_1)_{:,j}}{\sqrt{(v_K)_j} + \delta + \varepsilon}, \end{aligned}\]
\[D = Y\tilde{A} + \tilde{K}, \qquad \Delta = -\min\Bigl(\alpha, \frac{\alpha_\mathrm{max}}{\lVert{}D\rVert_F + \delta}\Bigr)D, \qquad Y \gets \mathtt{cayley\_direct}(Y, \Delta).\]
$\mathcal{T}_s$ carries $B_1$ from the previous point $Y_\mathrm{prev}$ with the vector transport $\mathcal{T}$ of transport, one part at a time, and puts each part back into its own subspace at $Y$:
\[\mathcal{T}_s(B_1) = P_V(Y)\mathcal{T}(P_V(Y_\mathrm{prev})B_1) + P_H(Y)\mathcal{T}(P_H(Y_\mathrm{prev})B_1).\]
$V_W$ is symmetric, so $\tilde{A}$ is skew-symmetric, and every column of $\tilde{K}$ is orthogonal to $Y$: $\Delta$ is a tangent vector with no projection after it. Each $P_H$ is two passes of $K \gets K - Y(Y^TK)$: one pass leaves a part of the order of $\mathrm{eps}(T)\lVert{}X\rVert$ along $Y$, and the scaling of a column with a small norm would make it large. A part of $B_1$ whose own second moment is zero holds only round-off; the floor $\varepsilon$, relative to both second moments and with $T$ the element type of the parameters, keeps it small, and the split transport keeps the one part out of the other. For $G = 0$, $\varepsilon = 0$. Every operation commutes with $Y \mapsto QY$, $G \mapsto QG$ for $Q \in O(M)$, so the iterates are left $O(M)$-equivariant.
The constraints on the coefficients, their element type and the learning rate are those of DirectScalarMomentAdam. Only a single StiefelManifold is a leaf of this method, and only TrainingOptimizer steps it.
Each off-diagonal entry of $\tilde{A}$ and each column of $\tilde{K}$ has a magnitude of about $1$, so $\lVert{}D\rVert_F \approx k$. At the step size of Adam, whose direction has $\lVert{}D\rVert_F \approx \sqrt{Mk}$, a step is about $\sqrt{M/k}$ times shorter.
The second moments hold the squares of the entries of $A$ and of the column norms of $K$ in T, so an entry of $A$ or a column norm of $K$ above about $\sqrt{\mathrm{floatmax}(T)}$, $1.8\cdot10^{19}$ in Float32, makes one of them infinite, and $\varepsilon$ and every denominator with it. For $\beta_2 > 0$ it stays infinite, so that step and every later step are zero. A gradient whose norm is above that limit while every entry of $A$ and every column norm of $K$ is below it does not stop the method: $\varepsilon$ is infinite at most while the sum of the second moments overflows.
GeometricOptimizers.GradientMethod — Type
GradientMethod()The gradient descent algorithm: the steepest descent with respect to the metric of the manifold. The gradient it holds is global_rep of the Riemannian gradient rgrad, whose tangent vector $\lambda(Y)BE$ is the same whatever section $\lambda(Y)$ is used.
MomentumMethod and Adam hold the same gradient, and BFGS and DFP start from its direction. On a SymplecticStiefelManifold it is the descent of the metric metric(::SymplecticStiefelManifold, ::AbstractMatrix, ::AbstractMatrix), and the path of GradientMethod does not depend on the section; see GeometricOptimizers.gradient_rep!. On a BiorthogonalManifold it is the descent of the metric the pairs inherit from $\mathbb{R}^{N\times2n}$, whose path does not depend on the section either.
GeometricOptimizers.MomentumMethod — Type
MomentumMethod(; α)The gradient descent algorithm with momentum, i.e. the heavy ball method. It holds the gradient of GradientMethod.
Stores the momentum coefficient α. The momentum is accumulated as
\[ p \gets \alpha{}p + \nabla{}L\]
and the direction is $-p$.
α carries no element type of the parameters: Optimizer and TrainingOptimizer convert it once, with change_precision, to the element type of the parameters they are given.
Like every OptimizerMethod, MomentumMethod only produces a direction; how far the optimizer goes along it is the line search's business. A fixed learning rate $\eta$ is therefore expressed as linesearch = η, or linesearch = Static(η).
GeometricOptimizers.Newton — Type
NewtonNewton's method: the direction solves $\nabla^2f(x)\delta = -\nabla{}f(x)$ with the exact Hessian, which SimpleSolvers.HessianAutodiff supplies.
Unlike BFGS and DFP this needs no approximation to build up, so it converges in few iterations, but it also inherits the Hessian's indefiniteness: where $\nabla^2f$ is not positive definite the direction ascends, and ensure_descent! substitutes the steepest-descent direction for it.
Runs on an AbstractVector and on nothing else. The exact Hessian is what makes it Newton's method: a bare Manifold has no Riemannian Hessian to build, and for a NeuralNetworkParameters.NetworkParameters the Hessian is not built over the flattening. Both are rejected at Optimizer and OptimizerState construction with a message saying so. BFGS and DFP take all three.
GeometricOptimizers.OptimizerMethod — Type
OptimizerMethod <: SolverMethodThe OptimizerMethod is used in Optimizer and determines the algorithm that is used.
GeometricOptimizers.ScalarMomentAdam — Type
ScalarMomentAdam(; β₁, β₂, δ, ambient_norm)Cayley ADAM, [16, Algorithm 2], as an experimental Stiefel-only baseline for Adam.
The moments are stored in bias-corrected form, as Adam's are, but the second one is a scalar:
\[m_1 \gets \frac{\beta_1 - \beta_1^t}{1 - \beta_1^t}m_1 + \frac{1 - \beta_1}{1 - \beta_1^t}\bar{G},\]
\[m_2 \gets \frac{\beta_2 - \beta_2^t}{1 - \beta_2^t}m_2 + \frac{1 - \beta_2}{1 - \beta_2^t}\lVert\bar{G}\rVert^2,\]
where $\bar{G}\in\mathfrak{g}^\mathrm{hor}$ is the gradient in the global tangent space representation, and the direction is $-m_1/\sqrt{m_2 + \delta}$.
That one scalar is the entire difference from Adam, and it is what the name says: $\lVert\bar{G}\rVert^2$ is a squared gradient norm where Adam's $m_2$ is a squared gradient, so the second moment carries no direction and the method assigns one adaptive learning rate to the whole matrix instead of one per coordinate. That is a reproduction of a published algorithm, and which of it and Adam reaches a lower loss depends on the objective, the step size and the number of steps.
Only a single StiefelManifold{T} solution is supported; ordinary arrays, NamedTuples, Grassmann solutions and mixed parameter trees throw a MethodError. As for Adam, the coefficients carry no element type of the parameters, and Optimizer converts them.
The source's lines 12–14 approximate the Cayley transform with two fixed-point iterations, and its line 11 caps the step length to keep that iteration contractive. Neither is ported: this package retracts exactly — Cayley, the default, evaluates the transform through the Sherman-Morrison-Woodbury formula — and it admits any other AbstractRetraction, Geodesic included. The step is bounded, but by step_αmax and for a different reason; step_ceiling = 1/2π recovers the source's bound up to its use of the induced 1-norm.
This is where the shared default learning rate stops meaning the same thing in both methods, and it matters for the comparison this one exists for. Adam's direction is $-m_1/(\sqrt{m_2}+\delta)$ componentwise, so every entry has magnitude $\approx{}1$ and $\lVert\delta\rVert \approx \sqrt{\dim}$. Here the divisor is one number chosen to normalize the whole lift, so $\lVert\delta\rVert \approx 1$ and each component is $\approx{}1/\sqrt{\dim}$.
Both methods take default_linesearch's Static(DEFAULT_LEARNING_RATE), so the same $\eta$ buys a step $\sqrt{\dim}$ times shorter here than it does for Adam. Scale $\eta$ accordingly before reading anything into a side-by-side run. It also means step_αmax's $2\pi{}c/\lVert\delta\rVert$ is $\approx 2\pi{}c$ and so essentially never binds on this method.
As for Adam, the source's learning rate $l$ is the line search's α, i.e. it is passed as linesearch = Static(η), which is also the default.
Arguments
β₁, β₂ and δ are the source's $\beta_1$, $\beta_2$ and $\varepsilon$, with $0 \le \beta_1, \beta_2 < 1$ and $\delta \ge 0$ validated. ambient_norm selects which $\lVert\cdot\rVert^2$ the second moment accumulates and defaults to false; see GeometricOptimizers._squared_gradient_norm, which is also where the reason the two choices are not interchangeable up to a constant is written down.
Extended help
The source's Algorithm 2, a table mapping each of its symbols onto the code, the derivation that makes its lines 8–10 be global_rep, and the two departures above with their reasons are on the Optimizer Methods page. The third departure is the momentum's transport: the source re-projects $M_k$ onto the tangent space at the new iterate (its equation (6)) where update_section! carries the lift here, which agrees for a Lie group and differs on a proper homogeneous space — the one departure that changes the iterates against the authors' implementation on the same objective and seed.
What is recorded only here is three discrepancies between the source and its own implementation, which are not departures of this port:
- $v_1$. Its line 2 initializes it to $1$,
stiefel_optimizer.pyto $0$ (v_buffer = torch.zeros([1])), and line 6's $1 - \beta_2^k$ is $0$ at the $k = 0$ its loop starts from. $0$ is followed, which is alsoAdam's convention here and which makes the first direction a normalized gradient step. - $\varepsilon$ inside or outside the root. Its line 7 and its implementation (
vnew_hat.add(epsilon).sqrt()) both put it inside;Adamhere puts it outside, $\sqrt{m_2}+\delta$. The source's placement is used, so this is the one conventionScalarMomentAdamdoes not share withAdam. - $s$, the number of fixed-point iterations. Its line 1 gives $s = 2$;
Cayley_loopingutils.pyrunsfor i in range(5). Neither number reaches this method, because the iteration they count is the approximation of the Cayley transform that the admonition above says is not ported —Cayleyis evaluated exactly. It is recorded because a reader comparing this port against the authors' code will meet it.
GeometricOptimizers.default_linesearch — Method
default_linesearch(T, method)Return the line search that Optimizer uses for method if none is supplied.
Everything except Adam defaults to SimpleSolvers.Backtracking(T; expand = true): the (quasi-)Newton methods because they build a direction with a scale of its own, and GradientMethod and MomentumMethod because a searching line search is what makes them converge rather than merely descend. All produce genuine descent directions, so a backtracking search always has an α to find.
expand = true is what lets that search lengthen a step as well as shorten it, and it is not the SimpleSolvers default — see the tip below for why it is the default here.
The AdamFamily methods are the exception and keep a fixed Static(DEFAULT_LEARNING_RATE). Adam's direction is $-m_1/(\sqrt{m_2} + \delta)$ and ScalarMomentAdam's is $-m_1/\sqrt{m_2 + \delta}$; either way it is a moving average that is deliberately not required to descend on any individual step, so a sufficient-decrease search has nothing to work with and would spend every such step reporting that it found no descent direction.
One caveat on sharing the value DEFAULT_LEARNING_RATE across the family: Adam normalizes componentwise and ScalarMomentAdam normalizes the whole lift at once, so the same $\eta$ is a step $\sqrt{\dim}$ shorter for the latter. See the warning in its docstring.
For AdamWithEuclideanDecay a fixed step is not merely the cheaper choice but the only one under which $\lambda$ means what it is documented to mean. Two reasons, and the first is the one that matters:
- The merit the line search minimizes is the bare objective $f$. It is not $f + \frac{\lambda}{2}||x||^2$, because this package regularizes by adding $-\lambda{}x$ to the direction rather than by penalizing the objective — that is what decoupled means. So the penalty is invisible to the search, which will spend its $\alpha$ undoing the decay's contribution to $f$ as far as it can. The search is not approximating a line minimum of the function the method is actually descending.
- The decay per step is $\alpha\lambda$, so a varying $\alpha$ makes the effective regularization strength whatever the search happened to pick on that step.
DecayingStatic is the exception to the exception: it varies $\alpha$ too, but on a schedule rather than in response to the merit, which is exactly AdamW's own learning-rate schedule and leaves $\lambda$ its meaning relative to $\eta$.
Pass linesearch = Static(η) for a fixed learning rate with any method.
Backtracking returns the first α that decreases f enough, while Bisection, SimpleSolvers.Quadratic and SimpleSolvers.BierlaireQuadratic bracket and then refine a line minimum, which costs an order of magnitude more merit evaluations per iteration. So compare them by objective evaluations, not by iterations.
A shrink-only backtracking search starts at α = 1 and can never exceed it. That is right for a direction already scaled like a Newton step, and wrong for one that is systematically under-scaled, such as the direction of DFP. expand = true lengthens an accepted first trial step while each longer trial satisfies sufficient decrease and improves the merit, for at most nexpand = 3 rounds of at most a factor q = 10 each. On a well-scaled problem it costs no evaluation, because the extrapolation reuses $\varphi(0)$, $\varphi'(0)$ and $\varphi(\alpha)$, which are known once the trial step is accepted.
Use a bracketing method when you pay for iterations rather than evaluations — a very expensive objective, or an outer loop bounded in iterations.
DFP converges under the default, but its direction stays under-scaled. StrongWolfe(T; c₂ = 0.1) is the choice to pass explicitly on a DFP-heavy workload: it takes fewer evaluations. Use c₂ = 0.1 and not the default 0.9 of StrongWolfe: at 0.9 the strong Wolfe conditions hold at α = 1 on nearly every iteration, so the bracketing phase does not start. 0.1 is the value that [37] recommends where a more accurate line search is necessary.
The manual page Linesearches on Manifolds gives the evaluation counts on the SVD problem.
GeometricOptimizers.default_step_size — Method
default_step_size(method)The fixed step size a TrainingOptimizer takes for method if its linesearch keyword is not given: 1e-2 for GradientMethod, MomentumMethod and DirectMomentum, and DEFAULT_LEARNING_RATE = 1e-3 for the AdamFamily, whose direction has a magnitude that does not depend on the gradient. That magnitude differs between the members: $\approx{}1$ per component for Adam, $\approx{}1$ in total for ScalarMomentAdam and DirectScalarMomentAdam, and $\approx{}1$ per off-diagonal entry of the vertical part and per column of the horizontal part for FactoredStiefelAdam, $\approx{}k$ in total on $\mathrm{St}(k, M)$. At the same step size, their steps on a StiefelManifold are therefore shorter than Adam's.
A CompositeMethod steps all of its leaves at one step size, so its default is the one its two methods agree on, and an ArgumentError asking for linesearch where they disagree.
GeometricOptimizers.GradientCache — Type
GradientCache <: OptimizerCacheCache for the gradient optimizer.
Fields
x::Manifold: the solution,g: the gradient (for the manifold case this is inAbstractLieAlgHorMatrixform),δ: the direction,Δg: difference in gradients,g̃: scratch forlatest_gradient,g̃_is_current: whetherg̃is the gradient atx; seestore_gradient!,g̃_norm: the Riemannian norm of the gradient atx; seelatest_gradient_norm,section: theGlobalSection.
Implementation
The line search evaluates $\varphi'(\alpha)$ into an array of the cache — that is what makes trial_slope allocation-free — and solver_step! refreshes the same array at the accepted iterate. Neither may land in g, because g is $\nabla{}f(x_k)$ at the iterate the direction was built from and the state updates read it afterwards: update!(::MomentumState, ...) accumulates it into the momentum, and with g shared that recursion would take the gradient at the last trial step of the search. MomentumCache and AdamCache carry the same field for the same reason.
GeometricOptimizers.GradientState — Type
GradientState <: OptimizerStateState for the gradient optimizer.
GeometricOptimizers.advance_state! — Method
advance_state!(state, cache, method)Carry state over to the step cache has just taken, without evaluating anything: the section becomes the cache's, and the method's own memory advances — the momentum $p \gets \alpha{}p + \nabla{}L$ of MomentumMethod, the moments of the AdamFamily.
This is the half of a state update that needs no objective, which is why it is the whole of the state update in optimization_step!. solve!'s update!(state, opt, x, f) calls it after it has recorded the iterate, its gradient and its objective value.
section(cache) is update_section!(section(state), direction, retraction) once the step is taken, so it is copied and not retracted a second time. On a manifold the retraction is $O(N^2n)$, and update_section! then transports the $N\times{}(N-n)$ block of the section by a product with an $(N-n)\times{}N$ block, which is $O(N^2(N-n))$, i.e. $O(N^3)$ for $n \ll N$, where the copy is $O(N^2)$.
GeometricOptimizers.MomentumCache — Type
MomentumCache <: OptimizerCacheCache for the gradient optimizer.
Fields
x::Manifold: the solution,g: the gradient (for the manifold case this is inAbstractLieAlgHorMatrixform),δ: the direction,Δg: difference in gradients (used inOptimizerStatus),g̃: scratch forlatest_gradient; seeGradientCachefor why it is separate fromg, and note that this is the cache the separation was measured on,g̃_is_current: whetherg̃is the gradient atx; seestore_gradient!,g̃_norm: the Riemannian norm of the gradient atx; seelatest_gradient_norm,section: theGlobalSection.
GeometricOptimizers.MomentumState — Type
MomentumState <: OptimizerStateState for the gradient optimizer.
GeometricOptimizers.AdamCache — Type
AdamCache <: OptimizerCacheCache for the gradient optimizer.
Fields
x::Manifold: the solution,g: the gradient (for the manifold case this is inAbstractLieAlgHorMatrixform),δ: the direction,Δg: difference in gradients, needed forOptimizerStatus,g̃: scratch forlatest_gradient; seeGradientCache,g̃_is_current: whetherg̃is the gradient atx; seestore_gradient!,g̃_norm: the Riemannian norm of the gradient atx; seelatest_gradient_norm,section: theGlobalSection.
GeometricOptimizers.AdamState — Type
AdamState <: OptimizerStateState for the gradient optimizer.
GeometricOptimizers.ScalarMomentAdamCache — Type
ScalarMomentAdamCache <: OptimizerCacheCache for ScalarMomentAdam.
The fields are AdamCache's, except that m₂ is a single number rather than an element of 𝔤ʰᵒʳ:
x::StiefelManifold: the solution,g: the gradient, inStiefelLieAlgHorMatrixform,δ: the direction,Δg: difference in gradients, needed forOptimizerStatus,g̃: scratch forlatest_gradient; seeGradientCache,g̃_is_current: whetherg̃is the gradient atx; seestore_gradient!,g̃_norm: the Riemannian norm of the gradient atx; seelatest_gradient_norm,m₁: the first moment, a horizontal lift, stored bias-corrected,m₂::T: the second moment, the scalar of [16], stored bias-corrected,m̃₂::T:√(m₂ + method.δ), the scalar the direction is divided by. Theδin it isScalarMomentAdam's regularizer and not theδfield above, which is the direction,section: theGlobalSection.
GeometricOptimizers.ScalarMomentAdamState — Type
ScalarMomentAdamState <: OptimizerStateState for ScalarMomentAdam.
As for ScalarMomentAdamCache, m₂ is a scalar and not a horizontal lift.
GeometricOptimizers._squared_gradient_norm — Method
_squared_gradient_norm(method::ScalarMomentAdam, cache, gradient, x)The ‖·‖² that ScalarMomentAdam's second moment accumulates, selected by method.ambient_norm.
false — the default — squares the horizontal lift already in the cache; true squares [16]'s own ambient Euclidean gradient, at one extra gradient evaluation per step. Gradient applied to a Manifold returns rgrad(Y, ∇L) and the ambient ∇L is not part of the optimizer protocol, so true recovers it by calling the gradient on the flat storage, as GradientAutodiff(F, ::Manifold) and the other Manifold gradients are built for — which is what gradient(vec(parent(x))) is. store_gradient!'s reuse does not help, because what it caches is the lift. A PrecomputedGradient holds its ambient gradient, so its norm is that of dp, at no extra evaluation.
The two are not interchangeable up to a constant, and which to reach for when is on the Optimizer Methods page.
GeometricOptimizers._is_decayable — Method
_is_decayable(x)Whether Euclidean weight decay can move x at all.
An ordinary array is decayable and a NamedTuple is decayable as soon as one of its entries is, which is the case AdamWithEuclideanDecay exists for. The StiefelManifold and the GrassmannManifold are not: $\lambda{}x$ is the gradient of $\frac{\lambda}{2}||x||^2$, which is constant on them, so the decay vanishes there identically (see the Weight Decay on Manifolds page). SymplecticStiefelManifold is non-compact — $\|U\|_F^2$ is unbounded on $Sp(2n, 2N)$ and $\mathrm{rgrad}(U, \lambda{}U)$ vanishes only at orthosymplectic points — while its direction is a horizontal lift that cannot subtract $\lambda{}U$ entrywise, so AdamWithEuclideanDecay refuses it with an ArgumentError. It refuses BiorthogonalManifold for the same two reasons: $\|[\Phi\ \ \Psi]\|_F^2$ is unbounded on it, and its direction is a lift in $\mathfrak{gl}(N)$.
Implementation
This is the only place that geometric fact is recorded — _weight_decay! consults it rather than restating it, so the no-op and the warning in OptimizerCache cannot drift apart.
It is declared on the concrete manifolds and not on Manifold on purpose. What makes the decay vanish on StiefelManifold and GrassmannManifold is that both are compact, with $||Y||_F^2 = \mathrm{tr}(Y^TY) = n$; it is not a consequence of being a manifold, as SymplecticStiefelManifold illustrates. A manifold added later therefore has to decide for itself, and gets an error saying so rather than inheriting a silent no-op that may be wrong for it.
GeometricOptimizers._weight_decay! — Method
_weight_decay!(δ, x, λ)Subtract the decoupled weight decay $\lambda{}x$ from the direction δ, in place.
This is called after the Adam direction has been formed, i.e. δ is $-m_1/(\sqrt{m_2} + \delta)$ on entry and $-m_1/(\sqrt{m_2} + \delta) - \lambda{}x$ on exit. It has to happen before the line search scales the direction, so that the decay is multiplied by the learning rate as [38] prescribes, and it must not touch the moments — that is the whole point of the decoupling, see AdamWithEuclideanDecay.
Implementation
The Manifold method is a genuine no-op and not an omission: δ is then an element of $\mathfrak{g}^\mathrm{hor}$ rather than something that could be added to x at all, and the quantity it would have to be corrected by — the Riemannian gradient of $\frac{\lambda}{2}||x||^2$ — is zero. It asserts _is_decayable rather than restating why, so that the no-op holds only for the manifolds on which that has been established. A Riemannian decay that does something here is an open question. test/manifold_optimizers/adam_with_euclidean_decay_optimizer.jl checks that rgrad(Y, λY) really does vanish rather than taking it on trust.
GeometricOptimizers.DirectMomentumState — Type
DirectMomentumState <: OptimizerStateThe state of DirectMomentum: the iteration number, the point x and the momentum p, a tangent vector at x.
GeometricOptimizers.DirectStiefelCache — Type
DirectStiefelCache <: OptimizerCacheThe cache of DirectMomentum and DirectScalarMomentAdam:
x::StiefelManifold: the point the step is taken from,g: the Riemannian gradient atx, anM × kmatrix,δ: the step $\Delta$, a tangent vector atx.
GeometricOptimizers.DirectScalarMomentAdamState — Type
DirectScalarMomentAdamState <: OptimizerStateThe state of DirectScalarMomentAdam: the iteration number, the point x, the first moment B₁, a tangent vector at x, and the scalar second moment v. Both moments are stored bias-corrected.
GeometricOptimizers.FactoredStiefelAdamCache — Type
FactoredStiefelAdamCache <: OptimizerCacheThe cache of FactoredStiefelAdam:
x::StiefelManifold: the point the step is taken from,g: the Riemannian gradient atx, anM × kmatrix,δ: the step $\Delta$, a tangent vector atx,SandA: a $k\times{}k$ product $Y^TX$, and the vertical part $Y^TG_\mathcal{R}$, a skew-symmetric $k\times{}k$ matrix, which the transport overwrites after the step,Ã: the scaled vertical part $\tilde{A}$, a skew-symmetric $k\times{}k$ matrix,K: the horizontal part $G_\mathcal{R} - Y(Y^TG_\mathcal{R})$, anM × kmatrix,n²andd: the squared column norms ofK, and the factors that scale the columns of the horizontal part of the first moment, two vectors of length $k$,A₁,V_Wandv_K: the vertical part of the first moment and the two second moments of the step being taken. The state takes them after the retraction.
GeometricOptimizers.FactoredStiefelAdamState — Type
FactoredStiefelAdamState <: OptimizerStateThe state of FactoredStiefelAdam: the iteration number, the point x, the first moment $B_1 = YA_1 + K_1$, a tangent vector at x, in its two parts, the vertical part A₁ = ½(YᵀB₁ - B₁ᵀY), a skew-symmetric $k\times{}k$ matrix, and the horizontal part K₁ = B₁ - Y(YᵀB₁), an M × k matrix, the vertical second moment V_W, a symmetric $k\times{}k$ matrix, and the horizontal second moment v_K, a vector of length $k$. The moments are stored bias-corrected.
GeometricOptimizers.NewtonOptimizerCache — Type
NewtonOptimizerCache <: OptimizerCacheKeys
x: current iterate (this stores the guess called by the functions generated withlinesearch_problem),Δx: direction of optimization step (difference betweenxandx̄); this is obtained by multiplyingrhswith the inverse of the Hessian,g: gradient value (this stores the gradient associated withx),g̃: scratch forlatest_gradient— the gradient at a line-search trial point, and at the accepted iterate oncesolver_step!has refreshed it; seeGradientCachefor why this is a field of its own and not an alias forg,g̃_is_current: whetherg̃is the gradient atx; seestore_gradient!,g̃_norm: the norm of the gradient atx; seelatest_gradient_norm,Δg: gradient difference (difference betweeng̃andg); this is used for computing theOptimizerStatus,rhs: the right hand side from which the update is computed,H: the Hessian matrix evaluated atx,
Also compare this to SimpleSolvers.NonlinearSolverCache.
GeometricBase.update! — Method
update!(cache::NewtonOptimizerCache, x, g, hes)Update an instance of NewtonOptimizerCache based on x.
This is used in update!(::OptimizerState, ::AbstractVector).
This sets:
\[\begin{aligned} % \bar{x}^\mathtt{cache} & \gets x, \\ x^\mathtt{cache} & \gets x, \\ g^\mathtt{cache} & \gets g, \\ \mathrm{rhs}^\mathtt{cache} & \gets -g, \\ H^\mathtt{cache} & \gets H(x), \\ \delta^\mathtt{cache} & \gets (H^\mathtt{cache})^{-1}\mathrm{rhs}^\mathtt{cache}, \end{aligned}\]
where we wrote $H$ for the Hessian (i.e. the input argument hes).
GeometricOptimizers.rhs — Method
rhs(cache)Return the right hand side of an instance of NewtonOptimizerCache
SimpleSolvers.direction — Method
direction(cache)Return the direction of the gradient step (i.e. Δx) of an instance of NewtonOptimizerCache.
GeometricOptimizers.NewtonState — Type
NewtonState <: OptimizerStateThe optimizer state is needed to update the Optimizer. This is different from OptimizerStatus and OptimizerResult which serve as diagnostic tools.
Keys
xx̄gḡff̄
The unbarred fields are the current iterate's and the barred ones the previous iterate's, as update! maintains them.
gradient and value read g and f and are exported. The other four accessors are internal: they are neither exported nor Base.ispublic, so they resolve only under a qualified name — GeometricOptimizers.solution for x, GeometricOptimizers.previous_solution for x̄, GeometricOptimizers.previous_gradient for ḡ and GeometricOptimizers.previous_value for f̄.
GeometricBase.update! — Method
update!(state::NewtonState, gradient, x)Update an instance of NewtonState based on x and gradient, where g is of type SimpleSolvers.Gradient.
Examples
If we only call update! once there are still NaNs for x̄, ḡ and f̄.
f(x) = sum(x.^2)
x = [1., 2.]
state = NewtonState(x)
grad = GradientAutodiff{Float64}(f, length(x))
update!(state, grad, x)
# output
NewtonState{Float64, Vector{Float64}, Vector{Float64}, GlobalSection{Float64, Vector{Float64}, Nothing}}(0, [1.0, 2.0], [NaN, NaN], [2.0, 4.0], [NaN, NaN], 5.0, NaN, GlobalSection{Float64, Vector{Float64}, Nothing}([1.0, 2.0], nothing))GeometricOptimizers._flat_mul! — Method
_flat_mul!(c, A, b, scratch)$c \gets Ab$ where A is in the flattened coordinates and c, b are in the parameters'.
The nothing method is mul!, for a solution that is already flat. The other flattens b into scratch, multiplies into scratch, and writes the result back through unflatten!, so that no flat vector and no ParameterLayout is allocated.
GeometricOptimizers._flat_scratch — Method
_flat_scratch(T, g)The flat buffers a quasi-Newton cache keeps, or nothing where it needs none.
$Q$ lives in the flattened coordinates — it is sized by the length of the flattening, it is where the outer products that build it are formed and where _dot pairs — while the secant pair, the right-hand side and the direction are handed around in the parameters' own representation: a NamedTuple, a container, or a horizontal lift of the ambient shape. These are the buffers that the crossing between the two writes into, through NeuralNetworkParameters' allocation-free flatten! and unflatten!, so that no update! allocates a fresh vector.
A NeuralNetworkParameters.FlatParameters rather than a bare Vector, because it carries its own ParameterLayout and keeps it through similar — so δ is built once and the other three buffers are one similar each, with no parameterlayout call written anywhere below this line. One is still made: δ is the flattening of g on its backend, whose first act is to build the layout. What the similars buy is that it happens once per cache rather than once per product with $Q$.
That layout then goes into the cache's own type, as FlatParameters' third type parameter and so as QuasiNewtonCache's FT. A LeafLayout{N} holds the shape alone, so the cache type does not carry the array types of the leaves, and the cache keeps no reference to the leaves.
The ambient and the intrinsic
This is where the distinction the quasi-Newton methods turn on is written down. $Q$ is sized by the intrinsic dimension of the parameters — the length of their flattening — while the direction and the gradient are handed around in the ambient representation. For a bare StiefelManifold of size $(3, 1)$ those are 2 and $3 \times 3$ respectively, so SimpleSolvers.outer!, which checks the axes of its arguments against those of its destination, would throw a DimensionMismatch. Flattening first is what makes BFGS and DFP run on a bare Manifold at all, and the buffers below hold the flat form once per cache rather than once per call.
Built from g, which callers pass as _zero(x) and not x, for the reason the flatlength(_zero(x)) beside it gives: on a manifold the flattening of the lift is the intrinsic dimension, 12 against 18 for a StiefelManifold(6, 3), and that is the length Q multiplies.
nothing for an AbstractVector solution. There the parameters are the flat coordinates, outer! and mul! reach their own methods on them, and nothing is allocated to begin with — so buffering would add a copy per iteration and buy nothing. _flat_mul! and the secant pair of QuasiNewtonCache's update! take the parameters unchanged in that case.
GeometricOptimizers.QuasiNewtonCache — Type
QuasiNewtonCacheThe OptimizerCache of BFGS and DFP. The two methods share every field and every step of update! but the update of the inverse Hessian, which _update_inverse_hessian! takes from method.
g̃ is the scratch for latest_gradient and g̃_is_current says whether it is the gradient at x; see GradientCache, which carries the same pair for the same reason, and store_gradient!. g̃_norm is the Riemannian norm of the gradient at x; see latest_gradient_norm.
T1, T2, T3, ΔxΔg and ΔxΔx are the $n \times n$ scratch of the update, where $n$ is the intrinsic dimension; DFP needs four of the five, and builds $\gamma\gamma^T$ in T3.
GeometricBase.update! — Method
update!(cache::QuasiNewtonCache, state, x, g)Update the QuasiNewtonCache and the inverse Hessian $Q$ of state based on x and g.
Extended help
Both methods form the secant pair
\[\delta \gets x^{(k)} - x^{(k-1)}, \qquad \gamma \gets \nabla{}f^{(k)} - \nabla{}f^{(k-1)},\]
and update $Q$ from it only where curvature_is_usable holds. The update rules can be found in [42] and [37]. BFGS does
\[\begin{aligned} T_1 & \gets \delta\gamma^TQ, \\ T_2 & \gets Q\gamma\delta^T, \\ T_3 & \gets (1 + \frac{\gamma^TQ\gamma}{\delta^T\gamma})\delta\delta^T,\\ Q & \gets Q - (T_1 + T_2 - T_3)/{\delta^T\gamma}, \end{aligned}\]
and DFP does $Q \gets Q - Q\gamma\gamma^TQ/(\gamma^TQ\gamma) + \delta\delta^T/(\delta^T\gamma)$ (nocedal2006numerical, eq. 6.15).
GeometricOptimizers.rhs — Method
rhs(cache)Return the right hand side of an instance of QuasiNewtonCache
SimpleSolvers.direction — Method
direction(cache)Return the direction of the gradient step (i.e. Δx) of an instance of QuasiNewtonCache.
GeometricOptimizers.BFGSState — Type
BFGSState <: OptimizerStateThe OptimizerState corresponding to the BFGS method.
Keys
x: the current iterate,x̄: the previous iterate,s: stores the previous direction. This needs to be stored in addition to the previous solution because of the manifold case.ḡ: the gradient the last step was built from,f: the objective atx,f̄: the objective atx̄,Q
The unbarred fields are the current iterate's and the barred ones the previous iterate's, as update! maintains them, and the accessors are the OptimizerState defaults: value reads f and is exported, GeometricOptimizers.solution, GeometricOptimizers.previous_solution and GeometricOptimizers.previous_value are internal.
GeometricOptimizers._metric_inverse! — Method
_metric_inverse!(Q, x, λY)Write into Q the inverse $M^{-1}$ of the Gram matrix of the metric in the flattened coordinates of the lifts at the section λY of x:
\[M_{ij} = g_x\big(\lambda(x)e_iE,\ \lambda(x)e_jE\big),\]
with $e_i$ the $i$-th flattened coordinate. This is where BFGS and DFP start $Q$, and where restart!(::BFGSState) puts it back.
The quasi-Newton methods hold the derivative with respect to the stored entries, GeometricOptimizers.gradient_rep!, because their secant pairs, their $Q$ and their descent test pair it with GeometricOptimizers._dot. That lift is $M$ times the lift global_rep of the Riemannian gradient, which GradientMethod holds. Starting from $Q = M^{-1}$ therefore makes the first direction, and every direction after a restart, $-M^{-1}\,\mathtt{gradient\_rep}(\Delta) = -\mathtt{global\_rep}(\Delta)$: the steepest descent of the metric, the same lift for every method, and independent of the section.
On the StiefelManifold, the GrassmannManifold and a vector space, GeometricOptimizers._dot is the metric, $M$ is the identity, and Q is set to it without forming $M$. On the SymplecticStiefelManifold and the BiorthogonalManifold the metric is not invariant under the group, $M$ depends on the point and the section, and it is built one column per coordinate, with GeometricOptimizers._metric_apply!, and inverted through its Cholesky factor: $O(d)$ lift products and $O(d^3)$ for the inverse, where $d$ is the length of the flattening, against the $O(d^2)$ of one update of $Q$. It is done at the start of a solve and at a restart, not at every step.
GeometricOptimizers.restart! — Method
restart!(state::BFGSState)Reset the inverse-Hessian approximation to the inverse $M^{-1}$ of the metric in the coordinates of the section, so that the next direction is the steepest-descent one; see GeometricOptimizers._metric_inverse!. On every parameter but a SymplecticStiefelManifold and a BiorthogonalManifold, $M$ is the identity.
This is the BFGSState method of restart!; DFPState is an alias for BFGSState, so it covers DFP as well. solver_step! calls it when a line search reports that it could not decrease the merit — see linesearch_rejected.
ensure_descent! already substitutes the steepest-descent direction for one step when $Q$ has stopped being positive definite, but it leaves $Q$ itself alone, so every subsequent direction comes from the same damaged approximation, and $\lambda_\mathrm{min}(Q)$ can stay negative for the rest of the solve. Discarding $Q$ is what recovers.
GeometricOptimizers.DFPState — Type
DFPStateThis is equivalent to BFGSState.