Skip to content

Commit

Permalink
Inverse retraction based distance approximation (#119)
Browse files Browse the repository at this point in the history
* Inverse retraction based distance approximation

* bump version
  • Loading branch information
mateuszbaran authored Jul 25, 2022
1 parent e509370 commit 44e2da8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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

2 comments on commit 44e2da8

@mateuszbaran
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/64940

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.15 -m "<description of version>" 44e2da89a8fe37ae7d885854ce016b6fbbe7c008
git push origin v0.13.15

Please sign in to comment.