Skip to content

Commit 281e6a3

Browse files
committed
test SE2Mani works as a mix beteween SO(2) x Tr(2) and SE(2) and some vee/hat
1 parent 27c8ddd commit 281e6a3

File tree

11 files changed

+197
-116
lines changed

11 files changed

+197
-116
lines changed

IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl

Lines changed: 1 addition & 1 deletion
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
2121

2222

2323
getManifold(de::DERelative{T}) where {T} = getManifold(de.domain)

IncrementalInference/src/Factors/Circular.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434

3535
function (cf::CalcFactor{<:PriorCircular})(m, p)
3636
M = getManifold(cf)
37-
Xc = vee(M, p, log(M, p, m))
37+
Xc = vee(LieAlgebra(M), log(M, p, m))
3838
return Xc
3939
end
4040

IncrementalInference/src/Factors/GenericFunctions.jl

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ DFG.getDimension(Z::BallTreeDensity) = Ndim(Z)
3636
# end
3737

3838
# ::MeasurementOnTangent
39-
function measurement_residual(G::LieGroup, X, p, q)
39+
function measurement_residual(G::AbstractLieGroup, X, p, q)
4040
= log(G, p, q)
41-
return vee(LieAlgebra(G), p, X - X̂) # TODO check sign
41+
return vee(LieAlgebra(G), X - X̂) # TODO check sign with gradients, does not matter for cost so can't double check.
42+
end
43+
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)
4250
end
4351

