Skip to content

Commit 4150b95

Browse files
committed
add few tree tests (API)
1 parent 9abed88 commit 4150b95

File tree

5 files changed

+124
-56
lines changed

5 files changed

+124
-56
lines changed

src/CanonicalGraphExamples.jl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
export loadCanonicalFG_Kaess, loadCanonicalFG_TestSymbolic
3+
4+
5+
"""
6+
$SIGNATURES
7+
8+
Canonical example from literature, Kaess, et al.: ISAM2, IJRR, 2011.
9+
10+
Notes
11+
- Paper variable ordering: p = [:l1;:l2;:x1;:x2;:x3]
12+
"""
13+
function loadCanonicalFG_Kaess()
14+
fg = initfg()
15+
16+
addVariable!(fg,:x1, ContinuousScalar)
17+
addFactor!(fg, [:x1;], Prior(Normal()))
18+
19+
20+
addVariable!(fg,:x2, ContinuousScalar)
21+
addFactor!(fg,[:x1, :x2], LinearConditional(Normal()))
22+
23+
addVariable!(fg, :x3, ContinuousScalar)
24+
addFactor!(fg,[:x2,:x3],LinearConditional(Normal()))
25+
26+
addVariable!(fg, :l1, ContinuousScalar)
27+
addFactor!(fg, [:x1,:l1], LinearConditional(Normal()) )
28+
addFactor!(fg, [:x2,:l1], LinearConditional(Normal()) )
29+
30+
addVariable!(fg, :l2, ContinuousScalar)
31+
addFactor!(fg, [:x3,:l2], LinearConditional(Normal()))
32+
33+
return fg
34+
end
35+
36+
37+
"""
38+
$SIGNATURES
39+
40+
Canonical example from literature, Kaess, et al.: ISAM2, IJRR, 2011.
41+
42+
Notes
43+
- Paper variable ordering: p = [:l1;:l2;:x1;:x2;:x3]
44+
"""
45+
function loadCanonicalFG_TestSymbolic()
46+
fg = initfg()
47+
48+
addVariable!(fg, :x1, ContinuousScalar)
49+
addVariable!(fg, :x2, ContinuousScalar)
50+
addVariable!(fg, :x3, ContinuousScalar)
51+
addVariable!(fg, :x4, ContinuousScalar)
52+
addVariable!(fg, :x5, ContinuousScalar)
53+
addVariable!(fg, :l1, ContinuousScalar)
54+
addVariable!(fg, :l2, ContinuousScalar)
55+
addVariable!(fg, :l3, ContinuousScalar)
56+
57+
addFactor!(fg, [:x1;:l1], LinearConditional(Normal()))
58+
addFactor!(fg, [:x1;:x2], LinearConditional(Normal()))
59+
addFactor!(fg, [:x2;:l1], LinearConditional(Normal()))
60+
addFactor!(fg, [:x2;:x3], LinearConditional(Normal()))
61+
addFactor!(fg, [:x3;:x4], LinearConditional(Normal()))
62+
addFactor!(fg, [:x4;:l2], LinearConditional(Normal()))
63+
addFactor!(fg, [:x4;:x5], LinearConditional(Normal()))
64+
addFactor!(fg, [:l2;:x5], LinearConditional(Normal()))
65+
addFactor!(fg, [:x4;:l3], LinearConditional(Normal()))
66+
addFactor!(fg, [:x5;:l3], LinearConditional(Normal()))
67+
68+
return fg
69+
end

src/IncrementalInference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ include("Factors/Sphere1D.jl")
548548
include("AdditionalUtils.jl")
549549
include("SolverAPI.jl")
550550

551+
include("CanonicalGraphExamples.jl")
551552
include("Deprecated.jl")
552553

553554
exportimg(pl) = error("Please do `using Gadfly` before IncrementalInference is used to allow image export.")

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ end
4040

4141
include("testBasicForwardConvolve.jl")
4242

43-
4443
include("testFactorMetadata.jl")
4544

45+
include("testJunctionTreeConstruction.jl")
46+
4647
include("testBasicCSM.jl")
4748

4849
include("testCliqueFactors.jl")

test/testJunctionTree2.jl

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

test/testJunctionTreeConstruction.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# another tree test
2+
3+
using IncrementalInference
4+
using Test
5+
6+
7+
@testset "Variable ordering Bayes tree member check." begin
8+
9+
fg = loadCanonicalFG_Kaess()
10+
# Choose specific variable ordering and perform check.
11+
vo = [:l1, :l2, :x1, :x2, :x3]
12+
tree = buildTreeFromOrdering!(fg, vo)
13+
@test vo == tree.variableOrder
14+
@test vo == getVariableOrder(tree)
15+
@test vo == getEliminationOrder(tree)
16+
17+
end
18+
19+
20+
@testset "Test tree formation and consistent APIs" begin
21+
22+
fg = loadCanonicalFG_TestSymbolic()
23+
24+
#writeGraphPdf(fg, show=true)
25+
26+
eo = [:x1; :l3; :l1; :x5; :x2; :l2; :x4; :x3]
27+
28+
tree = buildTreeFromOrdering!(fg,eo)
29+
# drawTree(tree, show=true)
30+
31+
@warn "TODO, complete test on tree formation"
32+
33+
34+
## test variable order APIs consistent, see issue 499
35+
36+
vo = getEliminationOrder(fg)
37+
tree1 = resetBuildTreeFromOrder!(fg, vo)
38+
# drawTree(tree1, show=true)
39+
40+
tree2 = wipeBuildNewTree!(fg)
41+
# drawTree(tree2, show=true)
42+
43+
@test getVariableOrder(tree1) == getVariableOrder(tree1)
44+
45+
end
46+
47+
48+
49+
50+
51+
52+
#

0 commit comments

Comments
 (0)