Skip to content

Commit 679ea04

Browse files
committed
add Caesar ring 1D test
1 parent ab471bb commit 679ea04

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

src/CanonicalGraphExamples.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
export loadCanonicalFG_Kaess, loadCanonicalFG_TestSymbolic
2+
export loadCanonicalFG_Kaess, loadCanonicalFG_TestSymbolic, loadCanonicalFG_CaesarRing1D
33

44

55
"""
@@ -37,10 +37,10 @@ end
3737
"""
3838
$SIGNATURES
3939
40-
Canonical example from literature, Kaess, et al.: ISAM2, IJRR, 2011.
40+
Canonical example introduced by Borglab.
4141
4242
Notes
43-
- Paper variable ordering: p = [:l1;:l2;:x1;:x2;:x3]
43+
- Known variable ordering: p = [:x1; :l3; :l1; :x5; :x2; :l2; :x4; :x3]
4444
"""
4545
function loadCanonicalFG_TestSymbolic()
4646
fg = initfg()
@@ -67,3 +67,40 @@ function loadCanonicalFG_TestSymbolic()
6767

6868
return fg
6969
end
70+
71+
72+
73+
"""
74+
$SIGNATURES
75+
76+
Canonical example introduced originally as Caesar Hex Example.
77+
78+
Notes
79+
- Paper variable ordering: p = [:x0;:x2;:x4;:x6;:x1;:l1;:x5;:x3;]
80+
"""
81+
function loadCanonicalFG_CaesarRing1D()
82+
83+
fg = initfg()
84+
85+
addVariable!(fg, :x0, ContinuousScalar)
86+
addVariable!(fg, :x1, ContinuousScalar)
87+
addVariable!(fg, :x2, ContinuousScalar)
88+
addVariable!(fg, :x3, ContinuousScalar)
89+
addVariable!(fg, :x4, ContinuousScalar)
90+
addVariable!(fg, :x5, ContinuousScalar)
91+
addVariable!(fg, :x6, ContinuousScalar)
92+
93+
addFactor!(fg, [:x0], Prior(Normal()))
94+
addFactor!(fg, [:x0;:x1], LinearConditional(Normal()))
95+
addFactor!(fg, [:x1;:x2], LinearConditional(Normal()))
96+
addFactor!(fg, [:x2;:x3], LinearConditional(Normal()))
97+
addFactor!(fg, [:x3;:x4], LinearConditional(Normal()))
98+
addFactor!(fg, [:x4;:x5], LinearConditional(Normal()))
99+
addFactor!(fg, [:x5;:x6], LinearConditional(Normal()))
100+
101+
addVariable!(fg, :l1, ContinuousScalar)
102+
addFactor!(fg, [:x0;:l1], LinearConditional(Normal()))
103+
addFactor!(fg, [:x6;:l1], LinearConditional(Normal()))
104+
105+
return fg
106+
end

test/testBasicGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ tree, smt, hist = solveTree!(fg)
106106
# check mean and covariance -- should be zero
107107
@test abs((getKDE(fg, :x0) |> getKDEMean)[1] + 1000) < 0.6
108108
# should be sqrt(1/2) = 0.707 -- computation results nearer 0.7.
109-
@test 0.3 < Statistics.cov( getPoints(getKDE(fg, :x0))[1,:] ) < 1
109+
@test 0.2 < Statistics.cov( getPoints(getKDE(fg, :x0))[1,:] ) < 1
110110

111111
end
112112

test/testJunctionTreeConstruction.jl

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,55 @@ using Test
1616

1717
end
1818

19+
@testset "Test Caesar Ring 1D symbolic tree construction" begin
20+
21+
fg = loadCanonicalFG_CaesarRing1D()
22+
# drawGraph(fg, show=true)
23+
24+
eo = [:x0;:x2;:x4;:x6;:x1;:l1;:x5;:x3;]
25+
26+
tree = buildTreeFromOrdering!(fg,eo)
27+
drawTree(tree, show=true)
28+
29+
@test length(tree.cliques) == 6
30+
31+
C0 = getCliq(tree, :x3)
32+
@test intersect( C0 |> getFrontals, [:x3; :x5; :l1]) |> length == 3
33+
@test C0 |> getCliqSeparatorVarIds |> length == 0
34+
35+
cC0 = getChildren(tree, C0)
36+
@test cC0 |> length == 3
37+
38+
C1 = getCliq(tree, :x1)
39+
@test C1 in cC0
40+
@test C1 |> getFrontals == [:x1;]
41+
@test intersect(C1 |> getCliqSeparatorVarIds, [:x3;:l1]) |> length == 2
42+
43+
cC1 = getChildren(tree, C1)
44+
@test cC1 |> length == 2
45+
46+
C4 = getCliq(tree, :x2)
47+
@test C4 in cC1
48+
@test C4 |> getFrontals == [:x2;]
49+
@test intersect(C4 |> getCliqSeparatorVarIds, [:x3;:x1]) |> length == 2
50+
51+
C5 = getCliq(tree, :x0)
52+
@test C5 in cC1
53+
@test C5 |> getFrontals == [:x0;]
54+
@test intersect(C5 |> getCliqSeparatorVarIds, [:l1;:x1]) |> length == 2
55+
56+
C2 = getCliq(tree, :x6)
57+
@test C2 in cC0
58+
@test C2 |> getFrontals == [:x6;]
59+
@test intersect(C2 |> getCliqSeparatorVarIds, [:l1;:x5]) |> length == 2
60+
61+
C3 = getCliq(tree, :x4)
62+
@test C3 in cC0
63+
@test C3 |> getFrontals == [:x4;]
64+
@test intersect(C3 |> getCliqSeparatorVarIds, [:x3;:x5]) |> length == 2
65+
66+
end
67+
1968

2069
@testset "Test tree formation and consistent APIs" begin
2170

@@ -28,7 +77,7 @@ end
2877
tree = buildTreeFromOrdering!(fg,eo)
2978
# drawTree(tree, show=true)
3079

31-
@warn "TODO, complete test on tree formation"
80+
@warn "TODO, complete further testing on tree formation"
3281

3382

3483
## test variable order APIs consistent, see issue 499

0 commit comments

Comments
 (0)