Skip to content

Commit b205f89

Browse files
committed
WIP on SE2 test
1 parent 8047f2e commit b205f89

File tree

13 files changed

+89
-98
lines changed

13 files changed

+89
-98
lines changed

IncrementalInference/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ KernelDensityEstimate = "0.5.6"
9090
LieGroups = "0.1.1"
9191
LinearAlgebra = "1.10"
9292
ManifoldDiff = "0.3, 0.4"
93-
Manifolds = "=0.10.16"
93+
Manifolds = "0.10.17"
9494
ManifoldsBase = "0.15, 1"
95-
Manopt = "^0.5.14"
95+
Manopt = "0.5.14"
9696
MetaGraphs = "0.7, 0.8"
9797
Optim = "1"
9898
OrderedCollections = "1"

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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})

IncrementalInference/src/Factors/GenericFunctions.jl

Lines changed: 21 additions & 36 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,21 @@ 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
37-
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̂)
44-
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
4537

4638
# ::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̂)
39+
function measurement_residual(G::LieGroup, X, p, q)
40+
= log(G, p, q)
41+
return vee(LieAlgebra(G), p, X - X̂) # TODO check sign
5242
end
5343

5444
"""
@@ -69,10 +59,7 @@ export ManifoldFactor
6959
# For now, `Z` is on the tangent space in coordinates at the point used in the factor.
7060
# For groups just the lie algebra
7161
# As transition it will be easier this way, we can reevaluate
72-
struct ManifoldFactor{
73-
M <: AbstractManifold,
74-
T <: SamplableBelief
75-
} <: RelativeObservation
62+
struct ManifoldFactor{M <: AbstractManifold, T <: SamplableBelief} <: RelativeObservation
7663
M::M
7764
Z::T
7865
end
@@ -96,15 +83,13 @@ end
9683

9784
# function (cf::CalcFactor{<:ManifoldFactor{<:AbstractDecoratorManifold}})(Xc, p, q)
9885
function (cf::CalcFactor{<:ManifoldFactor})(X, p, q)
99-
return distanceTangent2Point(cf.factor.M, X, p, q)
86+
return measurement_residual(cf.factor.M, X, p, q)
10087
end
10188

102-
10389
## ======================================================================================
10490
## adjoint factor - adjoint action applied to the measurement
10591
## ======================================================================================
10692

107-
10893
# Adjoints defined in ApproxManifoldProducts
10994
struct AdFactor{F <: RelativeObservation} <: RelativeObservation
11095
factor::F
@@ -147,7 +132,7 @@ end
147132
getMeasurementParametric(f::AdFactor) = getMeasurementParametric(f.factor)
148133

149134
getManifold(f::AdFactor) = getManifold(f.factor)
150-
function getSample(cf::CalcFactor{<:AdFactor})
135+
function getSample(cf::CalcFactor{<:AdFactor})
151136
M = getManifold(cf)
152137
return sampleTangent(M, cf.factor.factor.Z)
153138
end
@@ -168,8 +153,8 @@ struct ManifoldPrior{M <: AbstractManifold, T <: SamplableBelief, P, B <: Abstra
168153
retract_method::AbstractRetractionMethod
169154
end
170155

171-
function ManifoldPrior(M::AbstractDecoratorManifold, p, Z)
172-
return ManifoldPrior(M, p, Z, ManifoldsBase.VeeOrthogonalBasis(), ExponentialRetraction())
156+
function ManifoldPrior(M::LieGroup, p, Z)
157+
return ManifoldPrior(M, p, Z, MB.VeeOrthogonalBasis(), MB.ExponentialRetraction())
173158
end
174159

175160
DFG.getManifold(f::ManifoldPrior) = f.M
@@ -199,7 +184,7 @@ function getFactorMeasurementParametric(fac::ManifoldPrior)
199184
dims = manifold_dimension(M)
200185
meas = fac.p
201186
= convert(SMatrix{dims, dims}, invcov(fac.Z))
202-
meas, iΣ
187+
return meas, iΣ
203188
end
204189

205190
#TODO investigate SVector if small dims, this is slower

IncrementalInference/src/IncrementalInference.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ using Reexport
1313
# @reexport using Graphs
1414
@reexport using LinearAlgebra
1515

16-
using Manifolds
17-
using LieGroups
16+
import Manifolds
17+
using Manifolds: ProductGroup, AbstractDecoratorManifold, get_vector, get_coordinates, ProductManifold, PowerManifold, GeodesicInterpolation, DefaultOrthogonalBasis, get_vector!
18+
using ManifoldsBase
19+
using ManifoldsBase: ℝ, AbstractManifold, AbstractBasis, TypeParameter, AbstractRetractionMethod, AbstractPowerManifold, NestedReplacingPowerRepresentation, retract, ExponentialRetraction
20+
21+
import LieGroups
22+
using LieGroups: LieGroup, LieAlgebra, ProductLieGroup, hat, vee, compose, AbstractProductGroupOperation, AdditionGroupOperation, SpecialEuclideanGroup, SpecialOrthogonalGroup
23+
# using LieGroups: ProductGroupOperation, SemiDirectProductGroupOperation
24+
1825
using RecursiveArrayTools: ArrayPartition
1926
export ArrayPartition
2027
using ManifoldDiff
@@ -45,8 +52,6 @@ using StructTypes
4552

4653
using StaticArrays
4754

48-
using ManifoldsBase
49-
using ManifoldsBase: TypeParameter
5055
# for BayesTree
5156
using MetaGraphs
5257
using Logging

IncrementalInference/src/manifolds/services/ManifoldSampling.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function sampleTangent(
2828
M::AbstractManifold,
2929
z::Distribution,
3030
p = getPointIdentity(M),
31-
basis::AbstractBasis = DefaultOrthogonalBasis()
31+
basis::AbstractBasis = DefaultOrthogonalBasis(),
3232
)
3333
return get_vector(M, p, rand(z), basis)
3434
end
@@ -39,18 +39,20 @@ function sampleTangent(
3939
p = getPointIdentity(M),
4040
)
4141
return hat(M, p, SVector{length(z)}(rand(z))) #TODO make sure all Distribution has length,
42-
# if this errors maybe fall back no next line
42+
# if this errors maybe fall back no next line
4343
# return convert(typeof(p), hat(M, p, rand(z, 1)[:])) #TODO find something better than (z,1)[:]
4444
end
4545

46-
function sampleTangent(
47-
M::LieGroup,
48-
z::Distribution,
49-
p = nothing,
50-
)
51-
return hat(LieAlgebra(M), SVector{length(z)}(rand(z)), ArrayPartition{Float64}) #TODO make sure all Distribution has length,
52-
# if this errors maybe fall back no next line
53-
# return convert(typeof(p), hat(M, p, rand(z, 1)[:])) #TODO find something better than (z,1)[:]
46+
function sampleTangent(M::LieGroup, z::Distribution, p = getPointIdentity(M))
47+
return hat(LieAlgebra(M), SVector{length(z)}(rand(z)), typeof(p))
48+
end
49+
50+
function sampleTangent(M::LieGroup, x::ManifoldKernelDensity, p = mean(x))
51+
# get legacy matrix of coordinates and selected labels
52+
#TODO make sure that when `sample` is replaced in MKD, coordinates is a vector
53+
coords, lbls = sample(x.belief, 1)
54+
X = hat(LieAlgebra(x.manifold), coords[:], typeof(p))
55+
return X
5456
end
5557

5658
"""
@@ -152,7 +154,7 @@ function getSample(cf::CalcFactor{<:AbstractPrior})
152154
end
153155

