Skip to content

Commit c2fdb03

Browse files
authored
Update to LieGroups (#1874)
1 parent f89ad41 commit c2fdb03

40 files changed

+447
-257
lines changed

IncrementalInference/Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ FunctionalStateMachine = "3e9e306e-7e3c-11e9-12d2-8f8f67a2f951"
2424
IncrementalInferenceTypes = "9808408f-4dbc-47e4-913c-6068b950e289"
2525
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
2626
KernelDensityEstimate = "2472808a-b354-52ea-a80e-1658a3c6056d"
27+
LieGroups = "6774de46-80ba-43f8-ba42-e41071ccfc5f"
2728
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2829
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2930
ManifoldDiff = "af67fdf4-a580-4b9f-bbec-742ef357defd"
@@ -86,11 +87,12 @@ Gadfly = "1"
8687
Interpolations = "0.15"
8788
JSON3 = "1"
8889
KernelDensityEstimate = "0.5.6"
90+
LieGroups = "0.1.1"
8991
LinearAlgebra = "1.10"
9092
ManifoldDiff = "0.3, 0.4"
91-
Manifolds = "=0.10.16"
93+
Manifolds = "0.10.17"
9294
ManifoldsBase = "0.15, 1"
93-
Manopt = "^0.5.14"
95+
Manopt = "0.5.14"
9496
MetaGraphs = "0.7, 0.8"
9597
Optim = "1"
9698
OrderedCollections = "1"

IncrementalInference/ext/HeatmapSampler.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ end
8080

8181
(lsg::LevelSetGridNormal)(w...; kw...) = lsg.densityFnc(w...; kw...)
8282

83-
function sampleTangent(M::AbstractManifold, lsg::LevelSetGridNormal)
83+
function sampleTangent(M::AbstractLieGroup, lsg::LevelSetGridNormal)
8484
return sampleTangent(M, lsg.heatmap.densityFnc)
8585
end
8686

@@ -203,7 +203,7 @@ function HeatmapGridDensity(
203203
bw = getBW(density_)[:, 1]
204204
@cast pts[i, j] := vec_preIS[j][i]
205205
bel = kde!(collect(pts), bw, weights)
206-
density = ManifoldKernelDensity(TranslationGroup(Ndim(bel)), bel)
206+
density = ManifoldKernelDensity(LieGroups.TranslationGroup(Ndim(bel)), bel)
207207

208208
# return `<:SamplableBelief` object
209209
return HeatmapGridDensity(field_on_grid, domain, hint_callback, bw_factor, density)

IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using DocStringExtensions
1717

1818
export DERelative
1919

20-
import Manifolds: allocate, compose, hat, Identity, vee, log
20+
using LieGroups: allocate, compose, hat, Identity, vee, log, LieAlgebra
2121

2222

2323
getManifold(de::DERelative{T}) where {T} = getManifold(de.domain)
@@ -233,7 +233,7 @@ function (cf::CalcFactor{<:DERelative})(
233233
# find the difference between measured and predicted.
234234
# assuming the ODE integrated from current X1 through to predicted X2 (ie `meas1[:,idx]`)
235235
res_ = compose(M, inv(M, X[solveforIdx]), meas1)
236-
res = vee(M, Identity(M), log(M, Identity(M), res_))
236+
res = vee(LieAlgebra(M), log(M, res_))
237237

238238
return res
239239
end
@@ -301,7 +301,7 @@ function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int
301301
prob = oder.backwardProblem
302302
M_ = getManifold(getVariableType(cf.fullvariables[1]))
303303
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
304-
convert(Tuple, M_),
304+
AMP._manifoldtuple(M_),
305305
)
306306
# getBelief(cf.fullvariables[2]) |> getPoints
307307
cf._legacyParams[2], M_
@@ -311,7 +311,7 @@ function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int
311311
M_ = getManifold(getVariableType(cf.fullvariables[2]))
312312
# buffer manifold operations for use during factor evaluation
313313
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
314-
convert(Tuple, M_),
314+
AMP._manifoldtuple(M_),
315315
)
316316
# getBelief(cf.fullvariables[1]) |> getPoints
317317
cf._legacyParams[1], M_

IncrementalInference/ext/IncrInfrFluxFactorsExt.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using DataStructures: OrderedDict
99
using LinearAlgebra
1010
using Base64
1111
using Manifolds
12+
using LieGroups
1213
using DocStringExtensions
1314
using BSON
1415

@@ -51,8 +52,10 @@ function Random.rand(nfb::FluxModelsDistribution, N::Integer = 1)
5152
end
5253

5354
sampleTangent(M::AbstractManifold, fmd::FluxModelsDistribution, p = 0) = rand(fmd, 1)[1]
55+
sampleTangent(M::AbstractLieGroup, fmd::FluxModelsDistribution, p = 0) = rand(fmd, 1)[1]
56+
5457
samplePoint(M::AbstractManifold, fmd::FluxModelsDistribution, p = 0) = rand(fmd, 1)[1]
55-
function samplePoint(M::AbstractDecoratorManifold, fmd::FluxModelsDistribution, p = 0)
58+
function samplePoint(M::AbstractLieGroup, fmd::FluxModelsDistribution, p = 0)
5659
return rand(fmd, 1)[1]
5760
end
5861

IncrementalInference/ext/IncrInfrInterpolationsExt.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using Statistics
77
using DocStringExtensions
88
using TensorCast
99
using Manifolds
10+
using LieGroups
11+
using LieGroups: TranslationGroup
1012
using ApproxManifoldProducts
1113
import ApproxManifoldProducts: sample
1214
const AMP = ApproxManifoldProducts

IncrementalInference/src/ExportAPI.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export AbstractDFG,
2121
setSolvedCount!,
2222
listSupersolves,
2323
listSolveKeys,
24-
cloneSolveKey!,
2524
diagm,
2625
listBlobEntries,
2726
FolderStore,
@@ -106,8 +105,6 @@ export CSMHistory,
106105
joinLogPath,
107106
lsfPriors,
108107
isPrior,
109-
lsTypes,
110-
lsfTypes,
111108
findClosestTimestamp,
112109
printVariable,
113110
printFactor,

IncrementalInference/src/Factors/Circular.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
function (cf::CalcFactor{<:CircularCircular})(X, p, q)
66
M = getManifold(cf)
7-
return distanceTangent2Point(M, X, p, q)
7+
return measurement_residual(M, X, p, q)
88
end
99

1010
function getSample(cf::CalcFactor{<:CircularCircular})
1111
# FIXME workaround for issue with manifolds CircularGroup,
12-
return [rand(cf.factor.Z)]
12+
# return [rand(cf.factor.Z)]
13+
return sampleTangent(getManifold(cf), cf.factor.Z, getPointIdentity(Circular))
1314
end
1415

1516
function Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{CircularCircular})
@@ -28,13 +29,14 @@ function getSample(cf::CalcFactor{<:PriorCircular})
2829
# FIXME workaround for issue #TBD with manifolds CircularGroup,
2930
# JuliaManifolds/Manifolds.jl#415
3031
# no method similar(::Float64, ::Type{Float64})
31-
return samplePoint(cf.manifold, cf.factor.Z, [0.0])
32+
# return samplePoint(cf.manifold, cf.factor.Z, [0.0])
33+
return samplePoint(cf.manifold, cf.factor.Z, getPointIdentity(Circular))
3234
# return [Manifolds.sym_rem(rand(cf.factor.Z))]
3335
end
3436

