Skip to content

Commit 97d4161

Browse files
authored
Merge pull request #1586 from JuliaRobotics/master
v0.30.3-rc1
2 parents c64d6d7 + b9af43c commit 97d4161

File tree

6 files changed

+217
-186
lines changed

6 files changed

+217
-186
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "IncrementalInference"
22
uuid = "904591bb-b899-562f-9e6f-b8df64c7d480"
33
keywords = ["MM-iSAMv2", "Bayes tree", "junction tree", "Bayes network", "variable elimination", "graphical models", "SLAM", "inference", "sum-product", "belief-propagation"]
44
desc = "Implements the Multimodal-iSAMv2 algorithm."
5-
version = "0.30.2"
5+
version = "0.30.3"
66

77
[deps]
88
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"

src/Deprecated.jl

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,110 @@ end
5656
@deprecate initManual!(w...;kw...) initVariable!(w...;kw...)
5757

5858

59+
##==============================================================================
60+
## Old parametric kept for comparason until code stabilize
61+
##==============================================================================
62+
63+
64+
65+
"""
66+
$SIGNATURES
67+
68+
Batch solve a Gaussian factor graph using Optim.jl. Parameters can be passed directly to optim.
69+
Notes:
70+
- Only :Euclid and :Circular manifolds are currently supported, own manifold are supported with `algorithmkwargs` (code may need updating though)
71+
"""
72+
function solveGraphParametric2(fg::AbstractDFG;
73+
computeCovariance::Bool = true,
74+
solvekey::Symbol=:parametric,
75+
autodiff = :forward,
76+
algorithm=Optim.BFGS,
77+
algorithmkwargs=(), # add manifold to overwrite computed one
78+
options = Optim.Options(allow_f_increases=true,
79+
time_limit = 100,
80+
# show_trace = true,
81+
# show_every = 1,
82+
))
83+
84+
#Other options
85+
# options = Optim.Options(time_limit = 100,
86+
# iterations = 1000,
87+
# show_trace = true,
88+
# show_every = 1,
89+
# allow_f_increases=true,
90+
# g_tol = 1e-6,
91+
# )
92+
# Example for useing Optim's manifold functions
93+
# mc_mani = IIF.MixedCircular(fg, varIds)
94+
# alg = algorithm(;manifold=mc_mani, algorithmkwargs...)
95+
96+
97+
varIds = listVariables(fg)
98+
99+
flatvar = FlatVariables(fg, varIds)
100+
101+
for vId in varIds
102+
p = getVariableSolverData(fg, vId, solvekey).val[1]
103+
flatvar[vId] = getCoordinates(getVariableType(fg,vId), p)
104+
end
105+
106+
initValues = flatvar.X
107+
# initValues .+= randn(length(initValues))*0.0001
108+
109+
alg = algorithm(; algorithmkwargs...)
110+
111+
cfd = calcFactorMahalanobisDict(fg)
112+
tdtotalCost = Optim.TwiceDifferentiable((x)->_totalCost(fg, cfd, flatvar, x), initValues, autodiff = autodiff)
113+
114+
result = Optim.optimize(tdtotalCost, initValues, alg, options)
115+
rv = Optim.minimizer(result)
116+
117+
Σ = if computeCovariance
118+
H = Optim.hessian!(tdtotalCost, rv)
119+
pinv(H)
120+
else
121+
N = length(initValues)
122+
zeros(N,N)
123+
end
124+
125+
d = Dict{Symbol,NamedTuple{(:val, :cov),Tuple{Vector{Float64},Matrix{Float64}}}}()
126+
127+
for key in varIds
128+
r = flatvar.idx[key]
129+
push!(d,key=>(val=rv[r],cov=Σ[r,r]))
130+
end
131+
132+
return d, result, flatvar.idx, Σ
133+
end
134+
135+
## ================================================================================================
136+
## Manifolds.jl Consolidation
137+
## TODO: Still to be completed and tested.
138+
## ================================================================================================
139+
# struct ManifoldsVector <: Optim.Manifold
140+
# manis::Vector{Manifold}
141+
# end
142+
143+
# Base.getindex(mv::ManifoldsVector, inds...) = getindex(mv.mani, inds...)
144+
# Base.setindex!(mv, X, inds...) = setindex!(mv.mani, X, inds...)
145+
146+
# function ManifoldsVector(fg::AbstractDFG, varIds::Vector{Symbol})
147+
# manis = Bool[]
148+
# for k = varIds
149+
# push!(manis, getVariableType(fg, k) |> getManifold)
150+
# end
151+
# ManifoldsVector(manis)
152+
# end
153+
154+
# function Optim.retract!(manis::ManifoldsVector, x)
155+
# for (i,M) = enumerate(manis)
156+
# x[i] = project(M, x[i])
157+
# end
158+
# return x
159+
# end
160+
# function Optim.project_tangent!(manis::ManifoldsVector, G, x)
161+
# for (i, M) = enumerate(manis)
162+
# G[i] = project(M, x[i], G)
163+
# end
164+
# return G
165+
# end

