Skip to content

Commit 5723a26

Browse files
authored
Merge pull request #1598 from JuliaRobotics/master
v0.30.4-rc1
2 parents 97d4161 + 96fff67 commit 5723a26

35 files changed

+439
-387
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ The list below highlights breaking changes according to normal semver workflow -
1515

1616
- `ArrayPartition` should be used instead of `ProductRepr`, see issue #1537.
1717
- Remove old deprecated option keywords in `addVariable` and `addFactor`.
18+
- Improve `IIF.solveGraphParametric`.
19+
- Introduce `IIF.autoinitParametric!`.
20+
- Upgrade `initAll!(dfg, :parametric)`.
21+
- Refactor many files to subfolders `src/services` or `src/entities`.
1822

1923
# Changes in v0.29
2024

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.3"
5+
version = "0.30.4"
66

77
[deps]
88
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
File renamed without changes.

src/ExportAPI.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,45 @@ export samplePoint
326326

327327
export buildCliqSubgraph_StateMachine
328328

329+
export
330+
getCliqueStatus,
331+
setCliqueStatus!
332+
333+
export
334+
stackCliqUpMsgsByVariable,
335+
getCliqDownMsgsAfterDownSolve
336+
337+
export resetCliqSolve!
338+
export addLikelihoodsDifferential!
339+
export addLikelihoodsDifferentialCHILD!
340+
341+
export selectFactorType
342+
export approxDeconv, deconvSolveKey
343+
export approxDeconvBelief
344+
345+
export cont2disc
346+
export rebaseFactorVariable!
347+
export accumulateFactorMeans
348+
export solveFactorParameteric
349+
350+
351+
export repeatCSMStep!
352+
export attachCSM!
353+
export filterHistAllToArray, cliqHistFilterTransitions, printCliqSummary
354+
export printHistoryLine, printHistoryLane, printCliqHistorySummary
355+
export printCSMHistoryLogical, printCSMHistorySequential
356+
357+
export MetaBayesTree, BayesTree
358+
export CSMHistoryTuple
359+
360+
export getVariableOrder, calcCliquesRecycled
361+
export getCliquePotentials
362+
export getClique, getCliques, getCliqueIds, getCliqueData
363+
export hasClique
364+
export setCliqueDrawColor!, getCliqueDrawColor
365+
export appendSeparatorToClique!
366+
367+
export buildTreeFromOrdering! # TODO make internal and deprecate external use to only `buildTreeReset!``
368+
369+
370+
#

src/IncrementalInference.jl

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ include("Factors/MsgPrior.jl")
142142
include("entities/CliqueTypes.jl")
143143
include("entities/JunctionTreeTypes.jl")
144144

145+
include("services/JunctionTree.jl")
145146
include("services/GraphInit.jl")
146-
include("FactorGraph.jl")
147+
include("services/FactorGraph.jl")
147148
include("services/BayesNet.jl")
148149

149150
# Serialization helpers
@@ -153,16 +154,17 @@ include("Serialization/services/SerializingDistributions.jl")
153154
include("Serialization/services/SerializationMKD.jl")
154155
include("Serialization/services/DispatchPackedConversions.jl")
155156

156-
include("FGOSUtils.jl")
157-
include("CompareUtils.jl")
157+
include("services/FGOSUtils.jl")
158+
include("services/CompareUtils.jl")
159+
158160
include("NeedsResolution.jl")
159161

160162
# tree and init related functions
161-
include("SubGraphFunctions.jl")
162-
include("JunctionTree.jl")
163-
include("TreeMessageAccessors.jl")
164-
include("TreeMessageUtils.jl")
165-
include("TreeBasedInitialization.jl")
163+
include("services/SubGraphFunctions.jl")
164+
include("services/JunctionTreeUtils.jl")
165+
include("services/TreeMessageAccessors.jl")
166+
include("services/TreeMessageUtils.jl")
167+
include("services/TreeBasedInitialization.jl")
166168

167169

168170
# included variables of IIF, easy to extend in user's context
@@ -178,7 +180,10 @@ include("Factors/EuclidDistance.jl")
178180
include("Factors/Circular.jl")
179181
include("Factors/PartialPrior.jl")
180182
include("Factors/PartialPriorPassThrough.jl")
181-
include("DefaultNodeTypes.jl") # older file
183+
184+
185+
# older file
186+
include("services/DefaultNodeTypes.jl")
182187

183188
# Refactoring in progress
184189
include("services/CalcFactor.jl")
@@ -187,32 +192,34 @@ include("services/FactorGradients.jl")
187192
include("services/CliqueTypes.jl")
188193

189194
# solving graphs
190-
include("SolverUtilities.jl")
191-
include("NumericalCalculations.jl")
192-
include("DeconvUtils.jl")
193-
include("ExplicitDiscreteMarginalizations.jl")
195+
include("services/SolverUtilities.jl")
196+
include("services/NumericalCalculations.jl")
197+
include("services/DeconvUtils.jl")
198+
include("services/ExplicitDiscreteMarginalizations.jl")
194199
# include("InferDimensionUtils.jl")
195200
include("services/EvalFactor.jl")
196201
include("services/ApproxConv.jl")
197202

