Skip to content

Commit

Permalink
finish tests for product and power – extend features to also work on …
Browse files Browse the repository at this point in the history
…the sphere.
  • Loading branch information
kellertuer committed Sep 15, 2021
1 parent 844f8c4 commit c154516
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/manifolds/PowerManifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ function change_representer!(M::AbstractPowerManifold, Y, G::AbstractMetric, p,
M.manifold,
_write(M, rep_size, Y, i),
G,
_read(M, rep_size, P, i),
_read(M, rep_size, p, i),
_read(M, rep_size, X, i),
)
end
return Y
end

"""
Expand All @@ -105,7 +106,7 @@ Since the metric on a power manifold decouples, the change of a representer can
"""
change_metric(M::AbstractPowerManifold, ::AbstractMetric, ::Any, ::Any)

function change_metric!(M::AbstractPowerManifold, Y, ::AbstractMetric, p, X)
function change_metric!(M::AbstractPowerManifold, Y, G::AbstractMetric, p, X)
rep_size = representation_size(M.manifold)
for i in get_iterator(M)
change_metric!(
Expand All @@ -116,6 +117,7 @@ function change_metric!(M::AbstractPowerManifold, Y, ::AbstractMetric, p, X)
_read(M, rep_size, X, i),
)
end
return Y
end

@doc raw"""
Expand Down
6 changes: 5 additions & 1 deletion src/manifolds/Sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ end
function decorated_manifold(M::AbstractSphere{𝔽}) where {𝔽}
return Euclidean(representation_size(M)...; field=𝔽)
end
get_embedding(M::AbstractSphere{𝔽}) where {𝔽} = decorated_manifold(M)

# Since on every tangent space the Euclidean matric (restricted to this space) is used, this should be fine
default_metric_dispatch(::AbstractSphere, ::EuclideanMetric) = Val(true)

@doc raw"""
distance(M::AbstractSphere, p, q)
Expand Down Expand Up @@ -226,6 +228,8 @@ function get_coordinates!(
return Y
end

get_embedding(M::AbstractSphere{𝔽}) where {𝔽} = decorated_manifold(M)

@doc raw"""
get_vector(M::AbstractSphere{ℝ}, p, X, B::DefaultOrthonormalBasis)
Expand Down
19 changes: 19 additions & 0 deletions test/manifolds/power_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,23 @@ end
@test isapprox(a, a2)
@test_throws ErrorException get_point(M, A2, p, a2)
end

@testset "metric conversion" begin
M = SymmetricPositiveDefinite(3)
N = PowerManifold(M, NestedPowerRepresentation(), 2)
e = EuclideanMetric()
p = [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1]
q = [2.0 0.0 0.0; 0.0 2.0 0.0; 0.0 0.0 1]
P = [p, q]
X = [log(M, p, q), log(M, q, p)]
Y = change_metric(N, e, P, X)
Yc = [change_metric(M, e, p, log(M, p, q)), change_metric(M, e, q, log(M, q, p))]
@test norm(N, P, Y .- Yc) 0
Z = change_representer(N, e, P, X)
Zc = [
change_representer(M, e, p, log(M, p, q)),
change_representer(M, e, q, log(M, q, p)),
]
@test norm(N, P, Z .- Zc) 0
end
end
22 changes: 22 additions & 0 deletions test/manifolds/product_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,26 @@ end
p2 = get_point(M, A, p, a)
@test all(p2.parts .== p.parts)
end

@testset "metric conversion" begin
M = SymmetricPositiveDefinite(3)
N = ProductManifold(M, M)
e = EuclideanMetric()
p = [1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1]
q = [2.0 0.0 0.0; 0.0 2.0 0.0; 0.0 0.0 1]
P = ProductRepr(p, q)
X = ProductRepr(log(M, p, q), log(M, q, p))
Y = change_metric(N, e, P, X)
Yc = ProductRepr(
change_metric(M, e, p, log(M, p, q)),
change_metric(M, e, q, log(M, q, p)),
)
@test norm(N, P, Y - Yc) 0
Z = change_representer(N, e, P, X)
Zc = ProductRepr(
change_representer(M, e, p, log(M, p, q)),
change_representer(M, e, q, log(M, q, p)),
)
@test norm(N, P, Z - Zc) 0
end
end
9 changes: 9 additions & 0 deletions test/manifolds/sphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,13 @@ using ManifoldsBase: TFVector
end
end
end

@testset "Metric conversion is the identity" begin
p = [1.0, 0.0, 0.0]
X = [0.0, 1.0, 1.0]
Y = change_representer(M, EuclideanMetric(), p, X)
@test Y == X
Z = change_metric(M, EuclideanMetric(), p, X)
@test Z == X
end
end

0 comments on commit c154516

Please sign in to comment.