src/ManifoldsExtentions.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## ================================================================================================
2+
## AbstractPowerManifold with N as field to avoid excessive compiling time.
3+
## ================================================================================================
4+
struct NPowerManifold{𝔽, M<:AbstractManifold{𝔽}} <: AbstractPowerManifold{𝔽, M, NestedReplacingPowerRepresentation}
5+
manifold::M
6+
N::Int
7+
end
8+
9+
Manifolds.get_iterator(M::NPowerManifold) = Base.OneTo(M.N)
10+
11+
function Manifolds.manifold_dimension(M::NPowerManifold)
12+
return manifold_dimension(M.manifold) * M.N
13+
end
14+
115
## ================================================================================================
216
## ArrayPartition getPointIdentity (identity_element)
317
## ================================================================================================
@@ -16,18 +30,17 @@ function getPointIdentity(G::GroupManifold,::Type{T}=Float64) where T<:Real
1630
return error("getPointIdentity not implemented on G")
1731
end
1832

19-
function getPointIdentity(G::ProductManifold,::Type{T}=Float64) where T<:Real
33+
function getPointIdentity(@nospecialize(G::ProductManifold),::Type{T}=Float64) where T<:Real
2034
return ArrayPartition(map(x->getPointIdentity(x,T), G.manifolds))
2135
end
2236

23-
function getPointIdentity(M::Manifolds.PowerManifoldNestedReplacing,::Type{T}=Float64) where T<:Real
37+
function getPointIdentity(@nospecialize(M::PowerManifold),::Type{T}=Float64) where T<:Real
2438
N = Manifolds.get_iterator(M).stop
2539
return fill(getPointIdentity(M.manifold, T), N)
2640
end
2741

28-
function getPointIdentity(M::PowerManifold,::Type{T}=Float64) where T<:Real
29-
N = Manifolds.get_iterator(M).stop
30-
return fill(getPointIdentity(M.manifold, T), N)
42+
function getPointIdentity(M::NPowerManifold,::Type{T}=Float64) where T<:Real
43+
return fill(getPointIdentity(M.manifold, T), M.N)
3144
end
3245

3346
function getPointIdentity(G::SemidirectProductGroup,::Type{T}=Float64) where T<:Real

src/ParametricCSMFunctions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function solveUp_ParametricStateMachine(csmc::CliqStateMachineContainer)
6969
#fill in belief
7070
#TODO createBeliefMessageParametric(csmc.cliqSubFg, csmc.cliq, solvekey=opts.solvekey)
7171
cliqSeparatorVarIds = getCliqSeparatorVarIds(csmc.cliq)
72-
#Fil in CliqueLikelihood
72+
#Fill in CliqueLikelihood
7373
cliqlikelihood = calculateMarginalCliqueLikelihood(vardict, Σ, varIds, cliqSeparatorVarIds)
7474
# @info "$(csmc.cliq.id) clique likelihood message $(cliqlikelihood)"
7575
beliefMsg = LikelihoodMessage(sender=(; id=csmc.cliq.id.value,

0 commit comments

Comments
 (0)