3537
function (cf::CalcFactor{<:PriorCircular})(m, p)
3638
M = getManifold(cf)
37-
Xc = vee(M, p, log(M, p, m))
39+
Xc = vee(LieAlgebra(M), log(M, p, m))
3840
return Xc
3941
end
4042

IncrementalInference/src/Factors/EuclidDistance.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ getDimension(::InstanceType{<:EuclidDistance}) = 1
2020
(s::CalcFactor{<:EuclidDistance})(z, x1, x2) = z .- norm(x2 .- x1)
2121

2222
function Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{EuclidDistance})
23-
return Manifolds.TranslationGroup(1)
23+
return LieGroups.TranslationGroup(1)
2424
end
2525

2626
"""

IncrementalInference/src/Factors/GenericFunctions.jl

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function DFG.getDimension(Z::FluxModelsDistribution)
1313
Z.outputDim[1]
1414
else
1515
error(
16-
"can only do single index tensor at this time, please open an issue with Caesar.jl",
17-
)
16+
"can only do single index tensor at this time, please open an issue with Caesar.jl",
17+
)
1818
end
1919
end
2020
DFG.getDimension(Z::ManifoldKernelDensity) = getManifold(Z) |> getDimension
@@ -24,31 +24,29 @@ DFG.getDimension(Z::BallTreeDensity) = Ndim(Z)
2424
## ======================================================================================
2525
## Generic manifold cost functions
2626
## ======================================================================================
27-
"""
28-
$SIGNATURES
29-
Generic function that can be used in binary factors to calculate distance between points on Lie Groups with measurements.
30-
"""
31-
function distancePoint2Point(M::SemidirectProductGroup, m, p, q)
32-
= Manifolds.compose(M, p, m)
33-
# return log(M, q, q̂)
34-
return vee(M, q, log(M, q, q̂))
35-
# return distance(M, q, q̂)
36-
end
27+
# """
28+
# $SIGNATURES
29+
# Generic function that can be used in binary factors to calculate distance between points on Lie Groups with measurements.
30+
# """
31+
# function distancePoint2Point(M::SemidirectProductGroup, m, p, q)
32+
# q̂ = Manifolds.compose(M, p, m)
33+
# # return log(M, q, q̂)
34+
# return vee(M, q, log(M, q, q̂))
35+
# # return distance(M, q, q̂)
36+
# end
3737