4452
"""
@@ -153,8 +161,8 @@ struct ManifoldPrior{M <: AbstractManifold, T <: SamplableBelief, P, B <: Abstra
153161
retract_method::AbstractRetractionMethod
154162
end
155163

156-
function ManifoldPrior(M::LieGroup, p, Z)
157-
return ManifoldPrior(M, p, Z, MB.VeeOrthogonalBasis(), MB.ExponentialRetraction())
164+
function ManifoldPrior(M::AbstractLieGroup, p, Z)
165+
return ManifoldPrior(M, p, Z, DefaultLieAlgebraOrthogonalBasis(), MB.ExponentialRetraction())
158166
end
159167

160168
DFG.getManifold(f::ManifoldPrior) = f.M
@@ -171,14 +179,23 @@ DFG.getManifold(f::ManifoldPrior) = f.M
171179
function getSample(cf::CalcFactor{<:ManifoldPrior})
172180
Z = cf.factor.Z
173181
p = cf.factor.p
174-
M = cf.manifold # .factor.M
182+
M = cf.factor.M
175183
basis = cf.factor.basis
176184
retract_method = cf.factor.retract_method
177185
point = samplePoint(M, Z, p, basis, retract_method)
178186

179187
return point
180188
end
181189

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+
182199
function getFactorMeasurementParametric(fac::ManifoldPrior)
183200
M = getManifold(fac)
184201
dims = manifold_dimension(M)
@@ -191,11 +208,9 @@ end
191208
# dim = manifold_dimension(M)
192209
# Xc = [SVector{dim}(rand(Z)) for _ in 1:N]
193210

194-
function (cf::CalcFactor{<:ManifoldPrior})(m, p)
211+
function (cf::CalcFactor{<:ManifoldPrior{<:AbstractLieGroup}})(m, p)
195212
M = cf.factor.M
196-
# return log(M, p, m)
197-
return vee(M, p, log(M, p, m))
198-
# return distancePrior(M, m, p)
213+
return prior_residual(M, m, p)
199214
end
200215

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

IncrementalInference/src/IncrementalInference.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ using Reexport
1414
@reexport using LinearAlgebra
1515

1616
import Manifolds
17-
using Manifolds: ProductGroup, AbstractDecoratorManifold, get_vector, get_coordinates, ProductManifold, PowerManifold, GeodesicInterpolation, DefaultOrthogonalBasis, get_vector!
17+
using Manifolds: ProductGroup, AbstractDecoratorManifold, get_vector, ProductManifold, PowerManifold, GeodesicInterpolation, DefaultOrthogonalBasis, get_vector!
1818
using ManifoldsBase
1919
using ManifoldsBase: ℝ, AbstractManifold, AbstractBasis, TypeParameter, AbstractRetractionMethod, AbstractPowerManifold, NestedReplacingPowerRepresentation, retract, ExponentialRetraction
2020

2121
import LieGroups
22-
using LieGroups: LieGroup, LieAlgebra, ProductLieGroup, hat, vee, compose, AbstractProductGroupOperation, AdditionGroupOperation, SpecialEuclideanGroup, SpecialOrthogonalGroup
22+
using LieGroups: AbstractLieGroup, LieGroup, LieAlgebra, ProductLieGroup, hat, vee, compose, AbstractProductGroupOperation, AdditionGroupOperation, SpecialEuclideanGroup, SpecialOrthogonalGroup, DefaultLieAlgebraOrthogonalBasis
2323
using LieGroups: TranslationGroup
2424
# using LieGroups: ProductGroupOperation, SemiDirectProductGroupOperation
2525

IncrementalInference/src/manifolds/services/ManifoldSampling.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function sampleTangent(
4343
# return convert(typeof(p), hat(M, p, rand(z, 1)[:])) #TODO find something better than (z,1)[:]
4444
end
4545

46-
function sampleTangent(M::LieGroup, z::Distribution, p = getPointIdentity(M))
46+
function sampleTangent(M::AbstractLieGroup, z::Distribution, p = getPointIdentity(M))
4747
return hat(LieAlgebra(M), SVector{length(z)}(rand(z)), typeof(p))
4848
end
4949

50-
function sampleTangent(M::LieGroup, x::ManifoldKernelDensity, p = mean(x))
50+
function sampleTangent(M::AbstractLieGroup, x::ManifoldKernelDensity, p = mean(x))
5151
# get legacy matrix of coordinates and selected labels
5252
#TODO make sure that when `sample` is replaced in MKD, coordinates is a vector
5353
coords, lbls = sample(x.belief, 1)
@@ -84,7 +84,7 @@ function samplePoint(
8484
end
8585

8686
function samplePoint(
87-
M::LieGroup,
87+
M::AbstractLieGroup,
8888
sbelief,
8989
p = getPointIdentity(M),
9090
retraction_method::AbstractRetractionMethod = ExponentialRetraction(),

IncrementalInference/src/manifolds/services/ManifoldsExtentions.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function DFG.getPointIdentity(G::ProductGroup, ::Type{T} = Float64) where {T <:
104104
end
105105

106106
# fallback
107-
function DFG.getPointIdentity(G::LieGroup, ::Type{T} = Float64) where {T <: Real}
107+
function DFG.getPointIdentity(G::AbstractLieGroup, ::Type{T} = Float64) where {T <: Real}
108108
return error("getPointIdentity not implemented on $G")
109109
end
110110

@@ -117,14 +117,22 @@ end
117117

118118
#TODO test
119119
function DFG.getPointIdentity(
120-
PrG::LieGroup{𝔽, Op, M},
120+
PrG::AbstractLieGroup{𝔽, Op, M},
121121
::Type{T} = Float64,
122122
) where {𝔽, Op <: AbstractProductGroupOperation, M <: ProductManifold, T <: Real}
123123
PrM = PrG.manifold
124-
ε = map(getPointIdentity, map(LieGroup, PrM.manifolds, PrG.op.operations), T)
124+
ε = map(G -> getPointIdentity(G, T), map(LieGroup, PrM.manifolds, PrG.op.operations))
125125
return ArrayPartition(ε)
126126
end
127127

128+
function DFG.getPointIdentity(
129+
VG::LieGroups.ValidationLieGroup,
130+
::Type{T} = Float64,
131+
) where {T <: Real}
132+
G = VG.lie_group
133+
return LieGroups.ValidationMPoint(getPointIdentity(G, T))
134+
end
135+
128136
function DFG.getPointIdentity(
129137
@nospecialize(M::PowerManifold),
130138
::Type{T} = Float64,
@@ -167,6 +175,6 @@ function DFG.getPointIdentity(
167175
return zeros(SVector{N, T})
168176
end
169177

170-
function DFG.getPointIdentity(G::LieGroup{ℝ,AdditionGroupOperation,<:Circle{ℝ}}, ::Type{T} = Float64) where {T <: Real}
178+
function DFG.getPointIdentity(G::AbstractLieGroup{ℝ,AdditionGroupOperation,<:Circle{ℝ}}, ::Type{T} = Float64) where {T <: Real}
171179
return [zero(T)] #FIXME we cannot support scalars yet
172180
end

IncrementalInference/src/parametric/services/ParametricManopt.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ end
162162
# function JacF_RLM!(M, costF!; basis_domain::AbstractBasis = DefaultOrthonormalBasis())
163163
function JacF_RLM!(M, costF!, p, fg=nothing;
164164
all_points=p,
165-
basis_domain::AbstractBasis = DefaultOrthogonalBasis(),
165+
basis_domain::AbstractBasis = LieGroups.DefaultLieAlgebraOrthogonalBasis(),
166166
is_sparse=!isnothing(fg)
167167
)
168168

@@ -171,6 +171,7 @@ function JacF_RLM!(M, costF!, p, fg=nothing;
171171
X0 = zeros(manifold_dimension(M))
172172

173173
X = get_vector(M, p, X0, basis_domain)
174+
# X = vee(LieAlgebra(M), X0)
174175

175176
q = exp(M, p, X)
176177

IncrementalInference/src/parametric/services/ParametricUtils.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ function getFactorMeasurementParametric(fac::AbstractPrior)
104104
ϵ = getPointIdentity(M)
105105
dims = manifold_dimension(M)
106106
Xc, iΣ = getMeasurementParametric(fac)
107-
X = get_vector(M, ϵ, Xc, DefaultOrthogonalBasis())
107+
# X = get_vector(M, ϵ, Xc, DefaultOrthogonalBasis())
108+
X = hat(LieAlgebra(M), Xc, typeof(ϵ))
108109
meas = convert(typeof(ϵ), exp(M, ϵ, X))
109110
= convert(SMatrix{dims, dims}, iΣ)
110111
meas, iΣ
@@ -115,7 +116,12 @@ function getFactorMeasurementParametric(fac::AbstractRelative)
115116
ϵ = getPointIdentity(M)
116117
dims = manifold_dimension(M)
117118
Xc, iΣ = getMeasurementParametric(fac)
118-
measX = convert(typeof(ϵ), get_vector(M, ϵ, Xc, DefaultOrthogonalBasis()))
119+
# measX = convert(typeof(ϵ), get_vector(M, ϵ, Xc, DefaultOrthogonalBasis()))
120+
if M isa LieGroups.ValidationLieGroup
121+
measX = LieGroups.unwrap_validation(hat(LieAlgebra(M), Xc, typeof(ϵ)))
122+
else
123+
measX = convert(typeof(ϵ), hat(LieAlgebra(M), Xc, typeof(ϵ)))
124+
end
119125
= convert(SMatrix{dims, dims}, iΣ)
120126
measX, iΣ
121127
end
@@ -287,12 +293,18 @@ function buildGraphSolveManifold(vars::Vector{<:VariableCompute})
287293
PMs = map(vartypes) do vartype
288294
N = vartypecount[vartype]
289295
G = getManifold(vartype)
296+
if G isa LieGroups.ValidationLieGroup
297+
#strip away ValidationLieGroup
298+
G = G.lie_group
299+
end
290300
return NPowerManifold(G, N)
291301
# return LieGroups.PowerLieGroup(G, N)
302+
# return Manifolds.PowerManifold(G, N)
292303
# PowerManifold(G, NestedReplacingPowerRepresentation(), N)
293304
# PowerManifold(G, NestedPowerRepresentation(), N) #TODO investigate as it does not converge
294305
end
295306
M = ProductManifold(PMs...)
307+
# M = ProductLieGroup(PMs...)
296308
return M, vartypes, vartypeslist
297309
end
298310

@@ -307,7 +319,8 @@ function GraphSolveBuffers(@nospecialize(M), ::Type{T}) where {T}
307319
ϵ = getPointIdentity(M, T)
308320
p = deepcopy(ϵ)# allocate_result(M, getPointIdentity)
309321
X = deepcopy(ϵ) #allcoate(p)
310-
Xc = get_coordinates(M, ϵ, X, DefaultOrthogonalBasis())
322+
# Xc = Manifolds.get_coordinates(M, ϵ, X, DefaultOrthogonalBasis())
323+
Xc = vee(LieGroup(M), X)
311324
return GraphSolveBuffers(ϵ, p, X, Xc)
312325
end
313326

@@ -569,7 +582,8 @@ function solveGraphParametricOptim(
569582
# log!(M, X, Identity(ProductOperation), p)
570583
# calculate initial coordinates vector for Optim
571584
log!(M, X, ϵ, p)
572-
get_coordinates!(M, Xc, ϵ, X, DefaultOrthogonalBasis())
585+
# get_coordinates!(M, Xc, ϵ, X, DefaultOrthogonalBasis())
586+
vee!(LieGroup(M), Xc, X)
573587

574588
initValues = Xc
575589
#FIXME, for some reason we get NANs and adding a small random value works

IncrementalInference/src/services/NumericalCalculations.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ end
103103
function (hypoCalcFactor::CalcFactorNormSq)(M::AbstractManifold, Xc::AbstractVector)
104104
# hypoCalcFactor.manifold is the factor's manifold, not the variable's manifold that is needed here
105105
ϵ = getPointIdentity(M)
106-
X = get_vector(M, ϵ, SVector(Xc), DefaultOrthogonalBasis())
106+
# X = get_vector(M, ϵ, SVector(Xc), DefaultOrthogonalBasis())
107+
X = hat(LieAlgebra(M), SVector(Xc), typeof(ϵ))
107108
p = exp(M, ϵ, X)
108109
return hypoCalcFactor(CalcConv, p)
109110
end
@@ -131,7 +132,7 @@ function _solveLambdaNumeric(
131132
ϵ = getPointIdentity(variableType)
132133

133134
X0c = zero(MVector{getDimension(M),Float64})
134-
X0c .= vee(M, u0, log(M, ϵ, u0))
135+
X0c .= vee(LieAlgebra(M), log(M, ϵ, u0))
135136

136137
alg = islen1 ? Optim.BFGS() : Optim.NelderMead()
137138

@@ -171,7 +172,8 @@ end
171172
# for deconv with the measurement a tangent vector, can dispatch for other measurement types.
172173
function (hypoCalcFactor::CalcFactorNormSq)(::Type{CalcDeconv}, M::AbstractManifold, Xc::AbstractVector)
173174
ϵ = getPointIdentity(M)
174-
X = get_vector(M, ϵ, Xc, DefaultOrthogonalBasis())
175+
# X = get_vector(M, ϵ, Xc, DefaultOrthogonalBasis())
176+
X = hat(LieAlgebra(M), Xc, typeof(ϵ))
175177
return hypoCalcFactor(CalcDeconv, X)
176178
end
177179

@@ -188,7 +190,7 @@ function _solveLambdaNumericMeas(
188190
M = getManifold(fcttype)
189191
ϵ = getPointIdentity(M)
190192
X0c = zeros(manifold_dimension(M))
191-
X0c .= vee(M, ϵ, X0)
193+
X0c .= vee(LieAlgebra(M), X0)
192194

193195
alg = islen1 ? Optim.BFGS() : Optim.NelderMead()
194196

IncrementalInference/src/services/SubGraphFunctions.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ function transferUpdateSubGraph!(
141141
@info "transferUpdateSubGraph! -- syms=$syms"
142142
end
143143

144-
# transfer specific fields into dest from src
145-
@time for var in (x -> getVariable(src, x)).(syms)
146-
# NOTE compared copytoState! vs surgical updateVariableSolverData!
144+
for var in (x -> getVariable(src, x)).(syms)
145+
# NOTE compared copytoState! vs deprecated surgical updateVariableSolverData!
147146
# updateVariableSolverData! 0.000626 seconds (1.11 k allocations: 114.289 KiB)
148147
# copytoState! 0.000099 seconds (315 allocations: 27.758 KiB)
149148
DFG.copytoState!(

0 commit comments

Comments
 (0)