Skip to content

Commit

Permalink
Finish documentation and test for Generalised Grassmann.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertuer committed Sep 14, 2021
1 parent 152e9a1 commit 257b223
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/manifolds/GeneralizedGrassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ end
change_representer(M::GeneralizedGrassmann, ::EuclideanMetric, p, X)
Change `X` to the corresponding representer of the gradient with respect to the scaled metric
of the [`GeneralizedGrassmann`](@ref) `M`, i.e. `M.B\X`.
of the [`GeneralizedGrassmann`](@ref) `M`, i.e, since
```math
g_p(X,Y) = \operatorname{tr}(Y^{\mathrm{H}}BZ) = \operatorname{tr}(X^{\mathrm{H}}Z) = ⟨X,Z⟩
```
has to hold for all ``Z``, where the repreenter `X` is given, the resulting representer with
respect to the metric on the [`GeneralizedGrassmann`](@ref) is given by ``Y = B^{-1}X``.
"""
change_representer(::GeneralizedGrassmann, ::EuclideanMetric, ::Any, ::Any)

Expand All @@ -74,7 +81,6 @@ end
Change `X` to the corresponding vector with respect to the metric of the [`GeneralizedGrassmann`](@ref) `M`,
i.e. let ``B=LL'`` be the Cholesky decomposition of the matrix `M.B`, then the corresponding vector is ``L\X``.
"""
change_metric(M::GeneralizedGrassmann, ::EuclideanMetric, ::Any, ::Any)

Expand Down
44 changes: 27 additions & 17 deletions test/manifolds/generalized_grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include("../utils.jl")
@testset "Real" begin
B = [1.0 0.0 0.0; 0.0 4.0 0.0; 0.0 0.0 1.0]
M = GeneralizedGrassmann(3, 2, B)
x = [1.0 0.0; 0.0 0.5; 0.0 0.0]
p = [1.0 0.0; 0.0 0.5; 0.0 0.0]
@testset "Basics" begin
@test repr(M) ==
"GeneralizedGrassmann(3, 2, [1.0 0.0 0.0; 0.0 4.0 0.0; 0.0 0.0 1.0], ℝ)"
Expand All @@ -13,36 +13,46 @@ include("../utils.jl")
@test base_manifold(M) === M
@test_throws DomainError is_point(M, [1.0, 0.0, 0.0, 0.0], true)
@test_throws DomainError is_point(M, 1im * [1.0 0.0; 0.0 1.0; 0.0 0.0], true)
@test !is_vector(M, x, [0.0, 0.0, 1.0, 0.0])
@test_throws DomainError is_vector(M, x, [0.0, 0.0, 1.0, 0.0], true)
@test_throws DomainError is_vector(M, x, 1 * im * zero_vector(M, x), true)
@test !is_vector(M, p, [0.0, 0.0, 1.0, 0.0])
@test_throws DomainError is_vector(M, p, [0.0, 0.0, 1.0, 0.0], true)
@test_throws DomainError is_vector(M, p, 1 * im * zero_vector(M, p), true)
@test injectivity_radius(M) == π / 2
@test injectivity_radius(M, ExponentialRetraction()) == π / 2
@test injectivity_radius(M, x) == π / 2
@test injectivity_radius(M, x, ExponentialRetraction()) == π / 2
@test mean(M, [x, x, x]) == x
@test injectivity_radius(M, p) == π / 2
@test injectivity_radius(M, p, ExponentialRetraction()) == π / 2
@test mean(M, [p, p, p]) == p
end
@testset "Embedding and Projection" begin
y = similar(x)
z = embed(M, x)
@test z == x
embed!(M, y, x)
@test y == z
q = similar(p)
p2 = embed(M, p)
@test p2 == p
embed!(M, q, p)
@test q == p2
a = [1.0 0.0; 0.0 2.0; 0.0 0.0]
@test !is_point(M, a)
b = similar(a)
c = project(M, a)
@test c == x
@test c == p
project!(M, b, a)
@test b == x
@test b == p
X = [0.0 0.0; 0.0 0.0; -1.0 1.0]
Y = similar(X)
Z = embed(M, x, X)
embed!(M, Y, x, X)
Z = embed(M, p, X)
embed!(M, Y, p, X)
@test Y == X
@test Z == X
end

@testset "gradient and metric conversion" begin
B = [3.0 0.0 0.0; 0.0 4.0 0.0; 0.0 0.0 2.0]
M = GeneralizedGrassmann(3, 2, B)
p = [1.0 0.0; 0.0 0.5; 0.0 0.0]
L = cholesky(B).L
X = [0.0 0.0; 0.0 0.0; 1.0 -1.0]
Y = change_metric(M, EuclideanMetric(), p, X)
@test Y == L \ X
Z = change_representer(M, EuclideanMetric(), p, X)
@test Z == B \ X
end
types = [Matrix{Float64}]
TEST_STATIC_SIZED && push!(types, MMatrix{3,2,Float64,6})
X = [0.0 0.0; 1.0 0.0; 0.0 2.0]
Expand Down

0 comments on commit 257b223

Please sign in to comment.