Skip to content

Commit daa6cfd

Browse files
committed
fix propagateBelief N, more testing, passThru fix
1 parent 821a64d commit daa6cfd

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

src/Factors/PartialPrior.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
$(TYPEDEF)
55
66
Partial prior belief (absolute data) on any variable, given `<:SamplableBelief` and which dimensions of the intended variable.
7+
8+
Notes
9+
- If using [`AMP.ManifoldKernelDensity`](@ref), don't double partial. Only define the partial in this `PartialPrior` container.
10+
- Future TBD, consider using `AMP.getManifoldPartial` for more general abstraction.
711
"""
812
struct PartialPrior{T <: SamplableBelief,P <: Tuple} <: AbstractPrior
913
Z::T
1014
partial::P
1115
end
1216

13-
function getSample(cf::CalcFactor{<:PartialPrior}, N::Int=1)
14-
ret = Vector{Vector{Float64}}(undef, N)
15-
for i in 1:N
16-
ret[i] = rand(cf.factor.Z,1)[:]
17-
end
18-
(ret, )
19-
end
17+
getManifold(pp::PartialPrior{<:PackedManifoldKernelDensity}) = pp.Z.manifold
18+
19+
getSample(cf::CalcFactor{<:PartialPrior}, N::Int=1) = (randToPoints(cf.factor.Z,N), )
2020

2121

2222
"""

src/GraphProductOperations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function propagateBelief( dfg::AbstractDFG,
1919
factors::AbstractVector{<:DFGFactor};
2020
solveKey::Symbol=:default,
2121
dens = Vector{ManifoldKernelDensity}(),
22-
N::Int=maximum([length(getPoints(getBelief(destvar, solveKey))); getSolverParams(dfg).N]),
22+
N::Int=getSolverParams(dfg).N, #maximum([length(getPoints(getBelief(destvar, solveKey))); getSolverParams(dfg).N]),
2323
needFreshMeasurements::Bool=true,
2424
dbg::Bool=false,
2525
logger=ConsoleLogger() )

test/testBasicGraphs.jl

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -353,32 +353,6 @@ end
353353

354354

355355

356-
@testset "test propagateBelief returning a partial" begin
357-
##
358-
359-
fg = initfg()
360-
361-
v0 = addVariable!(fg, :x0, ContinuousEuclid{2})
362-
363-
pp = PartialPrior(Normal(), (2,))
364-
f0 = addFactor!(fg, [:x0;], pp, graphinit=false)
365-
366-
##
367-
368-
bel, infd = propagateBelief(fg, v0, [f0;])
369-
370-
@test isPartial(bel)
371-
372-
373-
##
374-
end
375-
376-
377-
378-
379-
380-
381-
382356

383357

384358
#

test/testPartialPrior.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Test
44
using IncrementalInference
5+
using Manifolds
56

67
##
78

@@ -20,7 +21,6 @@ getSample(cfo::CalcFactor{<:PartialDim2}, N::Int=1) = ([rand(cfo.factor.Z, 1)[:]
2021
##
2122

2223
@testset "Test partial dimensions on prior are correct" begin
23-
2424
##
2525

2626
fg = initfg()
@@ -48,5 +48,35 @@ predictbelief(fg, :x0, [:x0f1;])
4848
@test true
4949

5050
##
51+
end
52+
53+
54+
55+
@testset "test propagateBelief returning a partial" begin
56+
##
57+
58+
fg = initfg()
59+
60+
v0 = addVariable!(fg, :x0, ContinuousEuclid{2})
61+
62+
pts = [randn(1) for _ in 1:1000];
63+
mkd = manikde!(TranslationGroup(1), pts, bw=[0.1;])
64+
pp = PartialPrior(mkd, (2,))
65+
f0 = addFactor!(fg, [:x0;], pp, graphinit=false)
66+
67+
##
68+
69+
bel, infd = propagateBelief(fg, v0, [f0;])
70+
@test isPartial(bel)
5171

52-
end
72+
##
73+
74+
doautoinit!(fg, :x0)
75+
76+
# check the number of points in the graph value store
77+
@show getSolverParams(fg).N
78+
@test length(getPoints(getBelief(fg, :x0))) == getSolverParams(fg).N
79+
@info "PassThrough factors currently work different and will pass the full N=1000 count through to the graph."
80+
81+
##
82+
end

test/testSpecialEuclidean2Mani.jl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
232+
hmd = HeatmapDensityRegular(img_, (x_,y_), 5.5, 0.1, N=1000)
233233
pthru = PartialPriorPassThrough(hmd, (1,2))
234234

235235
# test without nullhyp
@@ -240,6 +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
243244

244245

245246
## repeat test with nullhypo
@@ -253,9 +254,46 @@ f0 = addFactor!(fg, [:x0], pthru, graphinit=false, nullhypo=0.2)
253254
## test the inference functions
254255

255256
bel, infd = propagateBelief(fg, v0, [f0])
256-
257257
@test isPartial(bel)
258258

259+
##
260+
261+
doautoinit!(fg, :x0)
262+
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."
265+
266+
##
267+
268+
solveGraph!(fg);
269+
270+
@test 1000 == length(getPoints(fg, :x0))
271+
272+
@warn "must still check if bandwidths are recalculated on many points (not necessary), or lifted from this case single prior"
273+
274+
##
275+
276+
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]))
277+
f1 = addFactor!(fg, [:x0], mp, graphinit=false)
278+
279+
@test length(ls(fg, :x0)) == 2
280+
281+
##
282+
283+
prp, infd = propagateBelief(fg, v0, [f0;f1])
284+
285+
@test length(getPoints(prp)) == getSolverParams(fg).N
286+
287+
## check that solve corrects the point count on graph variable
288+
289+
@test 1000 == length(getPoints(fg, :x0))
290+
291+
solveGraph!(fg);
292+
293+
# this number should drop down to usual, 100 at time of writing
294+
@test getSolverParams(fg).N == length(getPoints(fg, :x0))
295+
296+
259297
##
260298
end
261299

0 commit comments

Comments
 (0)