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

Fix apply_diff_group for some actions #673

Merged
merged 29 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
598d5a3
Inverse of differential, fix for apply_diff_group issue
mateuszbaran Oct 27, 2023
48eab50
Merge branch 'master' into mbaran/fix-apply-diff-goa
mateuszbaran Oct 27, 2023
f130856
news entry
mateuszbaran Oct 27, 2023
6a941f8
`inverse_translate_diff` fix
mateuszbaran Oct 27, 2023
8abdea7
Fixes
mateuszbaran Oct 27, 2023
cbb7537
Another fix
mateuszbaran Oct 27, 2023
5eadc7a
test for issue #669
mateuszbaran Oct 27, 2023
137a39d
improve coverage
mateuszbaran Oct 28, 2023
54ea696
more tests
mateuszbaran Oct 28, 2023
e729f03
Merge branch 'master' into mbaran/fix-apply-diff-goa
mateuszbaran Oct 28, 2023
46680df
some tests and figuring out
mateuszbaran Oct 28, 2023
cb05433
fix inv_diff
mateuszbaran Nov 3, 2023
d6e3381
fix translate_diff on general unitary
mateuszbaran Nov 3, 2023
8e4d1e0
remove some tests that don't apply to all actions
mateuszbaran Nov 4, 2023
4fcfd91
why fail there?
mateuszbaran Nov 4, 2023
7fff4cf
tests
mateuszbaran Nov 4, 2023
e934b63
add some tests
mateuszbaran Nov 4, 2023
f2b4a68
this was right
mateuszbaran Nov 4, 2023
66175b5
Giles is helpful
mateuszbaran Nov 4, 2023
cbd8de9
fix circle group inv_diff
mateuszbaran Nov 4, 2023
5ca782c
Merge branch 'master' into mbaran/fix-apply-diff-goa
mateuszbaran Nov 4, 2023
248e87d
add some more tests
mateuszbaran Nov 5, 2023
2a060c5
add pullbacks for group inverse
mateuszbaran Nov 5, 2023
f4120ff
test for translations
mateuszbaran Nov 5, 2023
2f323ac
update news
mateuszbaran Nov 5, 2023
193828c
fix tests
mateuszbaran Nov 5, 2023
ed9818e
fix the other test
mateuszbaran Nov 5, 2023
0ad3fad
coverage false positives
mateuszbaran Nov 5, 2023
6714cff
update version
mateuszbaran Nov 6, 2023
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
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.3] - 2023-10-xx

### Added

- Functions `inv_diff` and `inv_diff!` that correspond to differentials of group inversion.

### Fixed

- Fixed issue with incorrect implementation of `apply_diff_group` in `GroupOperationAction` with left backward and right forward action [#669](https://github.com/JuliaManifolds/Manifolds.jl/issues/669).

## [0.9.2] - 2023-10-27

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/Manifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ export adjoint_action,
identity_element!,
inv,
inv!,
inv_diff,
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
inv_diff!,
inverse_apply,
inverse_apply!,
inverse_apply_diff,
Expand Down
14 changes: 14 additions & 0 deletions src/groups/addition_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ function inv!(
return q
end

"""
inv_diff(::AdditionGroupTrait, G::AbstractDecoratorManifold, p, X)

Compute the value of differential of additive matrix inversion ``p ↦ -p`` at ``X``, i.e. ``-X``.
"""
function inv_diff(::AdditionGroupTrait, G::AbstractDecoratorManifold, p, X)
return -X
end
function inv_diff!(::AdditionGroupTrait, G::AbstractDecoratorManifold, Y, p, X)
Y .= X
Y .*= -1
return Y
end

function is_identity(::AdditionGroupTrait, G::AbstractDecoratorManifold, q; kwargs...)
return isapprox(G, q, zero(q); kwargs...)
end
Expand Down
20 changes: 18 additions & 2 deletions src/groups/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,22 @@ function inv!(
return e
end

@doc raw"""
inv_diff(G::AbstractDecoratorManifold, p, X)

Compute the value of differential of inverse ``p^{-1} ∈ \mathcal{G}`` of an element
``p ∈ \mathcal{G}`` at tangent vector `X` at `p`. The result is a tangent vector at ``p^{-1}``.
"""
inv_diff(G::AbstractDecoratorManifold, p)

@trait_function inv_diff(G::AbstractDecoratorManifold, p, X)
function inv_diff(::TraitList{<:IsGroupManifold}, G::AbstractDecoratorManifold, p, X)
Y = allocate_result(G, inv_diff, X, p)
return inv_diff!(G, Y, p, X)
end

@trait_function inv_diff!(G::AbstractDecoratorManifold, Y, p, X)

function Base.copyto!(
::TraitList{IsGroupManifold{O}},
::AbstractDecoratorManifold,
Expand Down Expand Up @@ -902,7 +918,7 @@ function inverse_translate_diff(
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate_diff(BG, inv(BG, p), q, X, conv)
return translate_diff(BG, inv(BG, p), q, inv_diff(BG, p, X), conv)
end

@trait_function inverse_translate_diff!(
Expand All @@ -923,7 +939,7 @@ function inverse_translate_diff!(
conv::ActionDirectionAndSide,
)
BG = base_group(G)
return translate_diff!(BG, Y, inv(BG, p), q, X, conv)
return translate_diff!(BG, Y, inv(BG, p), q, inv_diff(BG, p, X), conv)
end

@doc raw"""
Expand Down
27 changes: 25 additions & 2 deletions src/groups/group_operation_action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,34 @@ end

function apply_diff_group(A::GroupOperationAction, a, X, p)
G = base_group(A)
return translate_diff(G, p, a, X, reverse_direction_and_side(A))
if direction_and_side(A) === LeftForwardAction() ||
direction_and_side(A) === RightBackwardAction()
return translate_diff(G, p, a, X, reverse_direction_and_side(A))
else
return translate_diff(
G,
p,
a,
inv_diff(G, a, X),
(direction(A), switch_side(action_side(A))),
)
end
end
function apply_diff_group!(A::GroupOperationAction, Y, a, X, p)
G = base_group(A)
return translate_diff!(G, Y, p, a, X, reverse_direction_and_side(A))
if direction_and_side(A) === LeftForwardAction() ||
direction_and_side(A) === RightBackwardAction()
return translate_diff!(G, Y, p, a, X, reverse_direction_and_side(A))
else
return translate_diff!(
G,
Y,
p,
a,
inv_diff(G, a, X),
(direction(A), switch_side(action_side(A))),
)
end
end

function inverse_apply_diff(A::GroupOperationAction, a, p, X)
Expand Down
18 changes: 18 additions & 0 deletions src/groups/multiplication_operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ function inv!(
return q
end

"""
inv_diff(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, X)

Compute the value of differential of matrix inversion ``p ↦ p^{-1}`` at ``X``.
The formula reads ``-p^{-1}Xp^{-1}``.
"""
function inv_diff(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, X)
p_inv = inv(p)
return -p_inv * X * p_inv
end
function inv_diff!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, Y, p, X)
p_inv = inv(p)
Z = X * p_inv
mul!(Y, p_inv, Z)
Y .*= -1
return Y
end

compose(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, p, q) = p * q

function compose!(::MultiplicationGroupTrait, G::AbstractDecoratorManifold, x, p, q)
Expand Down