198-
include("ConsolidateParametricRelatives.jl") # FIXME CONSOLIDATE
203+
# FIXME CONSOLIDATE
204+
include("ConsolidateParametricRelatives.jl")
199205

200-
include("GraphProductOperations.jl")
201-
include("SolveTree.jl")
202-
include("TetherUtils.jl")
203-
include("TreeDebugTools.jl")
204-
include("CliqStateMachineUtils.jl")
206+
include("services/GraphProductOperations.jl")
207+
include("services/SolveTree.jl")
208+
include("services/TetherUtils.jl")
209+
include("services/TreeDebugTools.jl")
210+
include("CliqueStateMachine/services/CliqStateMachineUtils.jl")
205211

206212
#EXPERIMENTAL parametric
207213
include("ParametricCSMFunctions.jl")
208214
include("ParametricUtils.jl")
215+
include("services/MaxMixture.jl")
209216

210217
#X-stroke
211-
include("CliqueStateMachine.jl")
218+
include("CliqueStateMachine/services/CliqueStateMachine.jl")
212219

213220
include("CanonicalGraphExamples.jl")
214221

215-
include("AdditionalUtils.jl")
222+
include("services/AdditionalUtils.jl")
216223
include("SolverAPI.jl")
217224

218225
# Symbolic tree analysis files.

src/ParametricUtils.jl

