Skip to content

Commit

Permalink
Fix docs and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer committed Jan 5, 2024
1 parent c80df09 commit 60d2944
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/src/manifolds/grassmann.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Order = [:type,:function]

```@autodocs
Modules = [Manifolds]
Pages = ["GrassmannStiefel.jl"]
Pages = ["manifolds/GrassmannStiefel.jl"]
Order = [:type,:function]
```

Expand Down
2 changes: 1 addition & 1 deletion docs/src/manifolds/hamiltonian.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Symmetric matrices
# Hamiltonian matrices

```@autodocs
Modules = [Manifolds]
Expand Down
1 change: 1 addition & 0 deletions src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ export Euclidean,
GeneralizedGrassmann,
GeneralizedStiefel,
Grassmann,
HamiltonianMatrices,
HeisenbergGroup,
Hyperbolic,
KendallsPreShapeSpace,
Expand Down
100 changes: 98 additions & 2 deletions src/manifolds/Hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,43 @@ function Matrix(A::Hamiltonian)
return copy(A.value)

Check warning on line 28 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L27-L28

Added lines #L27 - L28 were not covered by tests
end

@doc raw"""
HamiltonianMatrices{T,𝔽} <: AbstractDecoratorManifold{𝔽}
The [`AbstractManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/types.html#ManifoldsBase.AbstractManifold)
consisting of (real-valued) hamiltonian matrices of size ``n × n``, i.e. the set
````math
\mathfrak{sp}(2n,𝔽) = \bigl\{p ∈ 𝔽^{2n × 2n}\ \big|\ p^+ = p \bigr\},
````
where ``\cdot^{+}`` denotes the [`symplectic_inverse`](@ref),. and ``𝔽 ∈ \{ ℝ, ℂ\}``.
Though it is slightly redundant, usually the matrices are stored as ``2n × 2n`` arrays.
The symbol refers to the main usage within `Manifolds.jl` that is the
Lie algebra to the [`Symplectic`](@ref) as a Lie group with the matrix operation as group operation.
# Constructor
HamiltonianMatrices(n::Int, field::AbstractNumbers=ℝ)
Generate the manifold of ``n × n`` symmetric matrices.
"""
struct HamiltonianMatrices{T,𝔽} <: AbstractDecoratorManifold{𝔽}
size::T
end

function HamiltonianMatrices(n::Int, field::AbstractNumbers=ℝ; parameter::Symbol=:type)
size = wrap_type_parameter(parameter, (n,))
return HamiltonianMatrices{typeof(size),field}(size)

Check warning on line 59 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L57-L59

Added lines #L57 - L59 were not covered by tests
end

function active_traits(f, ::HamiltonianMatrices, args...)
return merge_traits(IsEmbeddedSubmanifold())

Check warning on line 63 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L62-L63

Added lines #L62 - L63 were not covered by tests
end

ManifoldsBase.@default_manifold_fallbacks HamiltonianMatrices Hamiltonian Hamiltonian value value

@doc raw"""
^(A::Hamilonian, ::typeof(+))
Expand All @@ -37,6 +74,59 @@ function ^(A::Hamiltonian, ::typeof(+))
return Hamiltonian(symplectic_inverse(A.value))

Check warning on line 74 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L73-L74

Added lines #L73 - L74 were not covered by tests
end

@doc raw"""
check_point(M::HamiltonianMatrices{n,𝔽}, p; kwargs...)
Check whether `p` is a valid manifold point on the [`HamiltonianMatrices`](@ref) `M`, i.e.
whether `p` [`is_hamiltonian`](@ref).
The tolerance for the test of `p` can be set using `kwargs...`.
"""
function check_point(M::HamiltonianMatrices, p; kwargs...)
if !is_hamiltonian(p; kwargs...)
return DomainError(

Check warning on line 87 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L85-L87

Added lines #L85 - L87 were not covered by tests
norm((Hamiltonian(p)^+) + p),
"The point $(p) does not lie on $M, since it is not hamiltonian.",
)
end
return nothing

Check warning on line 92 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L92

Added line #L92 was not covered by tests
end

"""
check_vector(M::HamiltonianMatrices{n,𝔽}, p, X; kwargs... )
Check whether `X` is a tangent vector to manifold point `p` on the
[`HamiltonianMatrices`](@ref) `M`, i.e. `X` has to be a Hamiltonian matrix
The tolerance for [`is_hamiltonian`](@ref) `X` can be set using `kwargs...`.
"""
function check_vector(M::HamiltonianMatrices, p, X; kwargs...)
if !is_hamiltonian(X; kwargs...)
return DomainError(

Check warning on line 104 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L102-L104

Added lines #L102 - L104 were not covered by tests
norm((Hamiltonian(X)^+) + X),
"The vector $(X) is not a tangent vector to $(p) on $(M), since it is not hamiltonian.",
)
end
return nothing

