Skip to content

Commit 5de4ee9

Browse files
authored
Merge pull request #1345 from JuliaRobotics/21Q3/maint/upstgenerators
Standardize to TranslationGroup
2 parents 1704698 + f1ef4b2 commit 5de4ee9

File tree

11 files changed

+62
-38
lines changed

11 files changed

+62
-38
lines changed

src/FGOSUtils.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ function fifoFreeze!(dfg::AbstractDFG)
235235
end
236236

237237

238+
DFG.getPoint(typ::InferenceVariable, w...;kw...) = getPoint(typeof(typ), w...;kw...)
239+
DFG.getCoordinates(typ::InferenceVariable, w...;kw...) = getCoordinates(typeof(typ), w...;kw...)
240+
241+
# WIP
242+
# _getMeasurementRepresentation(::AbstractPrior, coord::AbstractVector{<:Number}) =
243+
238244

239245
"""
240246
$SIGNATURES
@@ -267,7 +273,7 @@ function calcPPE( var::DFGVariable,
267273
# calculate point
268274

269275
## TODO make PPE only use getCoordinates for now (IIF v0.25)
270-
Pme_ = getCoordinates(typeof(varType),Pme)
276+
Pme_ = getCoordinates(varType,Pme)
271277
# Pma_ = getCoordinates(M,Pme)
272278

273279
# suggested, max, mean, current time

src/FactorGraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ function prepgenericconvolution(Xi::Vector{<:DFGVariable},
629629
gradients = FactorGradientsCached!(usrfnc, tuple(varTypes[hypoidxs]...), measurement_, tuple(pts_[hypoidxs]...), _blockRecursion=true);
630630
end
631631
catch e
632-
@warn "Unable to create measurements and gradients for $usrfnc during prep of CCW, falling back on no-partial information assumption. Enable @debug printing to see the error."
632+
@warn "Unable to create measurements and gradients for $usrfnc during prep of CCW, falling back on no-partial information assumption. Enable ENV[\"JULIA_DEBUG\"] = \"IncrementalInference\" for @debug printing to see the error."
633633
@debug(e)
634634
end
635635

src/Factors/EuclidDistance.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ end
1414

1515
EuclidDistance(::UniformScaling=LinearAlgebra.I) = EuclidDistance(Normal())
1616

17-
getManifold(::InstanceType{EuclidDistance}) = Euclidean(1)
17+
# consider a different group?
18+
getManifold(::InstanceType{EuclidDistance}) = TranslationGroup(1)
1819
getDimension(::InstanceType{<:EuclidDistance}) = 1
1920

2021

@@ -30,7 +31,7 @@ function (s::CalcFactor{<:EuclidDistance})(z, x1, x2)
3031
end
3132

3233

33-
Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{EuclidDistance}) = Manifolds.Euclidean(1)
34+
Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{EuclidDistance}) = Manifolds.TranslationGroup(1)
3435

3536

3637
"""

src/Factors/LinearRelative.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050

5151

5252

53-
Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{LinearRelative{N}}) where N = Manifolds.Euclidean(N)
53+
Base.convert(::Type{<:MB.AbstractManifold}, ::InstanceType{LinearRelative{N}}) where N = Manifolds.TranslationGroup(N)
5454

5555

5656

src/IncrementalInference.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ import DistributedFactorGraphs: rebuildFactorMetadata!
6969
import DistributedFactorGraphs: getDimension, getManifold, getPointType, getPointIdentity
7070
import DistributedFactorGraphs: getPPE, getPPEDict
7171
import DistributedFactorGraphs: getFactorOperationalMemoryType
72+
import DistributedFactorGraphs: getPoint, getCoordinates
73+
7274

7375
# will be deprecated in IIF
7476
import DistributedFactorGraphs: isSolvable

src/ParametricUtils.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,37 @@ end
3939
"""
4040
$SIGNATURES
4141
42-
Returns the parametric measurement for a factor as a tuple (measurement, inverse covariance) for parametric inference (assumign Gaussian).
43-
Defaults to find the parametric measurement at field `Z` followed by `z`.
42+
Returns the parametric measurement for a factor as a tuple (measurement, inverse covariance) for parametric inference (assuming Gaussian).
43+
Defaults to find the parametric measurement at field `Zij`, `Z`, or `z`.
4444
4545
Notes
4646
- Users should overload this method should their factor not default to `.Z<:ParametricType` or `.z<:ParametricType`
47+
- First design choice was to restrict this function to returning coordinates
48+
- See https://github.com/JuliaRobotics/RoME.jl/issues/465
49+
- Pay attention to which tangent space point is used for converting points on a manifold to coordinates,
50+
- Originally written just for Lie Groups to support legacy, but future needs may well alter the design.
51+
- Original design driven by parametric solve and dead reckon tethering.
52+
53+
See also: [`accumulateFactorMeans`](@ref), [`solveFactorParameteric`](@ref)
4754
"""
4855
function getMeasurementParametric end
4956

