Skip to content

Commit ab750b3

Browse files
authored
Merge pull request #1769 from JuliaRobotics/23Q3/fix/derel
wip fixing DERelative
2 parents 7b32292 + 8259e2c commit ab750b3

File tree

9 files changed

+194
-148
lines changed

9 files changed

+194
-148
lines changed

NEWS.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Additional NEWS on IncrementalInference.jl Releases
1+
# NEWS on IncrementalInference.jl Releases
22

33
Currently general maintenance and bug fix changes are mostly tracked via Github Integrations. E.g. see Milestones along with Label filters to quickly find specific issues.
44
- https://github.com/JuliaRobotics/IncrementalInference.jl/milestones?state=closed
@@ -13,8 +13,11 @@ The list below highlights breaking changes according to normal semver workflow -
1313

1414
# Changes in v0.34
1515

16-
- Start transition to Manopt.jl via Riemannian Levenberg Marquart.
16+
- Start transition to Manopt.jl via Riemannian Levenberg-Marquart.
1717
- Deprecate `AbstractRelativeRoots`.
18+
- Standardization improvements surrounding weakdeps code extensions.
19+
- Code quality improvements along wiht refactoring and reorganizing of file names and locations.
20+
- Restoring `DERelative` factors, although further fixes necessary beyond anticipated patch release v0.34.1.
1821

1922
# Changes in v0.33
2023

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ IncrInfrInteractiveUtilsExt = "InteractiveUtils"
6565
IncrInfrInterpolationsExt = "Interpolations"
6666

6767
[compat]
68-
ApproxManifoldProducts = "0.7"
68+
ApproxManifoldProducts = "0.7, 0.8"
6969
BSON = "0.2, 0.3"
7070
BlockArrays = "0.16"
7171
Combinatorics = "1.0"

ext/IncrInfrDiffEqFactorExt.jl

Lines changed: 94 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using Dates
99

1010
using IncrementalInference
1111
import IncrementalInference: getSample, getManifold, DERelative
12+
import IncrementalInference: sampleFactor
1213

1314
using DocStringExtensions
1415

@@ -94,12 +95,12 @@ end
9495
#
9596
#
9697

97-
# Xtra splat are variable points (X3::Matrix, X4::Matrix,...)
98+
# n-ary factor: Xtra splat are variable points (X3::Matrix, X4::Matrix,...)
9899
function _solveFactorODE!(measArr, prob, u0pts, Xtra...)
99-
# should more variables be included in calculation
100+
# happens when more variables (n-ary) must be included in DE solve
100101
for (xid, xtra) in enumerate(Xtra)
101102
# update the data register before ODE solver calls the function
102-
prob.p[xid + 1][:] = Xtra[xid][:]
103+
prob.p[xid + 1][:] = xtra[:]
103104
end
104105

105106
# set the initial condition
@@ -111,47 +112,47 @@ function _solveFactorODE!(measArr, prob, u0pts, Xtra...)
111112
return sol
112113
end
113114

114-
getSample(cf::CalcFactor{<:DERelative}) = error("getSample(::CalcFactor{<:DERelative}) must still be implemented in new IIF design")
115+
# # # output for AbstractRelative is tangents (but currently we working in coordinates for integration with DiffEqs)
116+
# # # FIXME, how to consolidate DERelative with parametric solve which currently only goes through getMeasurementParametric
117+
# function getSample(cf::CalcFactor{<:DERelative})
118+
# #
119+
# oder = cf.factor
120+
121+
# # how many trajectories to propagate?
122+
# # @show getLabel(cf.fullvariables[2]), getDimension(cf.fullvariables[2])
123+
# meas = zeros(getDimension(cf.fullvariables[2]))
124+
125+
# # pick forward or backward direction
126+
# # set boundary condition
127+
# u0pts = if cf.solvefor == 1
128+
# # backward direction
129+
# prob = oder.backwardProblem
130+
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
131+
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[1]))),
132+
# )
133+
# # FIXME use ccw.varValsAll containter?
134+
# (getBelief(cf.fullvariables[2]) |> getPoints)[cf._sampleIdx]
135+
# else
136+
# # forward backward
137+
# prob = oder.forwardProblem
138+
# # buffer manifold operations for use during factor evaluation
139+
# addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
140+
# convert(Tuple, getManifold(getVariableType(cf.fullvariables[2]))),
141+
# )
142+
# # FIXME use ccw.varValsAll containter?
143+
# (getBelief(cf.fullvariables[1]) |> getPoints)[cf._sampleIdx]
144+
# end
145+
146+
# # solve likely elements
147+
# # TODO, does this respect hyporecipe ???
148+
# # TBD check if cf._legacyParams == ccw.varValsAll???
149+
# idxArr = (k -> cf._legacyParams[k][cf._sampleIdx]).(1:length(cf._legacyParams))
150+
# _solveFactorODE!(meas, prob, u0pts, _maketuplebeyond2args(idxArr...)...)
151+
# # _solveFactorODE!(meas, prob, u0pts, i, _maketuplebeyond2args(cf._legacyParams...)...)
152+
153+
# return meas, diffOp
154+
# end
115155

