Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverse retraction based distance approximation #119

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ManifoldsBase"
uuid = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
authors = ["Seth Axen <[email protected]>", "Mateusz Baran <[email protected]>", "Ronny Bergmann <[email protected]>", "Antoine Levitt <[email protected]>"]
version = "0.13.14"
version = "0.13.15"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
10 changes: 10 additions & 0 deletions src/ManifoldsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ If ``\mathcal M`` is not connected, i.e. consists of several disjoint components
the distance between two points from different components should be ``∞``.
"""
distance(M::AbstractManifold, p, q) = norm(M, p, log(M, p, q))
"""
distance(M::AbstractManifold, p, q, m::AbstractInverseRetractionMethod)

Approximate distance between points `p` and `q` on manifold `M` using
[`AbstractInverseRetractionMethod`](@ref) `m`.
"""
function distance(M::AbstractManifold, p, q, m::AbstractInverseRetractionMethod)
return norm(M, p, inverse_retract(M, p, q, m))
end
distance(M::AbstractManifold, p, q, ::LogarithmicInverseRetraction) = distance(M, p, q)

"""
embed(M::AbstractManifold, p)
Expand Down
9 changes: 6 additions & 3 deletions test/default_manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function ManifoldsBase._retract(M::DefaultManifold, p, X, ::CustomDefinedRetract
return retract_custom(M, p, X)
end
function retract_custom(::DefaultManifold, p::DefaultPoint, X::DefaultTVector)
return DefaultPoint(p.value + X.value)
return DefaultPoint(2 * p.value + X.value)
end
function ManifoldsBase._inverse_retract(
M::DefaultManifold,
Expand All @@ -63,7 +63,7 @@ function ManifoldsBase._inverse_retract(
return inverse_retract_custom(M, p, q)
end
function inverse_retract_custom(::DefaultManifold, p::DefaultPoint, q::DefaultPoint)
return DefaultTVector(q.value - p.value)
return DefaultTVector(q.value - 2 * p.value)
end
struct MatrixVectorTransport{T} <: AbstractVector{T}
m::Matrix{T}
Expand Down Expand Up @@ -210,6 +210,8 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),)
@test isapprox(M, exp(M, pts[1], tv1, 0), pts[1])

@test distance(M, pts[1], pts[2]) ≈ norm(M, pts[1], tv1)
@test distance(M, pts[1], pts[2], LogarithmicInverseRetraction()) ≈
norm(M, pts[1], tv1)

@test mid_point(M, pts[1], pts[2]) == convert(T, [0.5, 0.5, 0.0])
midp = allocate(pts[1])
Expand Down Expand Up @@ -549,7 +551,8 @@ Base.size(x::MatrixVectorTransport) = (size(x.m, 2),)
@test X3 == log(M, p, q)
@test log!(M, X3, p, q) == log(M, p, q)
@test X3 == log(M, p, q)
@test inverse_retract(M, p, q, CustomDefinedInverseRetraction()) == -Y
@test inverse_retract(M, p, q, CustomDefinedInverseRetraction()) == -2 * Y
@test distance(M, p, q, CustomDefinedInverseRetraction()) == 2.0
X4 = ManifoldsBase.allocate_result(M, inverse_retract, p, q)
@test inverse_retract!(M, X4, p, q) == inverse_retract(M, p, q)
@test X4 == inverse_retract(M, p, q)
Expand Down