Skip to content

Commit 1b77d59

Browse files
committed
fix graphinit point count, compat AMP
1 parent 8325e70 commit 1b77d59

File tree

5 files changed

+99
-18
lines changed

5 files changed

+99
-18
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
4343
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
4444

4545
[compat]
46-
ApproxManifoldProducts = "0.4.14"
46+
ApproxManifoldProducts = "0.4.15"
4747
BSON = "0.2, 0.3"
4848
Combinatorics = "1.0"
4949
DataStructures = "0.16, 0.17, 0.18"

src/FactorGraph.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,18 @@ function setValKDE!(vnd::VariableNodeData,
221221
setinit::Bool=true,
222222
inferdim::Union{Float32, Float64, Int32, Int64}=0 ) where {M,B,L<:AbstractVector}
223223
#
224-
oldbel = getBelief(vnd)
224+
oldBel = getBelief(vnd)
225+
226+
# New infomation might be partial
227+
newBel = replace(oldBel, mkd)
228+
225229
# Set partial dims as Manifold points
226-
ptsArr = AMP.getPoints(mkd, false)
227-
oldPts = getVal(vnd)
228-
# get partial coord dims
229-
pvec = mkd._partial
230+
ptsArr = AMP.getPoints(newBel, false)
230231

231-
# also set the bandwidth
232-
bws = getBW(mkd)[:,1]
233-
bw_ = getBW
232+
# also get the bandwidth
233+
bws = getBandwidth(newBel, false)
234+
235+
# update values in graph
234236
setValKDE!(vnd,ptsArr,bws,setinit,inferdim )
235237
nothing
236238
end