154156
function getSample(cf::CalcFactor{<:AbstractRelative})
155-
M =getManifold(cf)
157+
M = getManifold(cf)
156158
if hasfield(typeof(cf.factor), :Z)
157159
X = sampleTangent(M, cf.factor.Z)
158160
else

IncrementalInference/src/manifolds/services/ManifoldsExtentions.jl

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
1010
Adapts Manifolds.jl manifolds for use in Optim.jl
1111
"""
12-
struct ManifoldWrapper{TM<:AbstractManifold} <: Optim.Manifold
13-
M::TM
12+
struct ManifoldWrapper{TM <: AbstractManifold} <: Optim.Manifold
13+
M::TM
1414
end
1515

1616
function Optim.retract!(M::ManifoldWrapper, x)
17-
ManifoldsBase.embed_project!(M.M, x, x)
18-
return x
17+
ManifoldsBase.embed_project!(M.M, x, x)
18+
return x
1919
end
2020

2121
function Optim.project_tangent!(M::ManifoldWrapper, g, x)
22-
ManifoldsBase.embed_project!(M.M, g, x, g)
23-
return g
22+
ManifoldsBase.embed_project!(M.M, g, x, g)
23+
return g
2424
end
2525

26-
2726
## ================================================================================================
2827
## AbstractPowerManifold with N as field to avoid excessive compiling time.
2928
## ================================================================================================
@@ -41,7 +40,7 @@ end
4140

4241
function Manifolds.get_vector!(M::NPowerManifold, Y, p, c, B::AbstractBasis)
4342
dim = manifold_dimension(M.manifold)
44-
rep_size = representation_size(M.manifold)
43+
rep_size = Manifolds.representation_size(M.manifold)
4544
v_iter = 1
4645
for i in Manifolds.get_iterator(M)
4746
Y[i] = get_vector(
@@ -57,7 +56,7 @@ function Manifolds.get_vector!(M::NPowerManifold, Y, p, c, B::AbstractBasis)
5756
end
5857

5958
function Manifolds.exp!(M::NPowerManifold, q, p, X)
60-
rep_size = representation_size(M.manifold)
59+
rep_size = Manifolds.representation_size(M.manifold)
6160
for i in Manifolds.get_iterator(M)
6261
q[i] = exp(
6362
M.manifold,
@@ -105,15 +104,25 @@ function DFG.getPointIdentity(G::ProductGroup, ::Type{T} = Float64) where {T <:
105104
end
106105

107106
# fallback
108-
function DFG.getPointIdentity(G::GroupManifold, ::Type{T} = Float64) where {T <: Real}
107+
function DFG.getPointIdentity(G::LieGroup, ::Type{T} = Float64) where {T <: Real}
109108
return error("getPointIdentity not implemented on $G")
110109
end
111110

112111
function DFG.getPointIdentity(
113-
@nospecialize(G::ProductManifold),
112+
G::LieGroups.TranslationGroup{ℝ, TypeParameter{Tuple{N}}},
114113
::Type{T} = Float64,
115-
) where {T <: Real}
116-
return ArrayPartition(map(x -> getPointIdentity(x, T), G.manifolds))
114+
) where {N, T <: Real}
115+
return zeros(SVector{N, T})
116+
end
117+
118+
#TODO test
119+
function DFG.getPointIdentity(
120+
PrG::LieGroup{𝔽, Op, M},
121+
::Type{T} = Float64,
122+
) where {𝔽, Op <: AbstractProductGroupOperation, M <: ProductManifold, T <: Real}
123+
PrM = PrG.manifold
124+
ε = map(getPointIdentity, map(LieGroup, PrM.manifolds, PrG.op.operations), T)
125+
return ArrayPartition(ε)
117126
end
118127

119128
function DFG.getPointIdentity(
@@ -128,33 +137,25 @@ function DFG.getPointIdentity(M::NPowerManifold, ::Type{T} = Float64) where {T <
128137
return fill(getPointIdentity(M.manifold, T), M.N)
129138
end
130139

131-
function DFG.getPointIdentity(G::SemidirectProductGroup, ::Type{T} = Float64) where {T <: Real}
132-
M = base_manifold(G)
133-
N, H = M.manifolds
134-
np = getPointIdentity(N, T)
135-
hp = getPointIdentity(H, T)
136-
return ArrayPartition(np, hp)
137-
end
138-
139140
function DFG.getPointIdentity(
140-
::typeof(SpecialEuclideanGroup(2; variant=:right)),
141-
::Type{T} = Float64
142-
) where T
141+
::typeof(SpecialEuclideanGroup(2; variant = :right)),
142+
::Type{T} = Float64,
143+
) where {T <: Real}
143144
N = 2
144-
return ArrayPartition(zeros(SVector{N,T}), SMatrix{N, N, T}(I))
145+
return ArrayPartition(zeros(SVector{N, T}), SMatrix{N, N, T}(I))
145146
end
146147

147148
function DFG.getPointIdentity(
148-
::typeof(SpecialEuclideanGroup(3; variant=:right)),
149-
::Type{T} = Float64
150-
) where T
149+
::typeof(SpecialEuclideanGroup(3; variant = :right)),
150+
::Type{T} = Float64,
151+
) where {T}
151152
N = 3
152-
return ArrayPartition(zeros(SVector{N,T}), SMatrix{N, N, T}(I))
153+
return ArrayPartition(zeros(SVector{N, T}), SMatrix{N, N, T}(I))
153154
end
154155

155156
function DFG.getPointIdentity(
156-
G::SpecialOrthogonal{TypeParameter{Tuple{N}}},
157-
::Type{T} = Float64
157+
G::SpecialOrthogonalGroup{TypeParameter{Tuple{N}}},
158+
::Type{T} = Float64,
158159
) where {N, T <: Real}
159160
return SMatrix{N, N, T}(I)
160161
end
@@ -163,9 +164,9 @@ function DFG.getPointIdentity(
163164
G::Manifolds.TranslationGroup{TypeParameter{Tuple{N}}},
164165
::Type{T} = Float64,
165166
) where {N, T <: Real}
166-
return zeros(SVector{N,T})
167+
return zeros(SVector{N, T})
167168
end
168169

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

IncrementalInference/src/parametric/services/ParametricManopt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function (jacF!::JacF_RLM!)(
212212
cache = jacF!.Jcache
213213

214214
fill!(X0, 0)
215-
215+
216216
# TODO make sure closure performs (let, ::, or (jacF!::JacF_RLM!)(res, Xc))
217217
function costf!(res, Xc)
218218
get_vector!(M, X, p, Xc, basis_domain)
@@ -414,7 +414,7 @@ function solve_RLM_conditional(
414414

415415
# get the subgraph formed by all frontals, separators and fully connected factors
416416
varlabels = union(frontals, separators)
417-
faclabels = sortDFG(setdiff(getNeighborhood(fg, varlabels, 1), varlabels))
417+
faclabels = sortDFG(setdiff(listNeighborhood(fg, varlabels, 1), varlabels))
418418

419419
filter!(faclabels) do fl
420420
return issubset(getVariableOrder(fg, fl), varlabels)

IncrementalInference/src/parametric/services/ParametricUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function buildGraphSolveManifold(vars::Vector{<:DFGVariable})
288288
N = vartypecount[vartype]
289289
G = getManifold(vartype)
290290
return NPowerManifold(G, N)
291+
# return LieGroups.PowerLieGroup(G, N)
291292
# PowerManifold(G, NestedReplacingPowerRepresentation(), N)
292293
# PowerManifold(G, NestedPowerRepresentation(), N) #TODO investigate as it does not converge
293294
end

IncrementalInference/src/services/EvalFactor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ function addEntropyOnManifold!(
105105
end
106106

107107
# preallocate
108-
T = number_eltype(points[1])
108+
T = ManifoldsBase.number_eltype(points[1])
109109
Xc = zeros(T, manifold_dimension(M))
110110
#allocate to change SMatrix to MMatrix
111-
X = allocate(get_vector(M, points[1], Xc, DefaultOrthogonalBasis()))
111+
X = ManifoldsBase.allocate(get_vector(M, points[1], Xc, DefaultOrthogonalBasis()))
112112

113113
for idx in 1:length(points)
114114
# build tangent coordinate random

0 commit comments

Comments
 (0)