Check warning on line 109 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L109

Added line #L109 was not covered by tests
end

embed(::HamiltonianMatrices, p) = p
embed(::HamiltonianMatrices, p, X) = X

Check warning on line 113 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L112-L113

Added lines #L112 - L113 were not covered by tests

function get_embedding(::HamiltonianMatrices{TypeParameter{Tuple{N}},𝔽}) where {N,𝔽}
return Euclidean(N, N; field=𝔽)

Check warning on line 116 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L115-L116

Added lines #L115 - L116 were not covered by tests
end
function get_embedding(M::HamiltonianMatrices{Tuple{Int},𝔽}) where {𝔽}
N = get_parameter(M.size)[1]
return Euclidean(N, N; field=𝔽, parameter=:field)

Check warning on line 120 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L118-L120

Added lines #L118 - L120 were not covered by tests
end

"""
is_flat(::HamiltonianMatrices)
Return true. [`HamiltonianMatrices`](@ref) is a flat manifold.
"""
is_flat(M::HamiltonianMatrices) = true

Check warning on line 128 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L128

Added line #L128 was not covered by tests

@doc raw"""
is_hamiltonian(A; kwargs...)
Expand All @@ -48,7 +138,7 @@ A^+ = -A
```
where ``A^+`` denotes the [`symplectic_inverse`](@ref) of `A`.
The passed keyword arguments are passed on to the [`isapprox`](@ref)
The passed keyword arguments are passed on to `isapprox`
check within
"""
function is_hamiltonian(A::AbstractMatrix; kwargs...)
Expand All @@ -61,5 +151,11 @@ end
function show(io::IO, ::MIME"text/plain", A::Hamiltonian)
return print(io, "Hamiltonian($(A.value))")

Check warning on line 152 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L151-L152

Added lines #L151 - L152 were not covered by tests
end

function Base.show(io::IO, ::HamiltonianMatrices{TypeParameter{Tuple{n}},F}) where {n,F}
return print(io, "HamiltonianMatrices($(n), $(F))")

Check warning on line 155 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L154-L155

Added lines #L154 - L155 were not covered by tests
end
function Base.show(io::IO, M::HamiltonianMatrices{Tuple{Int},F}) where {F}
n = get_parameter(M.size)[1]
return print(io, "HamiltonianMatrices($(n), $(F); parameter=:field)")

Check warning on line 159 in src/manifolds/Hamiltonian.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/Hamiltonian.jl#L157-L159

Added lines #L157 - L159 were not covered by tests
end
size(A::Hamiltonian) = size(A.value)
18 changes: 9 additions & 9 deletions src/manifolds/Symmetric.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@doc raw"""
SymmetricMatrices{n,𝔽} <: AbstractDecoratorManifold{𝔽}
The [`AbstractManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/types.html#ManifoldsBase.AbstractManifold) $ \operatorname{Sym}(n)$ consisting of the real- or complex-valued
symmetric matrices of size $n × n$, i.e. the set
The [`AbstractManifold`](https://juliamanifolds.github.io/ManifoldsBase.jl/stable/types.html#ManifoldsBase.AbstractManifold) ``\operatorname{Sym}(n)`` consisting of the real- or complex-valued
symmetric matrices of size ``n × n``, i.e. the set
````math
\operatorname{Sym}(n) = \bigl\{p ∈ 𝔽^{n × n}\ \big|\ p^{\mathrm{H}} = p \bigr\},
````
where $\cdot^{\mathrm{H}}$ denotes the Hermitian, i.e. complex conjugate transpose,
and the field $𝔽 ∈ \{ ℝ, ℂ\}$.
where ``\cdot^{\mathrm{H}}`` denotes the Hermitian, i.e. complex conjugate transpose,
and the field ``𝔽 ∈ \{ ℝ, ℂ\}``.
Though it is slightly redundant, usually the matrices are stored as $n × n$ arrays.
Though it is slightly redundant, usually the matrices are stored as ``n × n`` arrays.
Note that in this representation, the complex valued case has to have a real-valued diagonal,
which is also reflected in the [`manifold_dimension`](@ref manifold_dimension(::SymmetricMatrices)).
Expand All @@ -19,7 +19,7 @@ which is also reflected in the [`manifold_dimension`](@ref manifold_dimension(::
SymmetricMatrices(n::Int, field::AbstractNumbers=ℝ)
Generate the manifold of $n × n$ symmetric matrices.
Generate the manifold of ``n × n`` symmetric matrices.
"""
struct SymmetricMatrices{T,𝔽} <: AbstractDecoratorManifold{𝔽}
size::T
Expand Down Expand Up @@ -186,7 +186,7 @@ Return the dimension of the [`SymmetricMatrices`](@ref) matrix `M` over the numb
\end{aligned}
````
where the last $-n$ is due to the zero imaginary part for Hermitian matrices
where the last ``-n`` is due to the zero imaginary part for Hermitian matrices
"""
function manifold_dimension(M::SymmetricMatrices{<:Any,𝔽}) where {𝔽}
N = get_parameter(M.size)[1]
Expand All @@ -202,7 +202,7 @@ Projects `p` from the embedding onto the [`SymmetricMatrices`](@ref) `M`, i.e.
\operatorname{proj}_{\operatorname{Sym}(n)}(p) = \frac{1}{2} \bigl( p + p^{\mathrm{H}} \bigr),
````
where $\cdot^{\mathrm{H}}$ denotes the Hermitian, i.e. complex conjugate transposed.
where ``\cdot^{\mathrm{H}}`` denotes the Hermitian, i.e. complex conjugate transposed.
"""
project(::SymmetricMatrices, ::Any)

