Manifolds API
The manifolds, the decompositions that put a matrix onto one, and their global sections.
GeometricOptimizers.Manifold — Type
Manifold <: AbstractMatrixA manifold in GeometricOptimizers is a subtype of AbstractMatrix. All manifolds are matrix manifolds and therefore stored as matrices. More details can be found in the docstrings for the StiefelManifold, the GrassmannManifold, the SymplecticStiefelManifold and the BiorthogonalManifold.
GeometricOptimizers.OrthonormalizationFailure — Type
OrthonormalizationFailure(attempts)Thrown by orthonormal_columns when attempts independent draws each break CholeskyQR2 down. At the rate measured in that function's docstring this is not bad luck, so what a caller changes in response is the element type and not the seed. The type is distinct so that catching it does not also catch an unrelated ErrorException.
Base.rand — Method
rand(backend, manifold_type, N, n)Draw random elements for a specific device.
Examples
Random elements of the manifold can be allocated on GPU. Call ...
rand(CUDABackend(), StiefelManifold{Float32}, N, n)... for drawing elements on a CUDA device.
The element type
Naming it, as above, is what fixes it, and a named element type is honoured or refused — never narrowed. rand(MetalBackend(), StiefelManifold{Float64}, N, n) throws Metal's own ErrorException at allocation, whose message names Float64, rather than quietly returning a Float32 point of a type the caller did not ask for.
A call that leaves the element type open — rand(CUDABackend(), StiefelManifold, N, n) — gets default_eltype of the backend: Float64 on the host and Float32 on a device, for the reasons given there.
What the backend has to supply
A matrix product, a cholesky and a triangular solve, all for an array of its own type. The draw orthonormalizes a Gaussian matrix with _cholesky_qr2 and global_section does the same for the complement, so those three are what a backend needs to carry a point, draw one and carry an Optimizer.
qr is deliberately not among them. Metal implements no qr for an MtlArray: a call there raises Cannot access the contents of a private buffer, measured on real hardware. Any path through qr is host-only on such a device, and that path carries GlobalSection(Y) and Optimizer(Y, F) with it. Metal does implement cholesky, so CholeskyQR2 runs where Householder QR cannot, at better orthogonality than the host QR at every size measured — and a CUDA backend, which does supply qr through CUSOLVER, takes the same route as everything else rather than a second one.
The manifolds this draws
StiefelManifold and GrassmannManifold. SymplecticStiefelManifold is drawn on the host alone: its draw is the symplectic SR decomposition sr!, which is a host factorization, so a device spelling would be a host draw followed by a transfer rather than the device-native draw the other two get. Naming a device for it throws an ArgumentError saying so. BiorthogonalManifold is drawn on every backend, through the products, the cholesky and the triangular solves the other two need.
Base.rand — Method
rand(manifold_type, N, n)Draw random elements from the Stiefel and the Grassmann manifold.
Because both of these manifolds are compact spaces we can sample them uniformly [40].
Examples
When we call ...
using GeometricOptimizers
using GeometricOptimizers: _round # hide
import Random
Random.seed!(123)
N, n = 5, 3
Y = rand(StiefelManifold{Float32}, N, n)
_round(Y; digits = 5) # hide
# output
5×3 StiefelManifold{Float32, Matrix{Float32}}:
-0.27575 0.32991 0.77275
-0.62485 -0.33224 -0.0686
-0.69333 0.36724 -0.18988
-0.09295 -0.73145 0.46064
0.2102 0.33301 0.38717... the sampling is done by first allocating a random matrix of size $N\times{}n$ via Y = randn(Float32, N, n).
We then orthonormalize its columns with _cholesky_qr2 and return those. CholeskyQR2 rather than LinearAlgebra.qr — which uses Householder reflections internally — because qr is a host factorization for several of the backends this package supports, and CholeskyQR2 is expressible in products, reductions and triangular solves alone. The two answers differ by the sign of each column, since CholeskyQR2's $R$ has a positive diagonal and Householder's need not.
GeometricOptimizers._cholesky_qr2 — Method
_cholesky_qr2(A)An $N\times{}m$ matrix whose columns are an orthonormal basis of the columns of the $N\times{}m$ matrix A, or nothing when A is too ill-conditioned for its element type.
CholeskyQR2: take $R$ from cholesky(AᵀA), set $Q = AR^{-1}$, and do it again. Every step is a matrix product, a reduction or a triangular solve, so the whole factorization runs wherever A already is. LinearAlgebra.qr! does not: Metal implements no qr for an MtlArray, and a qr on a JLArray cannot rebuild its Q. Measured on an M4 Max with scalar indexing disallowed, this runs on Metal and its $\|Q^TQ - \mathbb{I}\|$ is smaller than the host Householder QR's at every size tried.
The second pass is not a refinement. One pass leaves $\|Q^TQ - \mathbb{I}\|$ orders of magnitude above the round-off of the second, and the manifold tests assert check(Y) < 1e-14 in Float64.
On a device this keeps the point there; it is not the faster route. The manual page Global Tangent Spaces gives the measurements of both statements.
Forming $A^TA$ squares the condition number, which is what the nothing is for. cholesky with check = false reports a Gram matrix that is no longer positive definite rather than throwing, and at this shape in Float32 an ordinary Gaussian draw reaches that about once in a hundred and twenty — see scripts/orthonormalization_breakdown_rate.jl. orthonormal_columns is what answers it.
Squaring the entries is a second hazard, and the scaling below is what answers that one. A Householder QR scales internally and this does not, so an argument whose entries are large enough gives an infinite Gram matrix and no answer at all. It is reachable: optimizer_status_tests.jl builds a point $10^{100}$ off the manifold to test a convergence guard, the projection carries that magnitude into A, and $A^TA$ is then Inf in Float64. Dividing A by $\max_{ij}|A_{ij}|$ — a reduction that cannot overflow, unlike a column norm — leaves $Q$ unchanged, since $(A/s)^T(A/s) = A^TA/s^2$ has Cholesky factor $R/s$.
GeometricOptimizers.check — Method
check(Y::Manifold)Measure how far Y is from the manifold, as $\|Y^TY - \mathbb{I}\|$.
Two of the four manifolds this package provides store a representative whose columns are orthonormal — for StiefelManifold that is the point itself, for GrassmannManifold it is the representative of the equivalence class — so the same expression measures both. A retraction maps onto the manifold by construction, so in exact arithmetic this is zero and what it actually returns is accumulated round-off.
SymplecticStiefelManifold and BiorthogonalManifold are the other two, and their constraints are different bilinear forms, so each carries its own method. Anything defining a further manifold has to decide whether its stored matrix has orthonormal columns rather than inherit this method by default.
This is the assertion the manifold tests rest on, for every retraction path.
Examples
using GeometricOptimizers
using GeometricOptimizers: check
import Random
Random.seed!(123)
check(rand(GrassmannManifold, 5, 3)) < 1e-14
# output
trueGeometricOptimizers.default_eltype — Function
default_eltype(backend)The element type a zeros or a rand that names no element type allocates in: Float64 on the host and Float32 on a device.
Neither value is arbitrary, which is the whole reason this is a function rather than a literal in each allocator. Float64 on the host is what zeros(n) and rand(n) already give, so an owned array or manifold allocated without an element type matches every other array allocated without one. Float32 on a device is the width an accelerator is built for, and a device that carries Float64 at all normally carries it at a fraction of the Float32 rate.
The rule deliberately does not ask KernelAbstractions.supports_float64. A backend being able to hold a Float64 is not a reason to hand it one: a caller who has not said which width it wants is better served by the width the device is fast at. An element type the caller does name and the backend cannot hold is refused by the backend's own allocation rather than narrowed, which the rand(backend, manifold_type, N, n) docstring states.
A caller who wants a fixed width names it, in the parametric form rand(backend, StiefelManifold{Float64}, N, n).
GeometricOptimizers.manifold_constructor — Method
manifold_constructor(x::Manifold)The one-argument constructor of x's manifold: GrassmannManifold for a GrassmannManifold{Float32, Matrix{Float32}}.
The type name and not typeof(x), because the array the result is applied to may have a different element type from x's: the closure GradientAutodiff differentiates is handed a vector of ForwardDiff.Duals. And x's manifold rather than a hardcoded StiefelManifold, so that a bare GrassmannManifold reaches Optimizer too.
Its callers are GeometricOptimizers._similar(::Manifold), copyto!(::Manifold, ::Manifold) and the reconstruction that GradientAutodiff(F, ::Manifold) and GradientFiniteDifferences(F, ::Manifold) compose F with. The flattening does not call it: NeuralNetworkParameters.rebuild takes a prototype rather than a type, so a round trip keeps a GrassmannManifold a GrassmannManifold.
GeometricOptimizers.orthonormal_columns — Method
orthonormal_columns(draw)Orthonormalize draw() with _cholesky_qr2, drawing again while the draw is too ill-conditioned for it.
draw takes no argument and returns an $N\times{}m$ matrix whose entries are a fresh draw each time it is called. Only the entries have to be fresh: nothing here writes into the matrix, so a draw that fills one buffer in place and returns it every time is correct. The result has orthonormal columns and is on whatever backend draw allocated on, so this is the entry point for orthonormalizing on a device: LinearAlgebra.qr! is a host factorization, and Metal implements no qr for its arrays at all. Exhausting the attempts throws OrthonormalizationFailure.
draw is called again rather than its result repaired, so each call must produce new entries and not hand back the previous draw. This package's own callers — rand(backend, manifold_type, N, n) and global_section — each draw a Gaussian matrix, which carries no information, so one CholeskyQR2 cannot orthonormalize is replaced; nothing is repaired and no result is kept that the algorithm did not produce cleanly. A draw that ignores this and returns the same entries every time turns a breakdown into the error below instead of an answer.
The rate is not negligible. global_section factorizes $N\times(N-n)$ Gaussian columns with the span of Y projected out, so the matrix is square inside that complement and its condition number has the heavy tail a square Gaussian's does. Measured in Float32 over 9000 draws at $N = 50, 100, 200$ and $n = 3$, across three seeds: 77 break CholeskyQR2 down, a rate between one in 107 and one in 125. Each is replaced, and three of those 77 replacements fail as well — a higher rate than the draws themselves, which is why the attempt bound is not derived from one failure probability raised to the eighth power. The script is scripts/orthonormalization_breakdown_rate.jl.
A redraw costs the caller determinism, not just time. The number of Gaussian draws global_section consumes in Float32 depends on the draws themselves, so a seeded Float32 computation downstream of one is not reproducible across a change to this function or to the element type. The device sweep in scripts/device_products.jl seeds one, and relies only on the same code repeating its draws.
Shifted CholeskyQR3 measured on the same draws does not close it — one failure in 300 even with the exact $\|A\|_2$ in the shift, because forming $A^TA$ in Float32 loses a singular value that small whatever the shift is.
GeometricOptimizers.CanonicalMetric — Type
CanonicalMetric <: StiefelMetricThe canonical metric of the Stiefel manifold, $g_Y(\Delta_1, \Delta_2) = \mathrm{Tr}(\Delta_1^T(\mathbb{I} - \frac{1}{2}YY^T)\Delta_2)$. The two-argument form of rgrad and the three-argument form of metric use it.
GeometricOptimizers.EuclideanMetric — Type
EuclideanMetric <: StiefelMetricThe metric that the Stiefel manifold inherits from $\mathbb{R}^{N\times{}n}$, $g_Y(\Delta_1, \Delta_2) = \mathrm{Tr}(\Delta_1^T\Delta_2)$.
GeometricOptimizers.StiefelManifold — Type
StiefelManifold <: ManifoldAn implementation of the Stiefel manifold [17]. The Stiefel manifold is the collection of all matrices $Y\in\mathbb{R}^{N\times{}n}$ whose columns are orthonormal, i.e.
\[ St(n, N) = \{Y: Y^TY = \mathbb{I}_n \}.\]
The Stiefel manifold can be shown to have manifold structure (as the name suggests) and this is heavily used in GeometricOptimizers. It is further a compact space. More information can be found in the docstrings for rgrad(::StiefelManifold, ::AbstractMatrix) and metric(::StiefelManifold, ::AbstractMatrix, ::AbstractMatrix).
GeometricOptimizers.StiefelMetric — Type
StiefelMetricA Riemannian metric on the Stiefel manifold, passed as the last argument of rgrad and metric. The two metrics are CanonicalMetric and EuclideanMetric.
GeometricOptimizers.global_section — Method
global_section(Y::StiefelManifold)Compute a matrix of size $N\times(N-n)$ whose columns are orthogonal to the columns in Y.
This matrix is also called $Y_\perp$ [6, 10, 11].
Examples
using GeometricOptimizers
using GeometricOptimizers: global_section
import Random
Random.seed!(123)
Y = StiefelManifold([1. 0.; 0. 1.; 0. 0.; 0. 0.])
round.(global_section(Y); digits = 3)
# output
4×2 Matrix{Float64}:
0.0 0.0
0.0 0.0
-0.936 0.353
-0.353 -0.936Implementation
Internally we do:
λ = orthonormal_columns() do
A = randn(N, N - n) # or the gpu equivalent
A - Y.A * (Y.A' * A)
end
_cholesky_qr2(λ - Y.A * (Y.A' * λ))The projection and the orthonormalization are done twice. The first projection leaves a rounding error in the span of Y, and the orthonormalization multiplies it by the condition number of the projected draw, which has a heavy tail. Once only, the worst of a few thousand draws gives $\|Y^T\lambda\|$ of 3e-3 to 7e-2 in Float32, depending on the size. The first result is orthonormal, so the second orthonormalization amplifies nothing, and $\|Y^T\lambda\|$ stays at rounding level: measured over 20000 draws at $6\times3$ and 2000 at $50\times3$ and $200\times10$, at most 6.1e-7 in Float32 and 1.1e-15 in Float64, at twice the cost. Projecting twice before one orthonormalization does not do this, because the amplification comes after it.
The orthonormalization is CholeskyQR2 and not LinearAlgebra.qr!, on every backend — see _cholesky_qr2. qr! is a host factorization here: Metal implements no qr for its array type at all, so a qr! in this function puts GlobalSection(Y) and Optimizer(Y, F) out of reach on a device — and this function is on the path geodesic and cayley take on every step.
A is square inside the complement of Y, so its condition number has a square Gaussian's heavy tail and CholeskyQR2 breaks down on it about once in a hundred and twenty in Float32. A draw it cannot orthonormalize is replaced — see orthonormal_columns for the measurement and for why a redraw rather than a repair is the honest answer.
GeometricOptimizers.metric — Method
metric(Y::StiefelManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix, ::CanonicalMetric)
metric(Y::StiefelManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix, ::EuclideanMetric)The dot product of Δ₁ and Δ₂ at Y in the given metric: the canonical one of metric(::StiefelManifold, ::AbstractMatrix, ::AbstractMatrix), or $\mathrm{Tr}(\Delta_1^T\Delta_2)$. A Δ₁ or Δ₂ of another size than Y raises a DimensionMismatch.
GeometricOptimizers.metric — Method
metric(Y::StiefelManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix)Compute the dot product for Δ₁ and Δ₂ at Y.
This uses the canonical Riemannian metric for the Stiefel manifold:
\[g_Y: (\Delta_1, \Delta_2) \mapsto \mathrm{Tr}(\Delta_1^T(\mathbb{I} - \frac{1}{2}YY^T)\Delta_2).\]
GeometricOptimizers.rgrad — Method
rgrad(Y::StiefelManifold, ∇L::AbstractMatrix, ::CanonicalMetric)
rgrad(Y::StiefelManifold, ∇L::AbstractMatrix, ::EuclideanMetric)The Riemannian gradient at Y for the given metric, from the Euclidean gradient ∇L:
\[\nabla{}L - Y(\nabla{}L)^TY \quad\text{(canonical)}, \qquad \nabla{}L - \frac{1}{2}Y(Y^T\nabla{}L + (\nabla{}L)^TY) \quad\text{(Euclidean)}.\]
The Euclidean form is the orthogonal projection of ∇L onto the tangent space at Y. Both forms satisfy $\mathtt{metric}(Y, \mathtt{rgrad}(Y, \nabla{}L, m), \Delta, m) = \mathrm{Tr}((\nabla{}L)^T\Delta)$ for every tangent vector $\Delta$. A ∇L of another size than Y raises a DimensionMismatch.
GeometricOptimizers.rgrad — Method
rgrad(Y::StiefelManifold, ∇L::AbstractMatrix)Compute the Riemannian gradient for the Stiefel manifold at Y based on ∇L.
Here $Y\in{}St(N,n)$ and $\nabla{}L\in\mathbb{R}^{N\times{}n}$ is the Euclidean gradient.
The function computes the Riemannian gradient with respect to the canonical metric: metric(::StiefelManifold, ::AbstractMatrix, ::AbstractMatrix).
The precise form of the mapping is:
\[\mathtt{rgrad}(Y, \nabla{}L) \mapsto \nabla{}L - Y(\nabla{}L)^TY\]
Note the property $Y^T\mathtt{rgrad}(Y, \nabla{}L)\in\mathcal{S}_\mathrm{skew}(n).$
Examples
using GeometricOptimizers
Y = StiefelManifold([1 0 ; 0 1 ; 0 0; 0 0])
Δ = [1 2; 3 4; 5 6; 7 8]
rgrad(Y, Δ)
# output
4×2 Matrix{Int64}:
0 -1
1 0
5 6
7 8GeometricOptimizers.GrassmannManifold — Type
GrassmannManifold <: ManifoldThe GrassmannManifold is based on the StiefelManifold.
GeometricOptimizers.global_section — Method
global_section(Y::GrassmannManifold)Compute a matrix of size $N\times(N-n)$ whose columns are orthogonal to the columns in Y.
The method global_section for the Grassmann manifold is equivalent to that for the StiefelManifold (we represent the Grassmann manifold as an embedding in the Stiefel manifold).
See the documentation for global_section(Y::StiefelManifold{T}) where T.
GeometricOptimizers.metric — Method
metric(Y::GrassmannManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix)Compute the metric for vectors Δ₁ and Δ₂ at Y.
The representation of the Grassmann manifold is realized as a quotient space of the Stiefel manifold.
The metric for the Grassmann manifold is:
\[g^{Gr}_Y(\Delta_1, \Delta_2) = g^{St}_Y(\Delta_1, \Delta_2) = \mathrm{Tr}(\Delta_1^T (\mathbb{I} - Y Y^T) \Delta_2) = \mathrm{Tr}(\Delta_1^T \Delta_2),\]
where we used that $Y^T\Delta_i$ for $i = 1, 2.$
GeometricOptimizers.rgrad — Method
rgrad(Y::GrassmannManifold, ∇L::AbstractMatrix)Compute the Riemannian gradient for the Grassmann manifold at Y based on ∇L.
Here $Y$ is a representation of $\mathrm{span}(Y)\in{}Gr(n, N)$ and $\nabla{}L\in\mathbb{R}^{N\times{}n}$ is the Euclidean gradient.
This gradient has the property that it is orthogonal to the space spanned by $Y$.
The precise form of the mapping is:
\[\mathtt{rgrad}(Y, \nabla{}L) \mapsto \nabla{}L - YY^T\nabla{}L.\]
Note the property $Y^T\mathrm{rgrad}(Y, \nabla{}L) = \mathbb{O}.$
Also see rgrad(::StiefelManifold, ::AbstractMatrix).
Examples
using GeometricOptimizers
Y = GrassmannManifold([1 0 ; 0 1 ; 0 0; 0 0])
Δ = [1 2; 3 4; 5 6; 7 8]
rgrad(Y, Δ)
# output
4×2 Matrix{Int64}:
0 0
0 0
5 6
7 8GeometricOptimizers.SymplecticStiefelManifold — Type
SymplecticStiefelManifold(A)The symplectic Stiefel manifold, the set of $2N\times2n$ matrices whose columns span a symplectic subspace:
\[Sp(2n, 2N) = \{U \in \mathbb{R}^{2N\times2n} : U^T\mathbb{J}_{2N}U = \mathbb{J}_{2n}\},\]
with $\mathbb{J}$ the canonical Poisson tensor. Compare StiefelManifold, whose constraint is $Y^TY = \mathbb{I}$: the two agree in form and differ in which bilinear form the columns preserve.
The metric and the Riemannian gradient are (3.16) and (3.17) of [12]. The canonical-like metric of [18] is a different metric: it agrees with this one at the base point for $\rho = 2$, and for no $\rho$ at a general point. scripts/symplectic_metric_attribution.jl checks both statements. rand builds a point through the symplectic SR decomposition sr!, which is the construction [41] uses for its retraction.
The horizontal space depends on the metric here, in contrast to the Stiefel case. For the Stiefel manifold, [22] gives one horizontal space in its (2.21), with the blocks $A$ and $-B^T$, and the canonical metric is half the restriction of the metric of the orthogonal group to it, (2.22) and (2.39). [12] gives two. The space below (3.4) is the complement of the vertical space with respect to the pseudo-Riemannian metric $h$ of its (2.1), which is bi-invariant and not positive definite. The space in (3.13) is the complement with respect to the right-invariant Riemannian metric $g$ of its (2.2), under a condition that depends on $U$, and this is the horizontal space of the metric (3.16) that this type implements.
The optimizers step this type through the first of the two, the one subspace of the Lie algebra that is horizontal at every point: SymplecticLieAlgHorMatrix implements it, and global_rep maps a tangent vector into it. GradientMethod, MomentumMethod and Adam follow the Riemannian gradient of the metric (3.16); the line search, BFGS and DFP pair the derivative of the loss with respect to the stored entries of a lift, and the quasi-Newton methods start from the Riemannian gradient. GeometricOptimizers.gradient_rep! gives each of them. Every first-order and quasi-Newton method of Optimizer and TrainingOptimizer takes a point, and a parameter set with such a leaf, except AdamWithEuclideanDecay, whose weight decay is not defined here, and the methods that take a StiefelManifold by their signature.
A point is only as good as the decomposition it came from, and that decomposition has no re-orthogonalization step. The residual check reports has a median of 1.3e-14 at 6x4 in Float64 and 6.2e-8 at 40x20; in Float32 the median is already 0.014 at 20x10, and at 40x20 some draws return a non-finite residual or throw. Only the medians reproduce: the maxima move by orders of magnitude with the draw order, so no particular worst case is quoted here. Nothing warns when a draw comes back far from the manifold. CHANGELOG.md carries the full table and what closing it would take.
Examples
using GeometricOptimizers
using GeometricOptimizers: check
import Random
Random.seed!(1234)
check(rand(SymplecticStiefelManifold, 6, 4)) < 1e-5
# output
trueBase.rand — Method
rand(::Type{SymplecticStiefelManifold{T}}, N2, n2)Draw a random point of the $2N\times2n$ symplectic Stiefel manifold.
The draw is a Gaussian matrix put through the symplectic SR decomposition sr!; the point is n columns from each half of the symplectic factor. This is the symplectic counterpart of the orthonormalization rand(::Type{StiefelManifold}, …) does, and no orthonormalization will serve here: an orthonormal factor preserves the Euclidean form, not $\mathbb{J}$.
GeometricOptimizers.check — Method
check(U::SymplecticStiefelManifold)How far U is from the manifold, as $\|U^T\mathbb{J}_{2N}U - \mathbb{J}_{2n}\|$.
This replaces the generic check(::Manifold), whose residual is the orthonormality one.
GeometricOptimizers.global_section — Method
global_section(U::SymplecticStiefelManifold)A symplectic completion of U: $2N - 2n$ columns $U^s$ with $U^T\mathbb{J}_{2N}U^s = \mathbb{O}$ and $(U^s)^T\mathbb{J}_{2N}U^s = \mathbb{J}_{2N - 2n}$. The result is $2N\times(2N - 2n)$, as global_section(::StiefelManifold) is $N\times(N - n)$, and it is what GlobalSection expects: $[U\ \ U^s]$ is symplectic in the basis SymplecticLieAlgHorMatrix describes.
Implementation
The completion spans the symplectic complement $\{x : U^T\mathbb{J}_{2N}x = 0\}$ of U, which is the orthogonal complement of the range of $\mathbb{J}_{2N}^TU$. A full QR decomposition of that matrix gives an orthonormal basis $Q$ of it, and in this basis the Poisson tensor is the skew-symmetric $S = Q^T\mathbb{J}_{2N}Q$. The eigenvectors $v_j = a_j + ib_j$ of the Hermitian $iS$ for its $N - n$ positive eigenvalues $\sigma_j$ have $Sa_j = \sigma_jb_j$, and their real and imaginary parts are orthogonal to each other and of norm $1/\sqrt{2}$, so
\[U^s = Q\begin{bmatrix} \frac{\sqrt{2}b_1}{\sqrt{\sigma_1}} & \cdots & \frac{\sqrt{2}a_1}{\sqrt{\sigma_1}} & \cdots \end{bmatrix}\]
satisfies both conditions. This is the Schur-type normal form of a skew-symmetric matrix that [12] use to build a point from a projector on the symplectic Grassmann manifold. Its columns are orthogonal, with norms $1/\sqrt{\sigma_j}$, so the condition number of $U^s$ is $\sqrt{\sigma_\mathrm{max}/\sigma_\mathrm{min}}$, and $U^s$ is orthonormal where U is orthosymplectic. The optimizers transport the section from there, and its conditioning is what the coordinates of the lift, and so the steps of Adam and of the quasi-Newton methods, are measured in. On one $10\times{}4$ point, a completion drawn at random and made symplectic by sr! gave a section $[U\ \ U^s]$ with condition number $6.4\times10^3$, and gradient descent measured in it stalled far from the minimum.
This one is host-only, and the other three of this type's operations are not
rgrad, metric and check run wherever the point is, metric as far as the backend supplies an lu, since it forms $\mathrm{inv}(U^TU)$. This does not: it needs a full QR decomposition and the eigendecomposition of a Hermitian matrix, which a KernelAbstractions backend is under no obligation to supply, and the points it is applied to are drawn on the host anyway, because rand(::AbstractRNG, ::KernelAbstractions.Backend, ::Type{<:SymplecticStiefelManifold}, …) refuses a backend other than the host.
A device-backed point is therefore refused with an ArgumentError that says so.
GeometricOptimizers.metric — Method
metric(U::SymplecticStiefelManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix)The Riemannian metric of the symplectic Stiefel manifold, (3.16) of [12] with the factors of the trace in another order:
\[g_U(\Delta_1, \Delta_2) = \mathrm{tr}\left( P \Delta_1^T \left(\mathbb{I}_{2N} - \frac{1}{2}\mathbb{J}_{2N}^TUPU^T\mathbb{J}_{2N}\right)\Delta_2 \right), \qquad P = (U^TU)^{-1}.\]
Implementation
Every factor the trace needs is $2n\times{}2n$, and the expression is evaluated that way:
\[g_U(\Delta_1, \Delta_2) = \mathrm{tr}\left( P \left( \Delta_1^T\Delta_2 - \frac{1}{2} \left(\Delta_1^T\mathbb{J}_{2N}^TU\right) P \left(U^T\mathbb{J}_{2N}\Delta_2\right) \right) \right).\]
Written as the definition reads, the middle factor is a $2N\times{}2N$ matrix, and forming it costs $O(N^3)$ — a matrix of the ambient dimension to reach a number, on every step the optimizer takes. Grouped this way no product has two factors of the ambient dimension; the largest is $\mathbb{J}_{2N}^TU$, and it is formed once, because $U^T\mathbb{J}_{2N}$ is its adjoint. The $2N\times{}2N$ identity is not built at all, and $P$ is inverted once rather than twice. $\mathbb{J}_{2N}$ is still assembled dense by _poisson_tensor, and it is what a call allocates most of at the larger sizes. scripts/symplectic_metric_cost.jl carries the measurement.
GeometricOptimizers.rgrad — Method
rgrad(U::SymplecticStiefelManifold, ∇L::AbstractMatrix)The Riemannian gradient of a point of the symplectic Stiefel manifold, for the metric of metric(::SymplecticStiefelManifold, ::AbstractMatrix, ::AbstractMatrix). This is (3.17) of [12]:
\[\mathrm{grad}\,L(U) = \nabla{}L\,U^TU + \mathbb{J}_{2N}U(\nabla{}L)^T\mathbb{J}_{2N}U.\]
$\nabla{}L$ is the Euclidean gradient, i.e. the derivative of the loss with respect to the entries of U read as an unconstrained matrix.
The manifold is not compact, and the gradient grows with the point: like $\|U\|^3$ where $\nabla{}L$ grows like $\|U\|$, along a hyperbolic direction such as $U\,\mathrm{diag}(s\mathbb{I}, s^{-1}\mathbb{I})$. A fixed step size can therefore diverge from an ill-conditioned start; see Global Tangent Space for the Symplectic Stiefel Manifold.
GeometricOptimizers.BiorthogonalManifold — Type
BiorthogonalManifold(A)The manifold of biorthogonal pairs, stored as the $N\times2n$ matrix A $= [\Phi\ \ \Psi]$:
\[\mathcal{B}(n, N) = \{(\Phi, \Psi)\in\mathbb{R}^{N\times{}n}\times\mathbb{R}^{N\times{}n} : \Psi^T\Phi = \mathbb{I}_n\}.\]
Compare StiefelManifold, whose constraint is $Y^TY = \mathbb{I}_n$: the Stiefel manifold is the set of pairs with $\Phi = \Psi$. $\mathcal{B}(n, N)$ is the homogeneous space $GL(N)/GL(N - n)$ of the action $g\cdot(\Phi, \Psi) = (g\Phi, g^{-T}\Psi)$, of dimension $2Nn - n^2$; the manual page The Biorthogonal Manifold derives this. For $n = N$ it is $GL(N)$ itself, as the pairs $(g, g^{-T})$, which is what cayley and geodesic of a BiorthogonalLieAlgHorMatrix return.
A pair $(\Phi, \Psi)$ makes $\mathrm{diag}(\Phi, \Psi)$ a point of the SymplecticStiefelManifold of $2N\times2n$ matrices. Biorthogonal weights of this kind are used in [7, 8].
The metric is the one the pairs inherit from $\mathbb{R}^{N\times{}2n}$, see metric(::BiorthogonalManifold, ::AbstractMatrix, ::AbstractMatrix), and the optimizers step a point through the global tangent space BiorthogonalLieAlgHorMatrix.
rand(BiorthogonalManifold, N, 2n) draws a point, with the size of the stored matrix as for every other manifold here. The manifold is not compact, so there is no uniform distribution, and the draw is the one rand(::Type{<:BiorthogonalManifold}, ::Integer, ::Integer) describes.
Examples
using GeometricOptimizers
using GeometricOptimizers: check
import Random
Random.seed!(1234)
Y = rand(BiorthogonalManifold, 6, 4)
Φ, Ψ = Y[:, 1:2], Y[:, 3:4]
(check(Y) < 1e-12, Ψ' * Φ ≈ [1 0; 0 1])
# output
(true, true)Base.rand — Method
rand(::Type{BiorthogonalManifold{T}}, N, n2)Draw a point of the manifold of biorthogonal pairs $(\Phi, \Psi)$ with $N$ rows and $n = n_2/2$ columns each.
$\Phi$ and $W$ are Gaussian, and
\[\Psi = \Phi(\Phi^T\Phi)^{-1} + (\mathbb{I} - \Phi(\Phi^T\Phi)^{-1}\Phi^T)W,\]
the point of the fiber over $\Phi$ that $W$ selects; $\Psi^T\Phi = \mathbb{I}_n$ for every $W$. $(\Phi^T\Phi)^{-1}$ is applied through a Cholesky factor, so the draw takes the products, the cholesky and the triangular solves that rand of a StiefelManifold takes, and runs on the same backends.
GeometricOptimizers.check — Method
check(Y::BiorthogonalManifold)How far Y is from the manifold, as $\|\Psi^T\Phi - \mathbb{I}_n\|$.
This replaces the generic check(::Manifold), whose residual is the orthonormality one.
GeometricOptimizers.global_section — Method
global_section(Y::BiorthogonalManifold)The completion of a biorthogonal pair to an element of the general linear group and its dual: the $N\times2(N - n)$ matrix $[K\ \ \tilde{K}]$ with
\[\lambda(Y) = [\Phi\ \ K] \in GL(N), \qquad \lambda(Y)^{-T} = [\Psi\ \ \tilde{K}],\]
so that $\lambda(Y)\cdot(E, E) = (\Phi, \Psi)$ for the action $g\cdot(\Phi, \Psi) = (g\Phi, g^{-T}\Psi)$ and $E$ the first $n$ columns of the identity. $K$ is an orthonormal basis of the kernel of $\Psi^T$, which makes $[\Phi\ \ K]$ invertible (the manual page The Biorthogonal Manifold shows this), and $\tilde{K} = (\mathbb{I} - \Psi\Phi^T)K$. Then $\tilde{K}^T\Phi = \mathbb{O}$ and $\tilde{K}^TK = \mathbb{I}_{N-n}$, which is $\lambda(Y)^{-1}\lambda(Y) = \mathbb{I}_N$.
A GlobalSection stores the dual frame next to the frame because the group does not act by orthogonal matrices here: $\lambda(Y)^{-1}$ is not $\lambda(Y)^T$, and the optimizers transport both, as update_section! describes. At a point $\Phi = \Psi$ of the StiefelManifold, $\tilde{K} = K$ and the section is the one global_section(::StiefelManifold) draws.
$K$ is drawn as that function draws it, from the orthonormal basis of the span of $\Psi$ that _cholesky_qr2 gives, so it runs on the same backends. CholeskyQR2 squares the condition number of $\Psi$, and a valid pair can have a $\Psi$ whose squared condition number exceeds the precision of its element type. For such a $\Psi$ the basis comes from a Householder QR instead, which is a host factorization.
GeometricOptimizers.metric — Method
metric(Y::BiorthogonalManifold, Δ₁::AbstractMatrix, Δ₂::AbstractMatrix)The metric the manifold of biorthogonal pairs inherits from $\mathbb{R}^{N\times{}2n}$:
\[g_{(\Phi, \Psi)}(\Delta_1, \Delta_2) = \mathrm{tr}(\Delta_{1,\Phi}^T\Delta_{2,\Phi}) + \mathrm{tr}(\Delta_{1,\Psi}^T\Delta_{2,\Psi}),\]
with $\Delta = [\Delta_\Phi\ \ \Delta_\Psi]$ stored as the point is.
The general linear group does not act by isometries. For $n < N$ no metric on $\mathcal{B}(n, N)$ is invariant under it: at the point $(E, E)$, with $E$ the first $n$ columns of the identity, the isotropy group $GL(N - n)$ contains $\mathrm{diag}(\mathbb{I}_n, t\mathbb{I}_{N-n})$, which multiplies a tangent vector $(\Delta_\Phi, \mathbb{O})$ with $E^T\Delta_\Phi = \mathbb{O}$ by $t$. For $n = N$ the manifold is $GL(N)$ and the left-invariant metrics are invariant. This one is the simplest; at the StiefelManifold it restricts to twice the Euclidean metric of the Stiefel manifold, because a pair $(\Delta, \Delta)$ counts $\Delta$ twice.
GeometricOptimizers.rgrad — Method
rgrad(Y::BiorthogonalManifold, ∇L::AbstractMatrix)The Riemannian gradient of the metric metric(::BiorthogonalManifold, ::AbstractMatrix, ::AbstractMatrix), i.e. the orthogonal projection of the Euclidean gradient $\nabla{}L = [\nabla_\Phi L\ \ \nabla_\Psi L]$ onto the tangent space
\[T_{(\Phi, \Psi)}\mathcal{B}(n, N) = \{(\Delta_\Phi, \Delta_\Psi) : \Psi^T\Delta_\Phi + \Delta_\Psi^T\Phi = \mathbb{O}\}.\]
The normal space is $\{(\Psi M, \Phi M^T) : M\in\mathbb{R}^{n\times{}n}\}$, the image of the adjoint of the differential of $(\Phi, \Psi)\mapsto\Psi^T\Phi$, so
\[\mathrm{grad}\,L = (\nabla_\Phi L - \Psi M,\ \nabla_\Psi L - \Phi M^T), \qquad \Psi^T\Psi M + M\Phi^T\Phi = \Psi^T\nabla_\Phi L + (\nabla_\Psi L)^T\Phi .\]
Implementation
The Sylvester equation for $M$ is $n\times{}n$ and its two coefficients are symmetric positive definite. It is solved in the eigenbases of $\Psi^T\Psi = V_1\Lambda_1V_1^T$ and $\Phi^T\Phi = V_2\Lambda_2V_2^T$, where it is diagonal: $M = V_1\left[(V_1^TRV_2)_{ij}/(\lambda_{1,i} + \lambda_{2,j})\right]V_2^T$. Its three coefficients are $n\times{}n$, so it is solved on the host and $M$ is copied back to the storage of the gradient. rgrad therefore runs on every backend that supplies the matrix products.
GeometricOptimizers.Rfac — Type
Rfac(Λ::SymplecticHouseholderDecom)The $R$ factor of a symplectic SR decomposition, as an operator.
$R$ is upper triangular in the symplectic sense: in the $2N\times2M$ block form
\[R = \begin{pmatrix} R_{11} & R_{12} \\ R_{21} & R_{22} \end{pmatrix},\]
$R_{11}$ and $R_{22}$ are upper triangular and $R_{21}$ is strictly upper triangular. The entries come from the packed Λ; nothing is stored twice.
GeometricOptimizers.SR — Type
SR(S::Sfac, R::Rfac)The result of sr!: the two factors of $A = SR$, reached as F.S and F.R.
GeometricOptimizers.Sfac — Type
Sfac(Λ::SymplecticHouseholderDecom, inverse::Bool = false)The symplectic factor $S$ of a symplectic SR decomposition, as an operator.
S is never formed: multiplying by it applies the reflectors Λ stores, in $O(N^2)$ per vector. inv(S) is the same object with the reflectors applied in the opposite order, which is why the inverse costs what the forward application costs.
Indexing one entry builds the whole matrix and throws the rest away, because a reflector product has no cheap entrywise form. Use Matrix(S) when more than a few entries are wanted; that is what rand(SymplecticStiefelManifold, …) does before it slices.
GeometricOptimizers.SymplecticHouseholderDecom — Type
SymplecticHouseholderDecom(A, c₁, c₂, ρ, ν, μ)The packed form of a symplectic SR decomposition, as sr! computes it.
A holds the reflector vectors below the diagonal of each block, in place, exactly as LinearAlgebra's QRCompactWY holds its own. The five vectors are the scalars the reflectors were built with: c₁ and c₂ scale the two reflections of a step, and ρ, ν and μ are the diagonal entries the step produced in R.
This is the storage, not the factors. Sfac and Rfac read S and R off it.
GeometricOptimizers.apply_S_inverse_left! — Method
apply_S_inverse_left!(B, Λ::SymplecticHouseholderDecom)Overwrite B with $S^{-1}B$. Three things invert apply_S_left! together: the steps run from the first to the last rather than the last to the first, the two reflectors within a step are applied in the opposite order, and each update adds where the forward one subtracts.
GeometricOptimizers.apply_S_inverse_right! — Method
apply_S_inverse_right!(B, Λ::SymplecticHouseholderDecom)Overwrite B with $BS^{-1}$. Three things invert apply_S_right! together, for the reason given at apply_S_inverse_left!: the steps run from the last to the first, the two reflectors within a step are applied in the opposite order, and each factor is inverted, which for $I + cvv^J$ means negating $c$ because $v^Jv = 0$.
GeometricOptimizers.apply_S_left! — Method
apply_S_left!(B, Λ::SymplecticHouseholderDecom)Overwrite B with $SB$, applying the reflectors of Λ from the last step to the first.
GeometricOptimizers.apply_S_right! — Method
apply_S_right!(B, Λ::SymplecticHouseholderDecom)Overwrite B with $BS$. The reflections act on the rows of B, so this is written out rather than expressed through apply_S_left!.
GeometricOptimizers.sr! — Method
sr!(A)Compute the symplectic SR decomposition of A in place, and return it as an SR.
A is $2N\times2M$ with $N \geq M$, read as two stacked halves the way every symplectic object in this package is. A is overwritten with the packed reflectors.
$S$ is symplectic and therefore not orthogonal, its condition number is unbounded, and this implementation has no re-orthogonalization step. The median residual grows with the size by two to three orders of magnitude per doubling, and symplectic_householder! can raise a DomainError from a cancelled square root at large sizes in Float32. CHANGELOG.md has the measured table; read its medians, because the maxima do not reproduce across draw orders. Use it in Float64, at small sizes, and check the result.
Examples
using GeometricOptimizers
using LinearAlgebra
import Random
Random.seed!(1234)
F = sr!(randn(6, 4))
S = Matrix(F.S)
J = [zeros(3, 3) I(3); -I(3) zeros(3, 3)]
norm(S' * J * S - J) < 1e-5
# output
trueSee sr for the copying version.
GeometricOptimizers.sr — Method
sr(A)Compute the symplectic SR decomposition of A, leaving A alone. See sr!.
GeometricOptimizers.symplectic_form — Method
symplectic_form(a, b)The canonical symplectic form $a^TJb$ of two vectors of even length, evaluated without building $J$.
GeometricOptimizers.symplectic_householder! — Method
symplectic_householder!(a, b)Build one step of sr! in place, and return (c₁, c₂, ρ, ν, μ).
The step is a pair of symplectic reflections that together map the two columns a and b onto the shape $R$ needs. a and b are overwritten with the reflector vectors.
GeometricOptimizers.symplectic_householder — Method
symplectic_householder(a, b)symplectic_householder! on copies, returning the five scalars followed by the two reflector vectors.
GeometricOptimizers.symplectic_gram_schmidt — Function
symplectic_gram_schmidt(A, J, start = 1)symplectic_gram_schmidt! on a copy of A.
Examples
using GeometricOptimizers
using LinearAlgebra
import Random
Random.seed!(1234)
J₆ = [zeros(3, 3) I(3); -I(3) zeros(3, 3)]
J₄ = [zeros(2, 2) I(2); -I(2) zeros(2, 2)]
B = symplectic_gram_schmidt(randn(6, 4), J₆)
norm(B' * J₆ * B - J₄) < 1e-10
# output
trueGeometricOptimizers.symplectic_gram_schmidt! — Function
symplectic_gram_schmidt!(A, J, start = 1)Make the columns of A symplectic with respect to J, in place.
A is $2N\times2n$ and is read as two stacked halves: column i and column n + i are the pair that is normalized together. start skips the leading pairs, for the case where they are symplectic already.
GeometricOptimizers.symplectic_normalize — Method
symplectic_normalize(e, f, J)Scale a pair of vectors so that $e^TJf = 1$, including the sign: the factor sign(e^TJf) goes into e, so a pair whose form is negative comes back with the form +1 rather than -1.
The pair is the unit the symplectic Gram-Schmidt process works in: a single vector cannot be normalized against a form that vanishes on it.
Base.Matrix — Method
Matrix(λY::GlobalSection)Put λY into matrix form.
This is not recommended if speed is important!
Use apply_section and global_rep instead!
GeometricOptimizers.GlobalSection — Type
GlobalSection(Y)Construct a global section for Y.
A global section $\lambda$ is a mapping from a homogeneous space $\mathcal{M}$ to the corresponding Lie group $G$ such that
\[\lambda(Y)E = Y,\]
Also see apply_section and global_rep.
Implementation
For an implementation of GlobalSection for a custom array (especially manifolds), the function global_section has to be generalized.
GeometricOptimizers._metric_apply! — Method
_metric_apply!(D, λY, B)Write into D the lift $MB$, where $M$ is the Gram matrix of the metric in the stored entries of a lift at the section λY, so that
\[\langle{}MB, C\rangle = g\big(\lambda(Y)BE,\ \lambda(Y)CE\big) \quad \forall{}C\in\mathfrak{g}^\mathrm{hor},\]
with $\langle\cdot,\cdot\rangle$ the pairing of GeometricOptimizers._dot. On every lift but a SymplecticLieAlgHorMatrix and a BiorthogonalLieAlgHorMatrix that pairing is the metric and $M$ is the identity, as it is on a vector space. On a symplectic lift it is GeometricOptimizers.gradient_rep! of the tangent vector $\lambda(U)BE = U\mathcal{A} + U^s\mathcal{B}$, and on a biorthogonal lift gradient_rep! of the tangent vector $\lambda(Y)B\cdot(E, E) = (\Phi{}A + KB,\ -(\Psi{}A^T + \tilde{K}C^T))$, so $M$ takes the lift global_rep of a Riemannian gradient to the lift gradient_rep! of the same gradient. GeometricOptimizers._metric_inverse! builds $M$ from it.
GeometricOptimizers.apply_section! — Method
apply_section!(Y::AT, λY::GlobalSection{T, AT}, Y₂::AT) where {T, AT<:StiefelManifold{T}}Apply λY to Y₂ and store the result in Y.
This is the inplace version of apply_section.
GeometricOptimizers.apply_section — Method
apply_section(λY::GlobalSection{T, AT}, Y₂::AT) where {T, AT <: StiefelManifold{T}}Apply λY to Y₂.
Mathematically this is the group action of the element $\lambda{}Y\in{}G$ on the element $Y_2$ of the homogeneous space $\mathcal{M}$.
Internally it calls apply_section!.
GeometricOptimizers.global_rep — Method
global_rep(λY::GlobalSection{T, AT}, Δ::AbstractMatrix{T}) where {T, AT<:GrassmannManifold{T}}Express Δ (an element of the tangent space of Y) as an instance of GrassmannLieAlgHorMatrix.
The method global_rep for GrassmannManifold is similar to that for StiefelManifold.
Examples
using GeometricOptimizers
using GeometricOptimizers: _round
import Random
Random.seed!(123)
Y = rand(GrassmannManifold, 6, 3)
Δ = rgrad(Y, randn(6, 3))
λY = GlobalSection(Y)
_round(global_rep(λY, Δ); digits = 3)
# output
6×6 GrassmannLieAlgHorMatrix{Float64, Matrix{Float64}}:
0.0 0.0 0.0 0.981 2.058 -0.4
0.0 0.0 0.0 -0.424 -0.733 0.919
0.0 0.0 0.0 -1.815 -1.409 -1.085
-0.981 0.424 1.815 0.0 0.0 0.0
-2.058 0.733 1.409 0.0 0.0 0.0
0.4 -0.919 1.085 0.0 0.0 0.0GeometricOptimizers.global_rep — Method
global_rep(λY::GlobalSection{T, AT}, Δ::AbstractMatrix{T}) where {T, AT<:StiefelManifold{T}}Express Δ (an the tangent space of Y) as an instance of StiefelLieAlgHorMatrix.
This maps an element from $T_Y\mathcal{M}$ to an element of $\mathfrak{g}^\mathrm{hor}$.
These two spaces are isomorphic where the isomorphism where the isomorphism is established through $\lambda(Y)\in{}G$ via:
\[T_Y\mathcal{M} \to \mathfrak{g}^{\mathrm{hor}}, \Delta \mapsto \lambda(Y)^{-1}\Omega(Y, \Delta)\lambda(Y).\]
Also see GeometricOptimizers.Ω.
Examples
using GeometricOptimizers
using GeometricOptimizers: _round
import Random
Random.seed!(123)
Y = rand(StiefelManifold, 6, 3)
Δ = rgrad(Y, randn(6, 3))
λY = GlobalSection(Y)
_round(global_rep(λY, Δ); digits = 3)
# output
6×6 StiefelLieAlgHorMatrix{Float64, SkewSymMatrix{Float64, Vector{Float64}}, Matrix{Float64}}:
0.0 -0.525 1.786 0.981 2.058 -0.4
0.525 0.0 0.298 -0.424 -0.733 0.919
-1.786 -0.298 0.0 -1.815 -1.409 -1.085
-0.981 0.424 1.815 0.0 0.0 0.0
-2.058 0.733 1.409 0.0 0.0 0.0
0.4 -0.919 1.085 0.0 0.0 0.0Implementation
The function global_rep does in fact not perform the entire map $\lambda(Y)^{-1}\Omega(Y, \Delta)\lambda(Y)$ but only
\[\Delta \mapsto \mathrm{skew}(Y^T\Delta),\]
to get the small skew-symmetric matrix $A\in\mathcal{S}_\mathrm{skew}(n)$ and
\[\Delta \mapsto (\lambda(Y)_{[1:N, n:N]}^T \Delta)_{[1:(N-n), 1:n]},\]
to get the arbitrary matrix $B\in\mathbb{R}^{(N-n)\times{}n}$.
GeometricOptimizers.global_rep — Method
global_rep(λY::GlobalSection{T, AT}, Δ::AbstractMatrix{T}) where {T, AT<:SymplecticStiefelManifold{T}}Express Δ (an element of the tangent space of U) as an instance of SymplecticLieAlgHorMatrix.
This is the map $\Delta \mapsto \lambda(U)^{-1}\Omega(U, \Delta)\lambda(U)$, with $\Omega$ the horizontal lift GeometricOptimizers.Ω of the symplectic Stiefel manifold, as for the StiefelManifold. A horizontal element is determined by its first $2n$ columns, and those are $\lambda(U)^{-1}\Delta$, so the blocks are
\[\mathcal{A} = U^+\Delta, \qquad \mathcal{B} = (U^s)^+\Delta,\]
with $U^+ = \mathbb{J}_{2n}^TU^T\mathbb{J}_{2N}$ the symplectic inverse and $\lambda(U) = [U\ \ U^s]$. $\mathcal{A}$ is Hamiltonian for a tangent Δ; the Hamiltonian projection is taken all the same, as global_rep takes the skew-symmetric one for the Stiefel manifold.
Examples
using GeometricOptimizers
using GeometricOptimizers: apply_section, StiefelProjection
import Random
Random.seed!(123)
U = rand(SymplecticStiefelManifold, 6, 4)
Δ = rgrad(U, randn(6, 4))
λU = GlobalSection(U)
B = global_rep(λU, Δ)
λU.Y * (B * StiefelProjection(6, 4))[1:4, :] + λU.λ * (B * StiefelProjection(6, 4))[5:6, :] ≈ Δ
# output
trueGeometricOptimizers.gradient_rep! — Method
gradient_rep!(D, λY, Δ)
gradient_rep!(D, λY, Δ, method)Write into D the lift whose pairing with every lift $B$ under _dot is the derivative of the loss along $\lambda(Y)BE$, i.e. the derivative of the loss with respect to the stored entries of a lift at the section:
\[\langle D, B\rangle = \langle\nabla{}L, \lambda(Y)BE\rangle_F \quad \forall{}B\in\mathfrak{g}^\mathrm{hor}.\]
Δ is the Riemannian gradient rgrad, which is what a gradient of the optimizers returns. This lift is what makes trial_slope the derivative of the line search's merit and a descent check a statement about descent, and it is the gradient BFGS and DFP hold: their secant pairs and their $Q$ live in the same coordinates.
The four-argument form writes the gradient that method holds. For BFGS, DFP and every other method it is the lift above. For GradientMethod, MomentumMethod and Adam it is global_rep of Δ.
The biorthogonal manifold
The metric of BiorthogonalManifold is the Euclidean one, so Δ is the orthogonal projection of $\nabla{}L$ onto the tangent space and pairs with every tangent vector as $\nabla{}L$ does. The lift above is then global_rep's with the frame $[\Phi\ \ K]$ and the dual frame $[\Psi\ \ \tilde{K}]$ of the section exchanged: $A = \Phi^T\Delta_\Phi - \Delta_\Psi^T\Psi$, $B = K^T\Delta_\Phi$ and $C = -\Delta_\Psi^T\tilde{K}$; see Global Tangent Spaces.
The symplectic Stiefel manifold
For the StiefelManifold and the GrassmannManifold the lift above is global_rep(λY, Δ) itself, because the inner product of _dot on a lift is the canonical metric, and all of the forms above are the same. For the SymplecticStiefelManifold they are not: the metric metric(::SymplecticStiefelManifold, ::AbstractMatrix, ::AbstractMatrix) is not invariant under the symplectic group, so no inner product on the lift reproduces it at every point.
The method recovers $\langle\nabla{}L, \cdot\rangle_F = g_U(\Delta, \cdot)$ on the tangent space from Δ and the metric, which is
\[K = \Delta{}P - \frac{1}{2}\mathbb{J}_{2N}^TUP\,U^T\mathbb{J}_{2N}\Delta{}P, \qquad P = (U^TU)^{-1},\]
and writes the gradient of $B \mapsto \langle{}K, U\mathcal{A} + U^s\mathcal{B}\rangle_F$ with respect to the stored blocks of $B$. With $X = U^TK$ in four $n\times{}n$ blocks, that is $A_1 = X_{11} - X_{22}^T$, the storage gradients of $X_{12}$ and $X_{21}$ for the two SymmetricMatrix blocks, and $\mathcal{B} = (U^s)^TK = (U^s)^T\Delta{}P$. The metric enters because the gradient of the optimizers is the Riemannian one; it is applied through a Cholesky factor of $U^TU$ and not through its inverse.
With global_rep the tangent vector $\lambda(Y)DE$ of the held gradient is Δ for every section, so at a fixed step size the path of GradientMethod and MomentumMethod does not depend on the section (Adam's entrywise second moments and coordinate step ceilings still do). BFGS and DFP start from this direction; see GeometricOptimizers._metric_inverse!. scripts/symplectic_gradient_options.jl measures these statements.
GeometricOptimizers.update_section! — Method
update_section!(Λᵗ, Λ⁽ᵗ⁻¹⁾, B⁽ᵗ⁻¹⁾, retraction, workspace = nothing)
update_section!(Λ, B, retraction, workspace = nothing)Transport the GlobalSection Λ⁽ᵗ⁻¹⁾ along the step B⁽ᵗ⁻¹⁾ and write the result into Λᵗ:
\[\Lambda^{(t)} \leftarrow \Lambda^{(t-1)}\mathrm{Retraction}(B^{(t-1)}).\]
This is the fourth of the five steps an optimizer step consists of on a homogeneous space — see Optimization on Homogeneous Spaces — and the one that makes the cache independent of the iterate: the new point is read back out of the section afterwards with apply_section!, rather than the section being recomputed at the new point.
B⁽ᵗ⁻¹⁾ is the final velocity the optimizer method produced, already scaled by the step length. It is an AbstractLieAlgHorMatrix when the parameter is on a manifold, and of the parameter's own type when it is not — a vector-space parameter carries no $\lambda$, and the extended retraction on a vector space is addition, so retraction is then ignored.
The three-argument form is the two-argument section written in place, Λᵗ === Λ⁽ᵗ⁻¹⁾. A NamedTuple of parameters is walked leaf by leaf.
workspace is the RetractionWorkspace the retraction is taken in, or nothing to take it in fresh arrays. Optimizer passes one at every call site on the step path; nothing is the default so that a caller who has no optimizer, and every leaf of a parameter set that is not on a manifold, need not build one.
GeometricOptimizers.Ω — Method
Ω(Y::BiorthogonalManifold{T}, Δ::AbstractMatrix{T}) where TPerform the horizontal lift for the manifold of biorthogonal pairs:
\[ (\Delta_\Phi, \Delta_\Psi) \mapsto \Delta_\Phi\Psi^T - \Phi\Delta_\Psi^T(\mathbb{I} - \Phi\Psi^T).\]
The result $\Omega$ is an $N\times{}N$ matrix, i.e. an element of $\mathfrak{gl}(N)$, with $\Omega\cdot(\Phi, \Psi) = (\Omega\Phi, -\Omega^T\Psi) = (\Delta_\Phi, \Delta_\Psi)$ for a tangent Δ, and it is returned dense. It is $\lambda(Y)X\lambda(Y)^{-1}$ for the BiorthogonalLieAlgHorMatrix $X$ that global_rep returns, for every section $\lambda$, because $\lambda(Y)E\Psi^T + K\tilde{K}^T = \lambda(Y)\lambda(Y)^{-1} = \mathbb{I}$.
At a point $\Phi = \Psi = Y$ of the StiefelManifold and a tangent vector $(\Delta, \Delta)$, this is the canonical horizontal lift Ω(::StiefelManifold, ::AbstractMatrix) of $\Delta$.
GeometricOptimizers.Ω — Method
Ω(Y::GrassmannManifold{T}, Δ::AbstractMatrix{T}) where TPerform the canonical horizontal lift for the Grassmann manifold:
\[ \Delta \mapsto \Omega^{St}(\Delta),\]
where $\Omega^{St}$ is the canonical horizontal lift for the Stiefel manifold.
using GeometricOptimizers
using GeometricOptimizers: StiefelProjection
E = GrassmannManifold(StiefelProjection(5, 2))
Δ = [0. 0.; 0. 0.; 2. 3.; 4. 5.; 6. 7.]
GeometricOptimizers.Ω(E, Δ)
# output
5×5 SkewSymMatrix{Float64, Vector{Float64}}:
0.0 -0.0 -2.0 -4.0 -6.0
0.0 0.0 -3.0 -5.0 -7.0
2.0 3.0 0.0 -0.0 -0.0
4.0 5.0 0.0 0.0 -0.0
6.0 7.0 0.0 0.0 0.0GeometricOptimizers.Ω — Method
Ω(Y::StiefelManifold{T}, Δ::AbstractMatrix{T}) where TPerform canonical horizontal lift for the Stiefel manifold:
\[ \Delta \mapsto (\mathbb{I} - \frac{1}{2}YY^T)\Delta{}Y^T - Y\Delta^T(\mathbb{I} - \frac{1}{2}YY^T).\]
Internally this performs
SkewSymMatrix(2 * (I(n) - .5 * Y * Y') * Δ * Y')It uses SkewSymMatrix to save memory.
Examples
using GeometricOptimizers
using GeometricOptimizers: StiefelProjection
E = StiefelManifold(StiefelProjection(5, 2))
Δ = [0. -1.; 1. 0.; 2. 3.; 4. 5.; 6. 7.]
GeometricOptimizers.Ω(E, Δ)
# output
5×5 SkewSymMatrix{Float64, Vector{Float64}}:
0.0 -1.0 -2.0 -4.0 -6.0
1.0 0.0 -3.0 -5.0 -7.0
2.0 3.0 0.0 -0.0 -0.0
4.0 5.0 0.0 0.0 -0.0
6.0 7.0 0.0 0.0 0.0Note that the output of Ω is a skew-symmetric matrix, i.e. an element of $\mathfrak{g}$.
GeometricOptimizers.Ω — Method
Ω(U::SymplecticStiefelManifold{T}, Δ::AbstractMatrix{T}) where TPerform the horizontal lift for the symplectic Stiefel manifold, (3.7) of [12]:
\[ \Delta \mapsto \left(\mathbb{I} - \frac{1}{2}UU^+\right)\Delta{}U^+ - U\Delta^+\left(\mathbb{I} - \frac{1}{2}UU^+\right),\]
with $U^+ = \mathbb{J}_{2n}^TU^T\mathbb{J}_{2N}$ the symplectic inverse. The result is a Hamiltonian $2N\times2N$ matrix, i.e. an element of $\mathfrak{g}$, horizontal with respect to the pseudo-Riemannian metric $h$ of [12], and is returned dense: the symplectic Lie algebra has no structured type in this package. $\Omega(U, \Delta)U = \Delta$.
global_rep computes $\lambda(U)^{-1}\Omega(U, \Delta)\lambda(U)$ without forming this matrix; see there.
Base.Matrix — Method
Matrix(λY::GlobalSection{T, <:BiorthogonalManifold})The group element $\lambda(Y) = [\Phi\ \ K]\in{}GL(N)$. Its inverse transpose is $[\Psi\ \ \tilde{K}]$; see global_section(::BiorthogonalManifold).
GeometricOptimizers.global_rep — Method
global_rep(λY::GlobalSection{T, AT}, Δ::AbstractMatrix{T}) where {T, AT<:BiorthogonalManifold{T}}Express the tangent vector $\Delta = [\Delta_\Phi\ \ \Delta_\Psi]$ at $Y = (\Phi, \Psi)$ as a BiorthogonalLieAlgHorMatrix.
This is the map $\Delta\mapsto\lambda(Y)^{-1}\Omega(Y, \Delta)\lambda(Y)$, with $\Omega$ the horizontal lift GeometricOptimizers.Ω of the biorthogonal manifold. A horizontal $X$ acts on $(E, E)$ through its first $n$ columns and its first $n$ rows, and $\lambda(Y)X\cdot(E, E) = (\lambda(Y)XE, -\lambda(Y)^{-T}X^TE)$, so these are $\lambda(Y)^{-1}\Delta_\Phi$ and $-\lambda(Y)^T\Delta_\Psi$. With $\lambda(Y) = [\Phi\ \ K]$ and $\lambda(Y)^{-T} = [\Psi\ \ \tilde{K}]$ the blocks are
\[A = \Psi^T\Delta_\Phi = -\Delta_\Psi^T\Phi, \qquad B = \tilde{K}^T\Delta_\Phi, \qquad C = -\Delta_\Psi^TK .\]
The two expressions for $A$ agree for a tangent Δ, and their mean is taken all the same, as global_rep takes the skew-symmetric part for the StiefelManifold.
Examples
using GeometricOptimizers
using GeometricOptimizers: apply_section
import Random
Random.seed!(123)
Y = rand(BiorthogonalManifold, 6, 4)
Δ = rgrad(Y, randn(6, 4))
λY = GlobalSection(Y)
X = global_rep(λY, Δ)
# the tangent vector `λ(Y)X⋅(E, E)` is `Δ`
Φ, Ψ, K, K̃ = Y[:, 1:2], Y[:, 3:4], λY.λ[:, 1:4], λY.λ[:, 5:8]
XE, XᵀE = Matrix(X)[:, 1:2], Matrix(X)'[:, 1:2]
hcat([Φ K] * XE, -[Ψ K̃] * XᵀE) ≈ Δ
# output
true