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

Sketch change metric. #423

Merged
merged 49 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ae0cdd1
Sketch change metric.
kellertuer Sep 10, 2021
3347930
Document insights from yesterday evening and – getting stuck at the n…
kellertuer Sep 11, 2021
a302733
rfF.
kellertuer Sep 11, 2021
0857b21
fix a few typos.
kellertuer Sep 11, 2021
c9737b3
adds a change_gradient.
kellertuer Sep 11, 2021
616db5d
Fix a few typos in docs.
kellertuer Sep 11, 2021
158bbf2
Apply suggestions from code review
kellertuer Sep 11, 2021
056e24c
Update src/manifolds/MetricManifold.jl
kellertuer Sep 11, 2021
540f374
Specify Reisz representer, change adjoint to ^H.
kellertuer Sep 11, 2021
a17b4ca
Merge branch 'kellertuer/gradient-conversion' of github.com:JuliaMani…
kellertuer Sep 11, 2021
c742ea5
Fix two typos.
kellertuer Sep 11, 2021
2ee2072
Update src/manifolds/MetricManifold.jl
kellertuer Sep 11, 2021
cb2f932
adds a few conversion, where the embedding is not isometric.
kellertuer Sep 11, 2021
fb304c2
Merge branch 'kellertuer/gradient-conversion' of github.com:JuliaMani…
kellertuer Sep 11, 2021
42875a6
implement the remaining conversions.
kellertuer Sep 12, 2021
9769a1a
add the generic case for doubly stochastic (includes symmetric, too).
kellertuer Sep 12, 2021
05968dc
Apply suggestions from code review
kellertuer Sep 12, 2021
4912e4f
Adress points from code review.
kellertuer Sep 12, 2021
714862e
Merge branch 'kellertuer/gradient-conversion' of github.com:JuliaMani…
kellertuer Sep 12, 2021
5539f4b
introduce mutating variants and decorator transparency.
kellertuer Sep 13, 2021
2eac3ee
Change `change_gradient` to `change_represender` and introduce mutati…
kellertuer Sep 13, 2021
1b79065
Fix two typos.
kellertuer Sep 13, 2021
152e9a1
fix transparency of nonmutating to parent on a Manifold level.
kellertuer Sep 14, 2021
257b223
Finish documentation and test for Generalised Grassmann.
kellertuer Sep 14, 2021
ea76128
Document and test hyperbolic.
kellertuer Sep 14, 2021
d84a3cc
adds two further small tests.
kellertuer Sep 14, 2021
a62e134
Documentation and Test for Poincaré Ball conversion.
kellertuer Sep 15, 2021
6f1fb64
fix a small bug in Hyperbolic copyto! which returned the wrong value.
kellertuer Sep 15, 2021
95b8bc6
finishes testing for hyperbolic.
kellertuer Sep 15, 2021
6300f80
delete change_representer since it should be inherited from Probabili…
kellertuer Sep 15, 2021
7737c92
Extend ProbabilitySimples to also cover change_metric.
kellertuer Sep 15, 2021
d2cec4d
Finish positive Numbers.
kellertuer Sep 15, 2021
5005965
Document and test SPDs
kellertuer Sep 15, 2021
844f8c4
Fixes a few typos in the docs.
kellertuer Sep 15, 2021
c154516
finish tests for product and power – extend features to also work on …
kellertuer Sep 15, 2021
da98b5f
append this step to riemannian differentiation.
kellertuer Sep 15, 2021
cbcef94
Merge branch 'master' into kellertuer/gradient-conversion
kellertuer Sep 15, 2021
14fdb06
bump version.
kellertuer Sep 15, 2021
d1dbb7c
Apply suggestions from code review
kellertuer Sep 16, 2021
95a3c8b
adds a test for positive vectors and starts testing the default Metri…
kellertuer Sep 16, 2021
d34ef6c
Merge branch 'kellertuer/gradient-conversion' of github.com:JuliaMani…
kellertuer Sep 16, 2021
97417ae
Improve docs.
kellertuer Sep 16, 2021
a78ace4
Maybe. just maybe fixed local metric, but now get vector and get coor…
kellertuer Sep 17, 2021
49dc500
format this interims non-working test.
kellertuer Sep 17, 2021
ed2871c
maybe fix the new test by slightly overtyping the basis.
kellertuer Sep 18, 2021
420047d
Fix the error message for hyperbolic.
kellertuer Sep 18, 2021
e180bc4
Simplify default implementation. Extend coverage. Order functions alp…
kellertuer Sep 18, 2021
2f498da
add a test that double metric wrapping is avoided; remove unnecessary…
kellertuer Sep 18, 2021
4501a27
Apply suggestions from code review
kellertuer Sep 22, 2021
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 = "Manifolds"
uuid = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
authors = ["Seth Axen <seth.axen@gmail.com>", "Mateusz Baran <mateuszbaran89@gmail.com>", "Ronny Bergmann <manopt@ronnybergmann.net>", "Antoine Levitt <antoine.levitt@gmail.com>"]
version = "0.6.7"
version = "0.6.8"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
10 changes: 8 additions & 2 deletions src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ using ManifoldsBase:
AbstractLinearVectorTransportMethod,
ApproximateInverseRetraction,
ApproximateRetraction,
DifferentiatedRetractionVectorTransport,
ComponentManifoldError,
CompositeManifoldError,
CotangentSpaceType,
Expand Down Expand Up @@ -460,6 +459,10 @@ export ×,
allocate_result,
base_manifold,
bundle_projection,
change_metric,
change_metric!,
change_representer,
change_representer!,
check_point,
check_vector,
christoffel_symbols_first,
Expand Down Expand Up @@ -648,7 +651,10 @@ export get_basis,
get_coordinates, get_coordinates!, get_vector, get_vector!, get_vectors, number_system
# differentiation
export AbstractDiffBackend,
AbstractRiemannianDiffBackend, FiniteDifferencesBackend, RiemannianONBDiffBackend
AbstractRiemannianDiffBackend,
FiniteDifferencesBackend,
RiemannianONBDiffBackend,
RiemannianProjectionGradientBackend
export diff_backend, diff_backend!, diff_backends
# atlases and charts
export get_point, get_point!, get_parameters, get_parameters!
Expand Down
2 changes: 1 addition & 1 deletion src/groups/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ end