38-
#::MeasurementOnTangent
39-
function distanceTangent2Point(M::SemidirectProductGroup, X, p, q)
40-
= Manifolds.compose(M, p, exp(M, getPointIdentity(M), X)) #for groups
41-
# return log(M, q, q̂)
42-
return vee(M, q, log(M, q, q̂))
43-
# return distance(M, q, q̂)
38+
# ::MeasurementOnTangent
39+
function measurement_residual(G::AbstractLieGroup, X, p, q)
40+
= log(G, p, q)
41+
return vee(LieAlgebra(G), X - X̂) # TODO check sign with gradients, does not matter for cost so can't double check.
4442
end
4543

46-
# ::MeasurementOnTangent
47-
function distanceTangent2Point(M::AbstractManifold, X, p, q)
48-
= exp(M, p, X)
49-
# return log(M, q, q̂)
50-
return vee(M, q, log(M, q, q̂))
51-
# return distance(M, q, q̂)
44+
function prior_residual(G::AbstractLieGroup, m, p)
45+
#TODO should it be TₘM or TₚM?
46+
# Is the covariance that of the point m? If so, I would think it should be TₘM, but that doesn't seem to work.
47+
X = log(G, p, m) # X ∈ TₚM, # this one gives the correct hex.
48+
# X = log(G, m, p) # X ∈ TₘM,
49+
return vee(LieAlgebra(G), X)
5250
end
5351

