Skip to content

Commit 808da77

Browse files
committed
Fix ManifoldPrior for parameric
1 parent 5553f1a commit 808da77

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/Factors/GenericFunctions.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,20 @@ function getSample(cf::CalcFactor{<:ManifoldPrior})
141141
return point
142142
end
143143

144+
function getFactorMeasurementParametric(fac::ManifoldPrior)
145+
M = getManifold(fac)
146+
dims = manifold_dimension(M)
147+
meas = fac.p
148+
= convert(SMatrix{dims, dims}, invcov(fac.Z))
149+
meas, iΣ
150+
end
151+
144152
#TODO investigate SVector if small dims, this is slower
145153
# dim = manifold_dimension(M)
146154
# Xc = [SVector{dim}(rand(Z)) for _ in 1:N]
147155

148156
function (cf::CalcFactor{<:ManifoldPrior})(m, p)
149-
M = cf.manifold # .factor.M
157+
M = cf.factor.M
150158
# return log(M, p, m)
151159
return vee(M, p, log(M, p, m))
152160
# return distancePrior(M, m, p)

src/manifolds/services/ManifoldSampling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636
function sampleTangent(
3737
M::AbstractDecoratorManifold,
3838
z::Distribution,
39-
p = identity_element(M), #getPointIdentity(M),
39+
p = getPointIdentity(M),
4040
)
4141
return hat(M, p, rand(z, 1)[:]) #TODO find something better than (z,1)[:]
4242
end

src/parametric/services/ParametricManopt.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ function CalcFactorResidualAP(fg::GraphsDFG, factorLabels::Vector{Symbol}, varIn
7070
return ArrayPartition{CalcFactorResidual, typeof(parts_tuple)}(parts_tuple)
7171
end
7272

73-
function (cfm::CalcFactorResidual{T})(p) where T
73+
function (cfm::CalcFactorResidual)(p)
7474
meas = cfm.meas
7575
points = map(idx->p[idx], cfm.varOrderIdxs)
76-
return cfm.sqrt_iΣ * cfm(meas, points...) # 0.654783 seconds (6.75 M allocations: 531.688 MiB, 14.41% gc time)
76+
return cfm.sqrt_iΣ * cfm(meas, points...)
7777
end
7878

7979
function (cfm::CalcFactorResidual{T})() where T
80-
return cfm.sqrt_iΣ * cfm(cfm.meas, cfm.points...) # 0.654783 seconds (6.75 M allocations: 531.688 MiB, 14.41% gc time)
80+
return cfm.sqrt_iΣ * cfm(cfm.meas, cfm.points...)
8181
end
8282

8383
# cost function f: M->ℝᵈ for Riemannian Levenberg-Marquardt
@@ -110,7 +110,12 @@ struct CostFres!{CFT}
110110
# add return_ranges to allow MultiThreaded
111111
end
112112

113-
function calcFactorResVec!(x::Vector{T}, cfm_part::Vector{<:CalcFactorResidual}, p::AbstractArray{T}, st::Int) where T
113+
function calcFactorResVec!(
114+
x::Vector{T},
115+
cfm_part::Vector{<:CalcFactorResidual{FT}},
116+
p::AbstractArray{T},
117+
st::Int
118+
) where {T,FT}
114119
l = getDimension(cfm_part[1]) # all should be the same
115120
for cfm in cfm_part
116121
x[st:st + l - 1] = cfm(p) #NOTE looks like do not broadcast here
@@ -289,7 +294,7 @@ function covarianceFiniteDiff(M, jacF!::JacF_RLM!, p0)
289294
end
290295
end
291296

292-
@time H = FiniteDiff.finite_difference_hessian(costf, X0)
297+
H = FiniteDiff.finite_difference_hessian(costf, X0)
293298

294299
# inv(H)
295300
Σ = Matrix(H) \ Matrix{eltype(H)}(I, size(H)...)
@@ -356,7 +361,7 @@ function solve_RLM(
356361
else
357362
# TODO make sure J initial_jacobian_f is updated, otherwise recalc jacF!(M, J, lm_r) # lm_r === p0
358363
J = initial_jacobian_f
359-
H = J'J
364+
H = J'J # approx
360365
Σ = H \ Matrix{eltype(H)}(I, size(H)...)
361366
# Σ = pinv(H)
362367
end

0 commit comments

Comments
 (0)