Compose elements ``p,q ∈ \mathcal{G}`` using the group operation ``p \circ q``.

For implementing composition on a new group manifold, please overload [`_compose`](@ref)
For implementing composition on a new group manifold, please overload `_compose`
instead so that methods with [`Identity`](@ref) arguments are not ambiguous.
"""
compose(::AbstractGroupManifold, ::Any...)
Expand Down
4 changes: 2 additions & 2 deletions src/manifolds/CenteredMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where $c_i = \frac{1}{m}\sum_{j=1}^m p_{j,i}$ for $i = 1, \dots, n$.
"""
project(::CenteredMatrices, ::Any)

project!(M::CenteredMatrices, q, p) = copyto!(q, p .- mean(p, dims=1))
project!(::CenteredMatrices, q, p) = copyto!(q, p .- mean(p, dims=1))

@doc raw"""
project(M::CenteredMatrices, p, X)
Expand All @@ -119,7 +119,7 @@ where $c_i = \frac{1}{m}\sum_{j=1}^m x_{j,i}$ for $i = 1, \dots, n$.
"""
project(::CenteredMatrices, ::Any, ::Any)

project!(M::CenteredMatrices, Y, p, X) = (Y .= X .- mean(X, dims=1))
project!(::CenteredMatrices, Y, p, X) = (Y .= X .- mean(X, dims=1))

@generated representation_size(::CenteredMatrices{m,n,𝔽}) where {m,n,𝔽} = (m, n)

Expand Down
33 changes: 33 additions & 0 deletions src/manifolds/GeneralizedGrassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ function GeneralizedGrassmann(
return GeneralizedGrassmann{n,k,field,typeof(B)}(B)
end

@doc raw"""
change_representer(M::GeneralizedGrassmann, ::EuclideanMetric, p, X)

Change `X` to the corresponding representer of a cotangent vector at `p` with respect to the scaled metric
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)

function change_representer!(M::GeneralizedGrassmann, Y, ::EuclideanMetric, p, X)
return copyto!(M, Y, p, M.B \ X)
end

@doc raw"""
change_metric(M::GeneralizedGrassmann, ::EuclideanMetric, p X)

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)

function change_metric!(M::GeneralizedGrassmann, Y, ::EuclideanMetric, p, X)
C2 = cholesky(M.B).L
Y .= C2 \ X
return Y
end