116-
# FIXME see #1025, `multihypo=` will not work properly yet
117-
function sampleFactor(cf::CalcFactor{<:DERelative}, N::Int = 1)
118-
#
119-
oder = cf.factor
120-
121-
# how many trajectories to propagate?
122-
# @show getLabel(cf.fullvariables[2]), getDimension(cf.fullvariables[2])
123-
meas = [zeros(getDimension(cf.fullvariables[2])) for _ = 1:N]
124-
125-
# pick forward or backward direction
126-
# set boundary condition
127-
u0pts = if cf.solvefor == 1
128-
# backward direction
129-
prob = oder.backwardProblem
130-
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
131-
convert(Tuple, getManifold(getVariableType(cf.fullvariables[1]))),
132-
)
133-
getBelief(cf.fullvariables[2]) |> getPoints
134-
else
135-
# forward backward
136-
prob = oder.forwardProblem
137-
# buffer manifold operations for use during factor evaluation
138-
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
139-
convert(Tuple, getManifold(getVariableType(cf.fullvariables[2]))),
140-
)
141-
getBelief(cf.fullvariables[1]) |> getPoints
142-
end
143-
144-
# solve likely elements
145-
for i = 1:N
146-
# TODO, does this respect hyporecipe ???
147-
idxArr = (k -> cf._legacyParams[k][i]).(1:length(cf._legacyParams))
148-
_solveFactorODE!(meas[i], prob, u0pts[i], _maketuplebeyond2args(idxArr...)...)
149-
# _solveFactorODE!(meas, prob, u0pts, i, _maketuplebeyond2args(cf._legacyParams...)...)
150-
end
151-
152-
return map(x -> (x, diffOp), meas)
153-
end
154-
# getDimension(oderel.domain)
155156

156157
# NOTE see #1025, CalcFactor should fix `multihypo=` in `cf.__` fields; OBSOLETE
157158
function (cf::CalcFactor{<:DERelative})(measurement, X...)
@@ -197,6 +198,56 @@ function (cf::CalcFactor{<:DERelative})(measurement, X...)
197198
return res
198199
end
199200

201+
202+
203+
204+
## =========================================================================
205+
## MAYBE legacy
206+
207+
# FIXME see #1025, `multihypo=` will not work properly yet
208+
function IncrementalInference.sampleFactor(cf::CalcFactor{<:DERelative}, N::Int = 1)
209+
#
210+
oder = cf.factor
211+
212+
# how many trajectories to propagate?
213+
# @show getLabel(cf.fullvariables[2]), getDimension(cf.fullvariables[2])
214+
meas = [zeros(getDimension(cf.fullvariables[2])) for _ = 1:N]
215+
216+
# pick forward or backward direction
217+
# set boundary condition
218+
u0pts = if cf.solvefor == 1
219+
# backward direction
220+
prob = oder.backwardProblem
221+
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
222+
convert(Tuple, getManifold(getVariableType(cf.fullvariables[1]))),
223+
)
224+
getBelief(cf.fullvariables[2]) |> getPoints
225+
else
226+
# forward backward
227+
prob = oder.forwardProblem
228+
# buffer manifold operations for use during factor evaluation
229+
addOp, diffOp, _, _ = AMP.buildHybridManifoldCallbacks(
230+
convert(Tuple, getManifold(getVariableType(cf.fullvariables[2]))),
231+
)
232+
getBelief(cf.fullvariables[1]) |> getPoints
233+
end
234+
235+
# solve likely elements
236+
for i = 1:N
237+
# TODO, does this respect hyporecipe ???
238+
idxArr = (k -> cf._legacyParams[k][i]).(1:length(cf._legacyParams))
239+
_solveFactorODE!(meas[i], prob, u0pts[i], _maketuplebeyond2args(idxArr...)...)
240+
# _solveFactorODE!(meas, prob, u0pts, i, _maketuplebeyond2args(cf._legacyParams...)...)
241+
end
242+
243+
return map(x -> (x, diffOp), meas)
244+
end
245+
# getDimension(oderel.domain)
246+
247+
248+
249+
250+
200251
## the function
201252
# ode.problem.f.f
202253

src/IncrementalInference.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ include("entities/FactorOperationalMemory.jl")
130130
include("Factors/GenericMarginal.jl")
131131
# Special belief types for sampling as a distribution
132132
include("entities/AliasScalarSampling.jl")
133-
include("entities/OptionalDensities.jl") # used in BeliefTypes.jl::SamplableBeliefs
133+
include("entities/ExtDensities.jl") # used in BeliefTypes.jl::SamplableBeliefs
134+
include("entities/ExtFactors.jl")
134135
include("entities/BeliefTypes.jl")
135136

136137
include("services/HypoRecipe.jl")
@@ -234,7 +235,7 @@ include("services/SolverAPI.jl")
234235
# Symbolic tree analysis files.
235236
include("services/AnalysisTools.jl")
236237