5057
function getMeasurementParametric(Z)
5158
error("$(typeof(Z)) is not supported, please use non-parametric or open an issue if it should be")
5259
end
5360

54-
function getMeasurementParametric(M::AbstractManifold, Z::Normal)
61+
function getMeasurementParametric(Z::Normal)
5562
meas = mean(Z)
5663
= 1/std(Z)^2
5764
return [meas], reshape([iσ],1,1)
5865
end
5966

60-
function getMeasurementParametric(M::AbstractManifold, Z::MvNormal)
67+
function getMeasurementParametric(Z::MvNormal)
6168
meas = mean(Z)
6269
= invcov(Z)
63-
p_μ = exp(M, identity_element(M), hat(M, identity_element(M), meas))
64-
return p_μ, iΣ
70+
return meas, iΣ
6571
end
6672

67-
getMeasurementParametric(Z::Normal) = getMeasurementParametric(TranslationGroup(1), Z)
68-
getMeasurementParametric(Z::MvNormal) = getMeasurementParametric(TranslationGroup(length(mean(Z))), Z)
69-
7073
# the point `p` on the manifold is the mean
7174
function getMeasurementParametric(s::ManifoldPrior)
7275
meas = s.p
@@ -87,6 +90,7 @@ function getMeasurementParametric(s::AbstractFactor)
8790
else
8891
error("$(typeof(s)) not supported, please use non-parametric or open an issue if it should be")
8992
end
93+
9094
return getMeasurementParametric(Z)
9195
end
9296

@@ -114,6 +118,7 @@ function CalcFactorMahalanobis(fct::DFGFactor)
114118
multihypo = getSolverData(fct).multihypo
115119
nullhypo = getSolverData(fct).nullhypo
116120

121+
# FIXME, type instability, use dispatch instead of if-else
117122
if length(multihypo) > 0
118123
special = MaxMultihypo(multihypo)
119124
elseif nullhypo > 0

src/SolverUtilities.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ function fastnorm(u)
99
@fastmath @inbounds return sqrt(s)
1010
end
1111