5452
"""
@@ -69,10 +67,7 @@ export ManifoldFactor
6967
# For now, `Z` is on the tangent space in coordinates at the point used in the factor.
7068
# For groups just the lie algebra
7169
# As transition it will be easier this way, we can reevaluate
72-
struct ManifoldFactor{
73-
M <: AbstractManifold,
74-
T <: SamplableBelief
75-
} <: RelativeObservation
70+
struct ManifoldFactor{M <: AbstractManifold, T <: SamplableBelief} <: RelativeObservation
7671
M::M
7772
Z::T
7873
end
@@ -96,15 +91,13 @@ end
9691

9792
# function (cf::CalcFactor{<:ManifoldFactor{<:AbstractDecoratorManifold}})(Xc, p, q)
9893
function (cf::CalcFactor{<:ManifoldFactor})(X, p, q)
99-
return distanceTangent2Point(cf.factor.M, X, p, q)
94+
return measurement_residual(cf.factor.M, X, p, q)
10095
end
10196

102-
10397
## ======================================================================================
10498
## adjoint factor - adjoint action applied to the measurement
10599
## ======================================================================================
106100

107-
108101
# Adjoints defined in ApproxManifoldProducts
109102
struct AdFactor{F <: RelativeObservation} <: RelativeObservation
110103
factor::F
@@ -147,7 +140,7 @@ end
147140
getMeasurementParametric(f::AdFactor) = getMeasurementParametric(f.factor)
148141

149142
getManifold(f::AdFactor) = getManifold(f.factor)
150-
function getSample(cf::CalcFactor{<:AdFactor})
143+
function getSample(cf::CalcFactor{<:AdFactor})
151144
M = getManifold(cf)
152145
return sampleTangent(M, cf.factor.factor.Z)
153146
end
@@ -168,8 +161,8 @@ struct ManifoldPrior{M <: AbstractManifold, T <: SamplableBelief, P, B <: Abstra
168161
retract_method::AbstractRetractionMethod
169162
end
170163

171-
function ManifoldPrior(M::AbstractDecoratorManifold, p, Z)
172-
return ManifoldPrior(M, p, Z, ManifoldsBase.VeeOrthogonalBasis(), ExponentialRetraction())
164+
function ManifoldPrior(M::AbstractLieGroup, p, Z)
165+
return ManifoldPrior(M, p, Z, DefaultLieAlgebraOrthogonalBasis(), MB.ExponentialRetraction())
173166
end
174167

175168
DFG.getManifold(f::ManifoldPrior) = f.M
@@ -186,31 +179,38 @@ DFG.getManifold(f::ManifoldPrior) = f.M
186179
function getSample(cf::CalcFactor{<:ManifoldPrior})
187180
Z = cf.factor.Z
188181
p = cf.factor.p
189-
M = cf.manifold # .factor.M
182+
M = cf.factor.M
190183
basis = cf.factor.basis
191184
retract_method = cf.factor.retract_method
192185
point = samplePoint(M, Z, p, basis, retract_method)
193186

194187
return point
195188
end
196189

190+
function getSample(cf::CalcFactor{<:ManifoldPrior{<:AbstractLieGroup}})
191+
Z = cf.factor.Z
192+
p = cf.factor.p
193+
M = cf.factor.M
194+
point = samplePoint(M, Z, p)
195+
196+
return point
197+
end
198+
197199
function getFactorMeasurementParametric(fac::ManifoldPrior)
198200
M = getManifold(fac)
199201
dims = manifold_dimension(M)
200202
meas = fac.p
201203
= convert(SMatrix{dims, dims}, invcov(fac.Z))
202-
meas, iΣ
204+
return meas, iΣ
203205
end
204206

205207
#TODO investigate SVector if small dims, this is slower
206208
# dim = manifold_dimension(M)
207209
# Xc = [SVector{dim}(rand(Z)) for _ in 1:N]
208210

209-
function (cf::CalcFactor{<:ManifoldPrior})(m, p)
211+
function (cf::CalcFactor{<:ManifoldPrior{<:AbstractLieGroup}})(m, p)
210212
M = cf.factor.M
211-
# return log(M, p, m)
212-
return vee(M, p, log(M, p, m))
213-
# return distancePrior(M, m, p)
213+
return prior_residual(M, m, p)
214214
end
215215

216216
# dist²_Σ = ⟨X, Σ⁻¹*X'⟩

IncrementalInference/src/Factors/GenericMarginal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mutable struct GenericMarginal <: RelativeObservation # AbstractRelativeRoots
1111
GenericMarginal(a, b, c) = new(a, b, c)
1212
end
1313

14-
getManifold(::GenericMarginal) = TranslationGroup(1)
14+
getManifold(::GenericMarginal) = LieGroups.TranslationGroup(1)
1515

1616
getSample(::CalcFactor{<:GenericMarginal}) = [0]
1717

0 commit comments

Comments
 (0)