src/services/GraphInit.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ function doautoinit!( dfg::AbstractDFG,
123123
end
124124
# FIXME ensure a product of only partial densities and returned pts are put to proper dimensions
125125
bel,inferdim = propagateBelief(dfg, getVariable(dfg,vsym), getFactor.(dfg,useinitfct), solveKey=solveKey, logger=logger, N=N)
126+
# while the propagate step might allow large point counts, the graph should stay restricted to N
127+
bel_ = Npts(bel) == getSolverParams(dfg).N ? bel : resample(bel, getSolverParams(dfg).N)
126128
# @info "MANIFOLD IS" bel.manifold isPartial(bel) string(bel._partial) string(getPoints(bel, false)[1])
127-
setValKDE!(xi, bel, true, inferdim, solveKey=solveKey) # getPoints(bel, false)
129+
setValKDE!(xi, bel_, true, inferdim, solveKey=solveKey) # getPoints(bel, false)
128130
# Update the estimates (longer DFG function used so cloud is also updated)
129131
setVariablePosteriorEstimates!(dfg, xi.label, solveKey)
130132
# Update the data in the event that it's not local

src/services/HeatmapSampler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function HeatmapDensityRegular( data::AbstractMatrix{<:Real},
7272
# constuct a pre-density from which to draw intermediate samples
7373
density_ = fitKDE(support_, weights_, domain...; bw_factor=bw_factor)
7474
pts_preIS, = sample(density_, N)
75-
@show size(pts_preIS)
75+
# @show size(pts_preIS)
7676

7777
@cast vec_preIS[j][i] := pts_preIS[i,j]
7878

test/testSpecialEuclidean2Mani.jl

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ vnd = getVariableSolverData(fg, :x1)
219219
end
220220

221221

222-
@testset "test propagateBelief w HeatmapSampler and init for PartialPriorPassThrough" begin
222+
@testset "test propagateBelief w HeatmapSampler and init for PartialPriorPassThrough w Priors" begin
223223
##
224224

225225
fg = initfg()
@@ -229,7 +229,7 @@ v0 = addVariable!(fg, :x0, SpecialEuclidean2)
229229
img_ = rand(10,10).+5.0
230230
x_,y_ = ([-9:2.0:9;],[-9:2.0:9;])
231231

232-
hmd = HeatmapDensityRegular(img_, (x_,y_), 5.5, 0.1, N=1000)
232+
hmd = HeatmapDensityRegular(img_, (x_,y_), 5.5, 0.1, N=120)
233233
pthru = PartialPriorPassThrough(hmd, (1,2))
234234

235235
# test without nullhyp
@@ -240,7 +240,7 @@ f0 = addFactor!(fg, [:x0], pthru, graphinit=false)
240240
bel, infd = propagateBelief(fg, v0, [f0])
241241

242242
@test isPartial(bel)
243-
@test length(getPoints(bel)) == 1000
243+
@test length(getPoints(bel)) == 120
244244

245245

246246
## repeat test with nullhypo
@@ -260,14 +260,14 @@ bel, infd = propagateBelief(fg, v0, [f0])
260260

261261
doautoinit!(fg, :x0)
262262

263-
@test length(getPoints(getBelief(fg, :x0))) == 1000
264-
@info "PassThrough transfers the full point count to the graph, unless a product is calculated during the propagateBelief step."
263+
@test length(getPoints(getBelief(fg, :x0))) == getSolverParams(fg).N # 120
264+
# @info "PassThrough transfers the full point count to the graph, unless a product is calculated during the propagateBelief step."
265265

266266
##
267267

268268
solveGraph!(fg);
269269

270-
@test 1000 == length(getPoints(fg, :x0))
270+
@test 120 == length(getPoints(fg, :x0))
271271

272272
@warn "must still check if bandwidths are recalculated on many points (not necessary), or lifted from this case single prior"
273273

@@ -286,7 +286,7 @@ prp, infd = propagateBelief(fg, v0, [f0;f1])
286286

287287
## check that solve corrects the point count on graph variable
288288

289-
@test 1000 == length(getPoints(fg, :x0))
289+
@test 120 == length(getPoints(fg, :x0))
290290

291291
solveGraph!(fg);
292292

@@ -299,4 +299,81 @@ end
299299

300300

301301

302+
303+
@testset "test point count on propagate, solve, init for PartialPriorPassThrough w Relative" begin
304+
##
305+
306+
fg = initfg()
307+
308+
v0 = addVariable!(fg, :x0, SpecialEuclidean2)
309+
310+
img_ = rand(10,10).+5.0
311+
x_,y_ = ([-9:2.0:9;],[-9:2.0:9;])
312+
313+
hmd = HeatmapDensityRegular(img_, (x_,y_), 5.5, 0.1, N=120)
314+
pthru = PartialPriorPassThrough(hmd, (1,2))
315+
316+
# test without nullhyp
317+
f0 = addFactor!(fg, [:x0], pthru, graphinit=false)
318+
319+
## test the inference functions
320+
addVariable!(fg, :x1, SpecialEuclidean2)
321+
mp = ManifoldPrior(SpecialEuclidean(2), ProductRepr(@MVector([0.0,0.0]), @MMatrix([1.0 0.0; 0.0 1.0])), MvNormal([0.01, 0.01, 0.01]))
322+
f1 = addFactor!(fg, [:x1], mp, graphinit=false)
323+
324+
doautoinit!(fg, :x1)
325+
326+
## connect with relative and check calculation size on x0
327+
328+
mf = ManifoldFactor(SpecialEuclidean(2), MvNormal([1,2,pi/4], [0.01,0.01,0.01]))
329+
f2 = addFactor!(fg, [:x0, :x1], mf, graphinit=false)
330+
331+
##
332+
333+
bel, infd = propagateBelief(fg, v0, [f0;f2])
334+
335+
@test !isPartial(bel)
336+
@test getSolverParams(fg).N == length(getPoints(bel))
337+
338+
## check other functions
339+
340+
solveTree!(fg);
341+
342+
@test getSolverParams(fg).N == length(getPoints(fg, :x0))
343+
@test getSolverParams(fg).N == length(getPoints(fg, :x1))
344+
345+
346+
## and check that initAll! works the same (different init sequences may change code execution path)
347+
348+
fg = initfg()
349+
v0 = addVariable!(fg, :x0, SpecialEuclidean2)
350+
img_ = rand(10,10).+5.0
351+
x_,y_ = ([-9:2.0:9;],[-9:2.0:9;])
352+
hmd = HeatmapDensityRegular(img_, (x_,y_), 5.5, 0.1, N=120)
353+
pthru = PartialPriorPassThrough(hmd, (1,2))
354+
f0 = addFactor!(fg, [:x0], pthru, graphinit=false)
355+
addVariable!(fg, :x1, SpecialEuclidean2)
356+
mp = ManifoldPrior(SpecialEuclidean(2), ProductRepr(@MVector([0.0,0.0]), @MMatrix([1.0 0.0; 0.0 1.0])), MvNormal([0.01, 0.01, 0.01]))
357+
f1 = addFactor!(fg, [:x1], mp, graphinit=false)
358+
mf = ManifoldFactor(SpecialEuclidean(2), MvNormal([1,2,pi/4], [0.01,0.01,0.01]))
359+
f2 = addFactor!(fg, [:x0, :x1], mf, graphinit=false)
360+
361+
##
362+
363+
bel, infd = propagateBelief(fg, v0, [f0;f2])
364+
365+
@test !isPartial(bel)
366+
@test getSolverParams(fg).N == length(getPoints(bel))
367+
368+
##
369+
370+
initAll!(fg)
371+
372+
@test getSolverParams(fg).N == length(getPoints(fg, :x0))
373+
@test getSolverParams(fg).N == length(getPoints(fg, :x1))
374+
375+
##
376+
end
377+
378+
302379
#

0 commit comments

Comments
 (0)