12+
1213
"""
1314
$SIGNATURES
1415
1516
Helper function for IIF.getSample, to generate a vector of points regardless of the Manifold and probability density function used.
1617
17-
Related
18+
DevNotes:
19+
- FIXME deprecate to `sample`, see JuliaRobotics/RoME.jl#465
1820
19-
[`getSample`](@ref)
21+
See also: [`getSample`](@ref), [`rand`]
2022
"""
2123
randToPoints(distr::SamplableBelief, N::Int=1) = [rand(distr,1)[:] for i in 1:N]
2224
randToPoints(distr::ManifoldKernelDensity, N::Int=1) = rand(distr,N)
@@ -216,10 +218,10 @@ Related
216218
[`RoME.generateCanonicalFG_Honeycomb!`](@ref), [`accumulateFactorMeans`](@ref), [`getPPE`](@ref)
217219
"""
218220
function _checkVariableByReference( fg::AbstractDFG,
219-
srcLabel::Symbol, # = :x5
220-
destRegex::Regex, # = r"l\d+"
221-
destType::Type{<:InferenceVariable}, # = Point2
222-
factor::AbstractRelative; # = Pose2Poin2BearingRange(...)
221+
srcLabel::Symbol,
222+
destRegex::Regex,
223+
destType::Type{<:InferenceVariable},
224+
factor::AbstractRelative;
223225
srcType::Type{<:InferenceVariable} = getVariableType(fg, srcLabel) |> typeof,
224226
refKey::Symbol=:simulated,
225227
prior = DFG._getPriorType(srcType)( MvNormal(getPPE(fg[srcLabel], refKey).suggested, diagm(ones(getDimension(srcType)))) ),
@@ -245,16 +247,13 @@ function _checkVariableByReference( fg::AbstractDFG,
245247
end
246248

247249
ppe = DFG.MeanMaxPPE(refKey, refVal, refVal, refVal)
248-
# setPPE!(v_n, refKey, DFG.MeanMaxPPE, ppe)
249250

250251
# now check if we already have a landmark at this location
251252
varLms = ls(fg, destRegex) |> sortDFG
252253
ppeLms = getPPE.(getVariable.(fg, varLms), refKey) .|> x->x.suggested
253-
# @show typeof(ppeLms)
254254
errmask = ppeLms .|> x -> norm(x - ppe.suggested) < atol
255255
already = any(errmask)
256256

257-
# @assert sum(errmask) <= 1 "There should be only one landmark at $ppe"
258257
if already
259258
# does exist, ppe, variableLabel
260259
alrLm = varLms[findfirst(errmask)]
@@ -267,9 +266,9 @@ end
267266

268267

269268
function _checkVariableByReference( fg::AbstractDFG,
270-
srcLabel::Symbol, # = :x5
271-
destRegex::Regex, # = r"l\d+"
272-
destType::Type{<:InferenceVariable}, # = Point2
269+
srcLabel::Symbol,
270+
destRegex::Regex,
271+
destType::Type{<:InferenceVariable},
273272
factor::AbstractPrior;
274273
srcType::Type{<:InferenceVariable} = getVariableType(fg, srcLabel) |> typeof,
275274
refKey::Symbol=:simulated,
@@ -293,4 +292,7 @@ function _checkVariableByReference( fg::AbstractDFG,
293292
end
294293

295294

296-
#
295+
296+
297+
298+
#

src/entities/OptionalDensities.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Notes
3131
- Sampling can be more nuanced by injecting a hint, or location of interest:
3232
- Mostly aimed at limiting compute when faced with massive heatmaps, e.g. nav units are 10's but map is ~1e6.
3333
- Density approximation is constructed on Guassian measurement assumption of level set and sigma variation.
34-
- Assume data is on a regular grid on Euclidean(2)
34+
- Assume data is on a regular grid on TranslationGroup(2)
3535
3636
DevNotes:
3737
- Generalize to scalar fields on any Manifold.
@@ -54,7 +54,7 @@ struct HeatmapDensityRegular{T <: Real, H <: Union{<:Function, Nothing}, B <: Un
5454
"""general rule for kernel bandwidths used in construction of density, e.g. 0.7 of domain grid spacing"""
5555
bw_factor::T
5656
"""density function as samplable representation of the data over the domain"""
57-
densityFnc::B # TODO change to ::ManifoldKernelDensity{Euclidean(2),BallTreeDensity}
57+
densityFnc::B # TODO change to ::ManifoldKernelDensity{TranslationGroup(2),BallTreeDensity}
5858
end
5959

6060
(hmd::HeatmapDensityRegular)(w...;kw...) = hmd.densityFnc(w...;kw...)

src/entities/SolverParams.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SolverParams(;dimID::Int=0,
8181
gibbsIters::Int=3,
8282
maxincidence::Int=500,
8383
alwaysFreshMeasurements::Bool=true,
84-
attemptGradients::Bool=false,
84+
attemptGradients::Bool=true,
8585
devParams::Dict{Symbol,String}=Dict{Symbol,String}()
8686
) = begin useMsgLikelihoods==true && @warn "useMsgLikelihoods is under development, use with care, see #1010"
8787
SolverParams( dimID,

src/services/ApproxConv.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ end
244244
"""
245245
$SIGNATURES
246246
247-
Helper function to propagate a parametric estimate along a factor chain.
247+
Helper function to propagate a parametric estimate along a factor chain.
248+
This function takes and returns variable values as coordinates.
248249
249250
Notes
250251
- Not used during MM-iSAM inference.
@@ -276,25 +277,32 @@ function solveFactorParameteric(dfg::AbstractDFG,
276277
# get the measurement point
277278
fctTyp = getFactorType(fct)
278279
mea, _ = getMeasurementParametric(fctTyp)
280+
# should this be coords, tangent, or point
279281
measT = (mea,)
280282

281283
# get variable points
282284
function _getParametric(vari::DFGVariable, key=:default)
283285
# hasp = haskey(getPPEDict(vari), key)
284286
# FIXME use PPE via Manifold points currently in coordinates
285287
# hasp ? getPPE(vari, key).suggested : calcMean(getBelief(vari, key))
286-
calcMean(getBelief(vari, key))
288+
pt = calcMean(getBelief(vari, key))
289+
290+
getCoordinates(getVariableType(vari),pt)
287291
end
288292

289293
# overwrite specific src values from user
290-
prms = _getParametric.(getVariable.(dfg, varLbls), solveKey)
294+
coordVals = _getParametric.(getVariable.(dfg, varLbls), solveKey)
291295
for (srcsym, currval) in srcsym_vals
292-
prms[findfirst(varLbls .== srcsym)] = currval
296+
coordVals[findfirst(varLbls .== srcsym)] = currval
293297
end
294-
pts = tuple(prms...)
298+
crds = tuple(coordVals...)
295299

296-
# do the calculation to find solvefor index using the factor
297-
return _evalFactorTemporary!( fctTyp, varTypes, sfidx, measT, pts; solveKey=solveKey, evaltmpkw... )
300+
pts = tuple(map(t->getPoint(t...), zip(varTypes,crds))...)
301+
302+
# do the calculation to find solvefor index using the factor, as manifold point
303+
pt = _evalFactorTemporary!( fctTyp, varTypes, sfidx, measT, pts; solveKey=solveKey, evaltmpkw... )[1]
304+
305+
return getCoordinates(getVariableType(dfg, trgsym), pt)
298306
end
299307

300308

0 commit comments

Comments
 (0)