Expand All @@ -220,7 +220,7 @@ Project the matrix `X` onto the tangent space at `p` on the [`SymmetricMatrices`
\operatorname{proj}_p(X) = \frac{1}{2} \bigl( X + X^{\mathrm{H}} \bigr),
````
where $\cdot^{\mathrm{H}}$ denotes the Hermitian, i.e. complex conjugate transposed.
where ``\cdot^{\mathrm{H}}`` denotes the Hermitian, i.e. complex conjugate transposed.
"""
project(::SymmetricMatrices, ::Any, ::Any)

Expand Down
37 changes: 12 additions & 25 deletions src/manifolds/SymplecticGrassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,17 @@ The symplectic Grassmann manifold consists of all symplectic subspaces of
This manifold can be represented as corresponding representers on the [`SymplecticStiefel`](@ref)
````math
\operatorname{SpGr}(2n,2k) := \bigl\{ \operatorname{span}(p) \ \big| \ p ∈ \operatorname{SpSt}(2n, 2k, \mathhb R)\},
````
```math
\operatorname{SpGr}(2n,2k) = \bigl\{ \operatorname{span}(p)\ \big| \ p ∈ \operatorname{SpSt}(2n, 2k, )\},
```
or as projectors
````math
```math
\operatorname{SpGr}(2n, 2k, ℝ) = \bigl\{ p ∈ ℝ^{2n × 2n} \ \big| \ p^2 = p, \operatorname{rank}(p) = 2k, p^+=p \bigr\},
````
where ``⋅^+`` is defined even more general for ``q∈\mathbb R^{2n × 2k}`` matrices as
```
````math
q^+ := J_{2k}^{\mathrm{T}}q^{\mathrm{T}}J_{2n}
\quad\text{ with }\quad
J_{2n} =
\begin{bmatrix}
0_n & I_n \\
-I_n & 0_n
\end{bmatrix}.
````
where ``⋅^+`` is the [`symplectic_inverse`](@ref).
See also [`ProjectorPoint`](@ref) and [`StiefelPoint`](@ref) for these two representations,
where arrays are interpreted as those on the Stiefel manifold.
Expand All @@ -36,15 +26,12 @@ tangent vectors are representers of their corresponding congruence classes, or f
representation as projectors, using a [`ProjectorTVector`](@ref) as
```math
T_p\operatorname{SpGr}(2n, 2k, ℝ)
= \bigl\{
[X,p] \ \mid\ X ∈ \mathfrac{sp(2n,\mathbb R), Xp+pX = X
\bigr\},
T_p\operatorname{SpGr}(2n, 2k, ℝ) =
\bigl\{ [X,p] \ \mid\ X ∈ \mathfrak{sp}(2n,ℝ), Xp+pX = X \bigr\},
```
where
``[X,p] = Xp-pX`` denotes the matrix commutator and
``\mathfrac{sp}(2n,\mathbb R) = \{ X \in \mathbb R^{2n × 2n} \ \mid\ X^+ = -X\}``
is the Lie algebra of the Hamiltonian matrices.
where ``[X,p] = Xp-pX`` denotes the matrix commutator and
``\mathfrak{sp}(2n,ℝ)`` is the Lie algebra of the symplectic group consisting of [`HamiltonianMatrices`](@ref)
For simplicity, the [`ProjectorTVector`](@ref) is stored as just ``X`` from the representation above.
Expand Down Expand Up @@ -90,7 +77,7 @@ Return the dimension of the [`SymplecticGrassmann`](@ref)`(2n,2k)`, which is
\operatorname{dim}\operatorname{SpGr}(2n, 2k) = 4(n-k)k,
````
see [BendokatZimmermann](@cite), Section 4.
see [BendokatZimmermann:2021](@cite), Section 4.
"""
function manifold_dimension(::SymplecticGrassmann{<:Any,ℝ})
n, k = get_parameter(M.size)
Expand Down
8 changes: 4 additions & 4 deletions src/manifolds/SymplecticGrassmannProjector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Check whether `p` is a valid point on the [`SymplecticGrassmann`](@ref),
``\operatorname{SpGr}(2n, 2k)``, that is a propoer symplectic projection:
* ``p^2 = p``, that is ``p`` is a projection
* ``\operatorname{rank(p) = 2k``, that is, the supspace projected onto is of right dimension
* ``\operatorname{rank}(p) = 2k``, that is, the supspace projected onto is of right dimension
* ``p^+ = p`` the projection is symplectic.
"""
function check_point(M::SymplecticGrassmann, p::ProjectorPoint; kwargs...)
Expand Down Expand Up @@ -42,10 +42,10 @@ Check whether `X` is a valid tangent vector at `p` on the [`SymplecticGrassmann`
* ``X^+ = -X``, verify that `X` is [`Hamiltonian`](@ref)
* ``X = Xp + pX``
For details see Proposition 4.2 in [BendokatZimmermannAbsil:2020](@cite) and the definition of ``\mathfrac{sp}_P(2n)`` before,
For details see Proposition 4.2 in [BendokatZimmermann:2021](@cite) and the definition of ``\mathfrak{sp}_P(2n)`` before,
especially the ``\bar{Ω}``, which is the representation for ``X`` used here.
"""
function check_point(
function check_vector(

Check warning on line 48 in src/manifolds/SymplecticGrassmannProjector.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/SymplecticGrassmannProjector.jl#L48

Added line #L48 was not covered by tests
M::SymplecticGrassmann,
p::ProjectorPoint,
X::ProjectorTVector;
Expand All @@ -54,7 +54,7 @@ function check_point(
n, k = get_parameter(M.size)
if !is_hamiltonian(X.value; kwargs...)
return DomainError(

Check warning on line 56 in src/manifolds/SymplecticGrassmannProjector.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/SymplecticGrassmannProjector.jl#L54-L56

Added lines #L54 - L56 were not covered by tests
norm(Hamiltonian(X.value)^+X.value),
norm((Hamiltonian(X.value)^+) + X.value),
(
"The matrix X is not in the tangent space at $p of $M, since X is not Hamiltonian."
),
Expand Down
2 changes: 1 addition & 1 deletion src/manifolds/SymplecticGrassmannStiefel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Check whether `X` is a valid tangent vector at `p` on the [`SymplecticGrassmann`
is a valid representer of an equivalence class of the corersponding
[`SymplecticStiefel`](@ref) manifolds tangent space at `p`.
"""
function check_point(M::SymplecticGrassmann, p, X; kwargs...)
function check_vector(M::SymplecticGrassmann, p, X; kwargs...)
n, k = get_parameter(M.size)
return check_vector(SymplecticStiefel(2 * n, 2 * k), p, X; kwargs...)

Check warning on line 24 in src/manifolds/SymplecticGrassmannStiefel.jl

View check run for this annotation

Codecov / codecov/patch

src/manifolds/SymplecticGrassmannStiefel.jl#L22-L24

Added lines #L22 - L24 were not covered by tests
end
2 changes: 1 addition & 1 deletion test/manifolds/symplecticstiefel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ end
@testset "field parameter" begin
SpSt_6_4 = SymplecticStiefel(2 * 3, 2 * 2; parameter=:field)
@test typeof(get_embedding(SpSt_6_4)) === Euclidean{Tuple{Int,Int},ℝ}
@test repr(SpSt_6_4) == "SymplecticStiefel(6, 4, ℝ; parameter=:field)"
@test repr(SpSt_6_4) == "SymplecticStiefel(6, 4; field=ℝ; parameter=:field)"
@test get_total_space(SpSt_6_4) == Symplectic(6; parameter=:field)
end
end

0 comments on commit 60d2944

Please sign in to comment.