@@ -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
1919end
2020DFG. 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- 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
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- q̂ = 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+ X̂ = 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.
4442end
4543
46- # ::MeasurementOnTangent
47- function distanceTangent2Point (M :: AbstractManifold , X, p, q)
48- q̂ = 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 )
5250end
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
7873end
9691
9792# function (cf::CalcFactor{<:ManifoldFactor{<:AbstractDecoratorManifold}})(Xc, p, q)
9893function (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)
10095end
10196
102-
10397# # ======================================================================================
10498# # adjoint factor - adjoint action applied to the measurement
10599# # ======================================================================================
106100
107-
108101# Adjoints defined in ApproxManifoldProducts
109102struct AdFactor{F <: RelativeObservation } <: RelativeObservation
110103 factor:: F
147140getMeasurementParametric (f:: AdFactor ) = getMeasurementParametric (f. factor)
148141
149142getManifold (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)
153146end
@@ -168,8 +161,8 @@ struct ManifoldPrior{M <: AbstractManifold, T <: SamplableBelief, P, B <: Abstra
168161 retract_method:: AbstractRetractionMethod
169162end
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 ())
173166end
174167
175168DFG. getManifold (f:: ManifoldPrior ) = f. M
@@ -186,31 +179,38 @@ DFG.getManifold(f::ManifoldPrior) = f.M
186179function 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
195188end
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+
197199function getFactorMeasurementParametric (fac:: ManifoldPrior )
198200 M = getManifold (fac)
199201 dims = manifold_dimension (M)
200202 meas = fac. p
201203 iΣ = convert (SMatrix{dims, dims}, invcov (fac. Z))
202- meas, iΣ
204+ return meas, iΣ
203205end
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)
214214end
215215
216216# dist²_Σ = ⟨X, Σ⁻¹*X'⟩
0 commit comments