Lines changed: 12 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,18 @@ function _totalCost(fg,
515515
end
516516

517517

518-
#TODO maybe consolidate with solveGraphParametric
519-
#TODO WIP
520-
```
521-
$SIGNATURES
518+
"""
519+
$SIGNATURES
522520
Solve for frontal values only with values in seprarators fixed
523-
```
521+
522+
DevNotes
523+
- WIP
524+
- Relates to: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/466#issuecomment-562556953
525+
- Consolidation
526+
- Definitely with [`solveFactorParameteric`](@ref)
527+
- Maybe with [`solveGraphParametric`](@ref)
528+
- https://github.com/JuliaRobotics/IncrementalInference.jl/pull/1588#issuecomment-1210406683
529+
"""
524530
function solveConditionalsParametric(fg::AbstractDFG,
525531
frontals::Vector{Symbol},
526532
separators::Vector{Symbol} = setdiff(listVariables(fg), frontals);
@@ -769,170 +775,5 @@ function createMvNormal(v::DFGVariable, key=:parametric)
769775
end
770776

771777

772-
function autoinitParametric!(dfg::AbstractDFG,
773-
initme::Symbol;
774-
reinit::Bool=false)
775-
#
776-
solveKey = :parametric
777-
778-
xi = getVariable(dfg, initme)
779-
vnd = getSolverData(xi, solveKey)
780-
# don't initialize a variable more than once
781-
if reinit || !isInitialized(xi, solveKey)
782-
783-
# frontals - initme
784-
# separators - inifrom
785-
786-
initfrom = ls2(dfg, initme)
787-
filter!(initfrom) do vl
788-
isInitialized(dfg, vl, solveKey)
789-
end
790-
791-
vardict, result, flatvars, Σ = solveConditionalsParametric(dfg, [initme], initfrom)
792-
793-
val,cov = vardict[initme]
794-
795-
# fill in the variable node data value
796-
vnd.val[1] = val
797-
#calculate and fill in covariance
798-
vnd.bw = cov
799-
800-
vnd.initialized = true
801-
#fill in ppe as mean
802-
Xc = getCoordinates(getVariableType(xi), val)
803-
ppe = MeanMaxPPE(:parametric, Xc, Xc, Xc)
804-
getPPEDict(xi)[:parametric] = ppe
805-
806-
# updateVariableSolverData!(dfg, xi, solveKey, true; warn_if_absent=false)
807-
# updateVariableSolverData!(dfg, xi.label, getSolverData(xi, solveKey), :graphinit, true, Symbol[]; warn_if_absent=false)
808-
else
809-
result = nothing
810-
end
811-
812-
return result#isInitialized(xi, solveKey)
813-
end
814-
815-
## ================================================================================================
816-
## Experimental specialized dispatch for Mixture
817-
## ================================================================================================
818-
# To sort out how to dispatch on specialized functions.
819-
# related to #931 and #1069
820-
821-
struct MaxMixture <: AbstractMaxMixtureSolver
822-
p::Vector{Float64}
823-
# the chosen component to be used for the optimization
824-
choice::Base.RefValue{Int}
825-
end
826-
827-
function getMeasurementParametric(s::Mixture{N,F,S,T}) where {N,F,S,T}
828-
meas = map(c->getMeasurementParametric(c)[1], values(s.components))
829-
= map(c->getMeasurementParametric(c)[2], values(s.components))
830-
return meas, iΣ
831-
end
832-
833-
function _calcFactorMahalanobis(cfp, meas, iΣ, variables...)
834-
res = cfp.calcfactor!(meas, variables...)
835-
r = res' ** res
836-
return r
837-
end
838-
839-
# DEV NOTE: function with other options including select once and use
840-
# function (cfp::CalcFactorMahalanobis{<:CalcFactor, MaxMixture})(variables...)
841-
# if cfp.specialAlg.choice[] == 0
842-
# #calculate all mixture options
843-
# r = [_calcFactorMahalanobis(cfp, cfp.meas[i], cfp.iΣ[i], variables...) for i = 1:length(cfp.meas)]
844-
845-
# p = cfp.specialAlg.p
846778

847-
# k = size(cfp.iΣ[1], 2)
848-
# # α = 1 ./ sqrt.(2pi .* k .* det.(inv.(cfp.iΣ)))
849-
# α = sqrt.(det.(cfp.iΣ) ./ ((2pi)^k))
850-
851-
# # mm, at = findmax(α .* p .* exp.(-0.5 .* r))
852-
# # mm = sum(α .* p .* exp.(-0.5 .* r) )
853-
854-
# mm, at = findmin( 0.5 .* r .- log.(α .* p))
855-
# # mm = -log(sum(α .* p .* exp.(-0.5 .* r) ))
856-
# # return mm + maximum(log.(α .* p))
857-
858-
# cfp.specialAlg.choice[] = at
859-
860-
# return r[at]
861-
862-
# else
863-
# at = cfp.specialAlg.choice[]
864-
# return _calcFactorMahalanobis(cfp, cfp.meas[at], cfp.iΣ[at], variables...)
865-
# end
866-
867-
# end
868-
869-
function (cfp::CalcFactorMahalanobis{N, MaxMixture})(variables...) where N
870-
871-
r = [_calcFactorMahalanobis(cfp, cfp.meas[i], cfp.iΣ[i], variables...) for i = 1:length(cfp.meas)]
872-
873-
p = cfp.specialAlg.p
874-
875-
k = size(cfp.iΣ[1], 2)
876-
# α = 1 ./ sqrt.(2pi .* k .* det.(inv.(cfp.iΣ)))
877-
α = sqrt.(det.(cfp.iΣ) ./ ((2pi)^k))
878-
879-
mm, at = findmin(r .- log.(α .* p))
880-
# mm = -log(sum(α .* p .* exp.(-0.5 .* r) ))
881-
return mm + maximum(log.(α .* p))
882-
883-
end
884-
885-
886-
## ================================================================================================
887-
## Experimental specialised dispatch for multihypo and nullhypo
888-
## ================================================================================================
889-
#TODO better dispatch
890-
891-
struct MaxMultihypo <: AbstractMaxMixtureSolver
892-
multihypo::Vector{Float64}
893-
end
894-
struct MaxNullhypo <: AbstractMaxMixtureSolver
895-
nullhypo::Float64
896-
end
897-
898-
function (cfp::CalcFactorMahalanobis{N, MaxMultihypo})(X1, L1, L2) where N
899-
mh = cfp.specialAlg.multihypo
900-
@assert length(mh) == 3 "multihypo $mh not supported with parametric, length should be 3"
901-
@assert mh[1] == 0 "multihypo $mh not supported with parametric, first should be 0"
902-
903-
#calculate both multihypo options
904-
r1 = cfp(X1, L1)
905-
r2 = cfp(X1, L2)
906-
r = [r1, r2]
907-
908-
# hacky multihypo to start of with
909-
mm, at = findmin(r .* (1 .- mh[2:end]))
910-
nat = at == 1 ? 1 : 2
911-
k = length(X1)*one(r1) * 1e-3
912-
return r[at] + r[nat]*k
913-
914-
end
915-
916-
function (cfp::CalcFactorMahalanobis{N, MaxNullhypo})(X1, X2) where N
917-
nh = cfp.specialAlg.nullhypo
918-
@assert nh > 0 "nullhypo $nh not as expected"
919-
920-
#calculate factor residual
921-
res = cfp.calcfactor!(cfp.meas[1], X1, X2)
922-
r1 = res' * cfp.* res
923-
924-
# compare to uniform nullhypo
925-
r2 = length(res)*one(r1)
926-
r = [r1,r2]
927-
mm, at = findmin(r .* [nh, (1-nh)])
928-
929-
residual = at == 1 ? r1 : r1*1e-3
930-
931-
return residual
932-
933-
# rand residual option
934-
# idx = rand(Categorical([(1-nh), nh]))
935-
# nh == 0.05 && cfp.varOrder==[:x1,:l1] && println("$idx -> $(r1.value), $r2")
936-
# return r[idx]
937-
938-
end
779+
#

0 commit comments

Comments
 (0)