@doc raw"""
check_point(M::GeneralizedGrassmann{n,k,𝔽}, p)

Expand Down
5 changes: 4 additions & 1 deletion src/manifolds/Hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ for T in _HyperbolicTypes
allocate(p::$T, ::Type{P}, dims::Tuple) where {P} = $T(allocate(p.value, P, dims))

@inline Base.copy(p::$T) = $T(copy(p.value))
Base.copyto!(q::$T, p::$T) = copyto!(q.value, p.value)
function Base.copyto!(q::$T, p::$T)
copyto!(q.value, p.value)
return q
end

Base.similar(p::$T) = $T(similar(p.value))

Expand Down
28 changes: 27 additions & 1 deletion src/manifolds/HyperbolicHyperboloid.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
@doc raw"""
change_representer(M::Hyperbolic{n}, ::EuclideanMetric, p, X)

Change the Eucliden representer `X` of a cotangent vector at point `p`.
We only have to correct for the metric, which means that the sign of the last entry changes, since
for the result ``Y`` we are looking for a tangent vector such that

```math
g_p(Y,Z) = -y_{n+1}z_{n+1} + \sum_{i=1}^n y_iz_i = \sum_{i=1}^{n+1} z_ix_i
```

holds, which directly yields ``y_i=x_i`` for ``i=1,\ldots,n`` and ``y_{n+1}=-x_{n+1}``.
"""
change_representer(::Hyperbolic, ::EuclideanMetric, ::Any, ::Any)
mateuszbaran marked this conversation as resolved.
Show resolved Hide resolved

function change_representer!(M::Hyperbolic, Y, ::EuclideanMetric, p, X)
copyto!(M, Y, p, X)
Y[end] *= -1
return Y
end

function change_metric!(::Hyperbolic, ::Any, ::EuclideanMetric, ::Any, ::Any)
return error(
"Changing metric from Euclidean to Hyperbolic is not possible (see Sylvester's law of inertia).",
)
end

function check_point(M::Hyperbolic, p; kwargs...)
mpv = invoke(check_point, Tuple{supertype(typeof(M)),typeof(p)}, M, p; kwargs...)
Expand Down Expand Up @@ -325,7 +351,7 @@ component such that for the
resulting `p` we have that its [`minkowski_metric`](@ref) is $⟨p,X⟩_{\mathrm{M}} = 0$,
i.e. $X_{n+1} = \frac{⟨\tilde p, Y⟩}{p_{n+1}}$, where $\tilde p = (p_1,\ldots,p_n)$.
"""
_hyperbolize(M::Hyperbolic, p, Y) = vcat(Y, dot(p[1:(end - 1)], Y) / p[end])
_hyperbolize(::Hyperbolic, p, Y) = vcat(Y, dot(p[1:(end - 1)], Y) / p[end])

@doc raw"""
inner(M::Hyperbolic{n}, p, X, Y)
Expand Down
45 changes: 45 additions & 0 deletions src/manifolds/HyperbolicPoincareBall.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
@doc raw"""
change_representer(M::Hyperbolic{n}, ::EuclideanMetric, p::PoincareBallPoint, X::PoincareBallTVector)

Since in the metric we have the term `` α = \frac{2}{1-\sum_{i=1}^n p_i^2}`` per element,
the correction for the gradient reads `` Y = \frac{1}{α^2}X``.
"""
change_representer(
::Hyperbolic,
::EuclideanMetric,
::PoincareBallPoint,
::PoincareBallTVector,
)

function change_representer!(
::Hyperbolic,
Y::PoincareBallTVector,
::EuclideanMetric,
p::PoincareBallPoint,
X::PoincareBallTVector,
)
α = 2 / (1 - norm(p.value)^2)
Y.value .= X.value ./ α^2
return Y
end

@doc raw"""
change_metric(M::Hyperbolic{n}, ::EuclideanMetric, p::PoincareBallPoint, X::PoincareBallTVector)

Since in the metric we always have the term `` α = \frac{2}{1-\sum_{i=1}^n p_i^2}`` per element,
the correction for the metric reads ``Z = \frac{1}{α}X``.
"""
change_metric(::Hyperbolic, ::EuclideanMetric, ::PoincareBallPoint, ::PoincareBallTVector)

function change_metric!(
::Hyperbolic,
Y::PoincareBallTVector,
::EuclideanMetric,
p::PoincareBallPoint,
X::PoincareBallTVector,
)
α = 2 / (1 - norm(p.value)^2)
Y.value .= X.value ./ α
return Y
end

function check_point(M::Hyperbolic{N}, p::PoincareBallPoint; kwargs...) where {N}
mpv = check_point(Euclidean(N), p.value; kwargs...)
mpv === nothing || return mpv
Expand Down
Loading