237-
# optional densities on weakdeps
238+
# extension densities on weakdeps
238239
include("Serialization/entities/SerializingOptionalDensities.jl")
239240
include("Serialization/services/SerializingOptionalDensities.jl")
240241

src/entities/OptionalDensities.jl renamed to src/entities/ExtDensities.jl

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,6 @@ struct LevelSetGridNormal{T <: Real, H <: HeatmapGridDensity}
7272
heatmap::H
7373
end
7474

75-
##
76-
77-
"""
78-
$TYPEDEF
79-
80-
Build a full ODE solution into a relative factor to condense possible sensor data into a relative transformation,
81-
but keeping the parameter estimation process fluid. Assumes first and second variable in order
82-
are of same dimension and compatible manifolds, such that ODE runs from Xi to Xi+1 on all
83-
dimensions. Internal state vector can be decoupled onto different domain as needed.
84-
85-
Notes
86-
- Based on DifferentialEquations.jl
87-
- `getSample` step does the `solve(ODEProblem)` step.
88-
- `tspan` is taken from variables only once at object construction -- i.e. won't detect changed timestamps.
89-
- Regular factor evaluation is done as full dimension `AbstractRelativeRoots`, and is basic linear difference.
90-
91-
DevNotes
92-
- FIXME see 1025, `multihypo=` will not yet work.
93-
- FIXME Lots of consolidation and standardization to do, see RoME.jl #244 regarding Manifolds.jl.
94-
- TODO does not yet handle case where a factor spans across two timezones.
95-
"""
96-
struct DERelative{T <: InferenceVariable, P, D} <: AbstractRelativeMinimize
97-
domain::Type{T}
98-
forwardProblem::P
99-
backwardProblem::P
100-
""" second element of this data tuple is additional variables that will be passed down as a parameter """
101-
data::D
102-
specialSampler::Function
103-
end
104-
10575

10676
##
10777

src/entities/ExtFactors.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
"""
4+
$TYPEDEF
5+
6+
Build a full ODE solution into a relative factor to condense possible sensor data into a relative transformation,
7+
but keeping the parameter estimation process fluid. Assumes first and second variable in order
8+
are of same dimension and compatible manifolds, such that ODE runs from Xi to Xi+1 on all
9+
dimensions. Internal state vector can be decoupled onto different domain as needed.
10+
11+
Notes
12+
- Based on DifferentialEquations.jl
13+
- `getSample` step does the `solve(ODEProblem)` step.
14+
- `tspan` is taken from variables only once at object construction -- i.e. won't detect changed timestamps.
15+
- Regular factor evaluation is done as full dimension `AbstractRelativeRoots`, and is basic linear difference.
16+
17+
DevNotes
18+
- FIXME see 1025, `multihypo=` will not yet work.
19+
- FIXME Lots of consolidation and standardization to do, see RoME.jl #244 regarding Manifolds.jl.
20+
- TODO does not yet handle case where a factor spans across two timezones.
21+
"""
22+
struct DERelative{T <: InferenceVariable, P, D} <: AbstractRelativeMinimize
23+
domain::Type{T}
24+
forwardProblem::P
25+
backwardProblem::P
26+
""" second element of this data tuple is additional variables that will be passed down as a parameter """
27+
data::D
28+
specialSampler::Function
29+
end

src/entities/OptionalDensitiesSerialization.jl

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/runtests.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ TEST_GROUP = get(ENV, "IIF_TEST_GROUP", "all")
55
# temporarily moved to start (for debugging)
66
#...
77
if TEST_GROUP in ["all", "tmp_debug_group"]
8+
include("testSpecialOrthogonalMani.jl")
9+
include("testDERelative.jl")
810
include("testMultiHypo3Door.jl")
911
include("priorusetest.jl")
1012
end
1113

1214
if TEST_GROUP in ["all", "basic_functional_group"]
13-
# more frequent stochasic failures from numerics
15+
# more frequent stochasic failures from numerics
1416
include("manifolds/manifolddiff.jl")
1517
include("manifolds/factordiff.jl")
1618
include("testSpecialEuclidean2Mani.jl")
1719
include("testEuclidDistance.jl")
1820

1921
# regular testing
2022
include("testSphereMani.jl")
21-
include("testSpecialOrthogonalMani.jl")
2223
include("testBasicManifolds.jl")
2324

2425
# start as basic as possible and build from there
@@ -96,11 +97,6 @@ include("testCircular.jl")
9697
include("testMixtureLinearConditional.jl")
9798
include("testFluxModelsDistribution.jl")
9899
include("testAnalysisTools.jl")
99-
try
100-
include("testDERelative.jl")
101-
catch
102-
@error "[FAILED] Fix testDERelative.jl, likely just requires implementing DiffEqFactorExt.getSample(::CalcFactor{<:DERelative})."
103-
end
104100

105101
include("testBasicParametric.jl")
106102
include("testMixtureParametric.jl")

0 commit comments

Comments
 (0)