Skip to content

Commit f710d9f

Browse files
committed
IIF compat v0.21.2, update range testing
1 parent 1e0b2f4 commit f710d9f

File tree

6 files changed

+224
-42
lines changed

6 files changed

+224
-42
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ DistributedFactorGraphs = "0.12"
3535
Distributions = "0.21, 0.22, 0.23, 0.24"
3636
DocStringExtensions = "0.7, 0.8"
3737
FileIO = "1.0.2, 1.1, 1.2"
38-
IncrementalInference = "0.21.1"
38+
IncrementalInference = "0.21.2"
3939
JLD2 = "0.2, 0.3, 0.4"
4040
KernelDensityEstimate = "0.5.1, 0.6"
4141
Optim = "0.22, 1.0"

src/factors/Range2D.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ $(TYPEDEF)
66
"""
77
mutable struct Point2Point2Range{D <: IIF.SamplableBelief} <: IncrementalInference.AbstractRelativeMinimize
88
Z::D
9-
Point2Point2Range{D}() where {D} = new{D}()
10-
Point2Point2Range{D}(d::D) where {D <: IIF.SamplableBelief} = new{D}(d)
9+
# Point2Point2Range{D}() where {D} = new{D}()
10+
# Point2Point2Range{D}(d::D) where {D <: IIF.SamplableBelief} = new{D}(d)
1111
end
12-
Point2Point2Range(d::D) where {D <: IIF.SamplableBelief} = Point2Point2Range{D}(d)
12+
# Point2Point2Range(d::D) where {D <: IIF.SamplableBelief} = Point2Point2Range{D}(d)
13+
1314
function getSample(cfo::CalcFactor{<:Point2Point2Range}, N::Int=1)
1415
return (reshape(rand(cfo.factor.Z,N),1,N),)
1516
end
1617

1718
function (cfo::CalcFactor{<:Point2Point2Range})(rho, xi, lm)
1819
# Basically `EuclidDistance`
19-
return [rho[1] - norm(lm[1:2] .- xi[1:2])]
20+
# must return all dimensions
21+
return rho .- norm(lm[1:2] .- xi[1:2])
22+
# return [rho[1] - norm(lm[1:2] .- xi[1:2])]
2023
end
2124

2225
passTypeThrough(d::FunctionNodeData{Point2Point2Range}) = d
@@ -26,8 +29,8 @@ $(TYPEDEF)
2629
"""
2730
mutable struct PackedPoint2Point2Range <: IncrementalInference.PackedInferenceType
2831
str::String
29-
PackedPoint2Point2Range() = new()
30-
PackedPoint2Point2Range(s::AS) where {AS <: AbstractString} = new(s)
32+
# PackedPoint2Point2Range() = new()
33+
# PackedPoint2Point2Range(s::AS) where {AS <: AbstractString} = new(s)
3134
end
3235
function convert(::Type{PackedPoint2Point2Range}, d::Point2Point2Range)
3336
return PackedPoint2Point2Range(convert(PackedSamplableBelief, d.Z))
@@ -46,25 +49,26 @@ Range only measurement from Pose2 to Point2 variable.
4649
mutable struct Pose2Point2Range{T <: IIF.SamplableBelief} <: IIF.AbstractRelativeMinimize
4750
Z::T
4851
partial::Tuple{Int,Int}
49-
Pose2Point2Range{T}() where T = new()
50-
Pose2Point2Range{T}(Z::T) where {T <: IIF.SamplableBelief} = new{T}(Z, (1,2))
52+
# Pose2Point2Range{T}() where T = new()
5153
end
52-
Pose2Point2Range(Z::T) where {T <: IIF.SamplableBelief} = Pose2Point2Range{T}(Z)
54+
Pose2Point2Range(Z::T) where {T <: IIF.SamplableBelief} = Pose2Point2Range{T}(Z, (1,2))
55+
# Pose2Point2Range(Z::T) where {T <: IIF.SamplableBelief} = Pose2Point2Range{T}(Z)
5356

5457
function getSample(cfo::CalcFactor{<:Pose2Point2Range}, N::Int=1)
5558
return (reshape(rand(cfo.factor.Z,N),1,N), )
5659
end
5760

5861
function (cfo::CalcFactor{<:Pose2Point2Range})(rho, xi, lm)
5962
# Basically `EuclidDistance`
60-
return [rho[1] - norm(lm[1:2] .- xi[1:2])]
63+
return rho .- norm(lm[1:2] .- xi[1:2])
64+
# return [rho[1] - norm(lm[1:2] .- xi[1:2])]
6165
end
6266

6367

6468
mutable struct PackedPose2Point2Range <: IncrementalInference.PackedInferenceType
6569
str::String
66-
PackedPose2Point2Range() = new()
67-
PackedPose2Point2Range(s::AS) where {AS <: AbstractString} = new(s)
70+
# PackedPose2Point2Range() = new()
71+
# PackedPose2Point2Range(s::AS) where {AS <: AbstractString} = new(s)
6872
end
6973
function convert(::Type{PackedPose2Point2Range}, d::Pose2Point2Range)
7074
return PackedPose2Point2Range(convert(PackedSamplableBelief, d.Z))

test/TestPoseAndPoint2Constraints.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ using Test
55
using RoME
66
# , IncrementalInference, Distributions
77

8+
##
89

910
@testset "test pose and point combinations..." begin
1011

12+
##
1113

1214
N = 100
1315
fg = initfg()
@@ -21,9 +23,9 @@ v1 = addVariable!(fg, :x0, Pose2, N=N)
2123
initPosePrior = PriorPose2(MvNormal(zeros(3), initCov))
2224
f1 = addFactor!(fg,[v1], initPosePrior)
2325

24-
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) != nothing
25-
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) != nothing
26-
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) != nothing
26+
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) !== nothing
27+
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) !== nothing
28+
@test Pose2Pose2(MvNormal(randn(2), Matrix{Float64}(LinearAlgebra.I, 2,2))) !== nothing
2729

2830
# and a second pose
2931
v2 = addVariable!(fg, :x1, Pose2, N=N)
@@ -32,9 +34,13 @@ f2 = addFactor!(fg, [:x0;:x1], ppc)
3234

3335
# test evaluation of pose pose constraint
3436
pts = approxConv(fg, :x0x1f1, :x1)
35-
# pts = evalFactor(fg, f2, v2.index)
36-
@test norm(Statistics.mean(pts,dims=2)[1:2] - [50.0;0.0]) < 10.0
37-
@test abs(Statistics.mean(pts,dims=2)[3] - pi/2) < 0.5
37+
38+
pts[3,:] .= TU.wrapRad.(pts[3,:])
39+
@show mv = Statistics.mean(pts,dims=2)
40+
@test norm(mv[1:2] - [50.0;0.0]) < 10.0
41+
@test abs(mv[3] - pi/2) < 0.5
42+
43+
##
3844

3945
# @show ls(fg)
4046
tree, smt, hist = solveTree!(fg)
@@ -45,10 +51,14 @@ tree, smt, hist = solveTree!(fg)
4551

4652
# test post evaluation values are correct
4753
pts = getVal(fg, :x0)
54+
pts[3,:] .= TU.wrapRad.(pts[3,:])
55+
4856
@test norm(Statistics.mean(pts, dims=2)[1:2] - [0.0;0.0]) < 10.0
4957
@test abs(Statistics.mean(pts, dims=2)[3]) < 0.5
5058

5159
pts = getVal(fg, :x1)
60+
pts[3,:] .= TU.wrapRad.(pts[3,:])
61+
5262
@test norm(Statistics.mean(pts, dims=2)[1:2]-[50.0;0.0]) < 10.0
5363
@test abs(Statistics.mean(pts, dims=2)[3]-pi/2) < 0.5
5464

@@ -64,14 +74,17 @@ solveTree!(fg)
6474
# test post evaluation values are correct
6575
pts = getVal(fg, :x0)
6676
@test norm(Statistics.mean(pts, dims=2)[1:2]-[0.0;0.0]) < 20.0
77+
pts[3,:] .= TU.wrapRad.(pts[3,:])
6778
@test abs(Statistics.mean(pts, dims=2)[3]) < 0.5
6879

6980
pts = getVal(fg, :x1)
7081
@test norm(Statistics.mean(pts, dims=2)[1:2]-[50.0;0.0]) < 20.0
82+
pts[3,:] .= TU.wrapRad.(pts[3,:])
7183
@test abs(Statistics.mean(pts, dims=2)[3] - pi/2) < 0.5
7284

7385
pts = getVal(fg, :x2)
7486
@test norm(Statistics.mean(pts, dims=2)[1:2]-[50.0;50.0]) < 20.0
87+
pts[3,:] .= TU.wrapRad.(pts[3,:])
7588
@test abs(Statistics.mean(pts, dims=2)[3]-pi/2) < 0.5
7689

7790
println("test bearing range evaluations")

test/testInflation380.jl

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,134 @@ using Statistics
99

1010
##
1111

12+
13+
@testset "test inflation is working via distance" begin
14+
15+
##
16+
17+
fg = initfg()
18+
# getSolverParams(fg).inflation = 50.0
19+
20+
N = 100
21+
22+
addVariable!(fg, :x0, ContinuousEuclid{2})
23+
addVariable!(fg, :x1, ContinuousEuclid{2})
24+
25+
X0_ = zeros(2,N)
26+
X0_[1,:] .+= 1000.0
27+
initManual!(fg, :x0, X0_)
28+
29+
addFactor!(fg, [:x0;:x1], EuclidDistance(Normal(100.0, 1.0)))
30+
31+
pts = approxConv(fg, :x0, :x1)
32+
33+
34+
##
35+
# does this give a "donut ring" at 1000?
36+
37+
res = 99999*ones(100)
38+
39+
for i in 1:N
40+
res[i] = calcFactorResidual(fg, :x0x1f1, [100.0], [1000.0;0.0], pts[:,i])[1]
41+
end
42+
43+
@test 0.9*N < sum(abs.(res) .< 5)
44+
45+
## new test trying to force inflation error
46+
47+
X1_ = randn(2,N)
48+
X1_[1,:] .+= 1100.0
49+
initManual!(fg, :x1, X1_)
50+
51+
52+
##
53+
54+
IIF._getCCW(fg, :x0x1f1).inflation = 50.0
55+
pts = approxConv(fg, :x0x1f1, :x1)
56+
57+
initManual!(fg, :x1, pts)
58+
59+
pts = approxConv(fg, :x0x1f1, :x1)
60+
61+
62+
##
63+
# does this give a "donut ring" at 1000?
64+
65+
res = 99999*ones(100)
66+
67+
for i in 1:N
68+
res[i] = calcFactorResidual(fg, :x0x1f1, [100.0], [1000.0;0.0], pts[:,i])[1]
69+
end
70+
71+
@test 0.9*N < sum(abs.(res) .< 5)
72+
73+
74+
##
75+
76+
# using RoMEPlotting
77+
# Gadfly.set_default_plot_size(25cm,20cm)
78+
79+
# ##
80+
81+
# # pts = getBelief(fg, :x1) |> getPoints
82+
# plotKDE(manikde!(pts, ContinuousEuclid{2}))
83+
84+
85+
##
86+
87+
end
88+
89+
90+
@testset "test inflation on range solve" begin
91+
92+
##
93+
94+
N = 100
95+
fg = initfg()
96+
fg.solverParams.inflation = 10.0 # super size the inflation to force wide coverage
97+
98+
addVariable!(fg, :x1, ContinuousEuclid{2})
99+
addVariable!(fg, :l1, ContinuousEuclid{2})
100+
101+
addFactor!(fg, [:l1], Prior(MvNormal([-1000.0,0], [0.1, 0.1])))
102+
addFactor!(fg, [:x1; :l1], EuclidDistance(Normal(100.0, 1.0)))
103+
104+
pts = zeros(2,100)
105+
pts[1,:] .-= 900
106+
initManual!(fg, :x1, pts)
107+
108+
##
109+
110+
tree, _, = solveGraph!(fg);
111+
112+
##
113+
114+
pts = getBelief(fg, :x1) |> getPoints
115+
116+
@test 0.9*N < sum( -1150 .< pts[1,:] .< -850)
117+
@test 0.9*N < sum( -150 .< pts[2,:] .< 150)
118+
119+
pts_ = [norm(pts[:,i] - [-1000;0]) for i in 1:N]
120+
121+
@test 0.9*N < sum(80 .< pts_ .< 120)
122+
123+
# must still test spread
124+
125+
@test 0.2*N < sum(-1150 .< pts[1,:] .< -1000)
126+
@test 0.2*N < sum(-1000 .< pts[1,:] .< -850)
127+
@test 0.2*N < sum(-150 .< pts[2,:] .< 0)
128+
@test 0.2*N < sum(0 .< pts[2,:] .< 150)
129+
130+
131+
##
132+
133+
# pl = plotKDE(fg, ls(fg))
134+
135+
##
136+
137+
end
138+
139+
12140
@testset "test bearing range with inflation, #380, IIF #1051" begin
13141

14142
##

test/testPoint2Point2.jl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,48 @@ end
4141
# plotKDE(fg, ls(fg))
4242

4343

44-
@testset "test Point2Point2Range{T}..." begin
44+
@testset "test Point2Point2Range..." begin
4545

4646
##
4747

4848
N=100 # return to 200
4949
fg = initfg()
50-
getSolverParams(fg).inflation = 100.0
50+
# getSolverParams(fg).inflation = 50.0
51+
getSolverParams(fg).graphinit = false
5152

5253
addVariable!(fg, :x0, Point2, N=N)
53-
addFactor!(fg, [:x0], PriorPoint2(MvNormal([100.0;0], diagm(ones(2)) )))
54+
addFactor!(fg, [:x0], PriorPoint2(MvNormal([100.0;0], diagm(ones(2)) )), graphinit=false)
5455

5556
addVariable!(fg, :x1, Point2, N=N)
56-
addFactor!(fg, [:x1], PriorPoint2(MvNormal([0.0;100.0], diagm(ones(2)) )))
57+
addFactor!(fg, [:x1], PriorPoint2(MvNormal([0.0;100.0], diagm(ones(2)) )), graphinit=false)
5758

5859
addVariable!(fg, :l1, Point2, N=N)
59-
addFactor!(fg, [:x0;:l1], Point2Point2Range(Normal(100.0, 1.0)) )
60-
addFactor!(fg, [:x1;:l1], Point2Point2Range(Normal(100.0, 1.0)) )
60+
addFactor!(fg, [:x0;:l1], Point2Point2Range(Normal(100.0, 1.0)) , graphinit=false)
61+
addFactor!(fg, [:x1;:l1], Point2Point2Range(Normal(100.0, 1.0)) , graphinit=false)
6162

62-
##
63-
64-
# using Logging
65-
# @enter doautoinit!(fg, :l1, logger=NullLogger())
6663

6764
##
6865

69-
tree, smt, hist = solveTree!(fg)
66+
@warn("Point2Point2 range 2 mode, allow 3 attempts until IIF #1010 is completed")
67+
TP = false
68+
for ic in 1:3
69+
tree, _, = solveTree!(fg)
70+
71+
# mode 1
72+
@show T1 = (0.05*N < sum( 90 .< getVal(fg, :l1)[1,:] .< 110 ) && 0.05*N < sum( 90 .< getVal(fg, :l1)[2,:] .< 110 ))
73+
# mode 2
74+
@show T2 = (0.05*N < sum( -10 .< getVal(fg, :l1)[1,:] .< 10 ) && 0.05*N < sum( -10 .< getVal(fg, :l1)[2,:] .< 10 ))
75+
TP |= T1 && T2
76+
TP && break
77+
end
7078

71-
##
79+
@test TP
7280

73-
@test 0.05*N < sum( 90 .< getVal(fg, :l1)[1,:] .< 110 )
74-
@test 0.05*N < sum( -10 .< getVal(fg, :l1)[2,:] .< 10 )
81+
# @test 0.05*N < sum( 90 .< getVal(fg, :l1)[1,:] .< 110 )
82+
# @test 0.05*N < sum( -10 .< getVal(fg, :l1)[2,:] .< 10 )
7583

76-
@test 0.05*N < sum( -10 .< getVal(fg, :l1)[1,:] .< 10 )
77-
@test 0.05*N < sum( 90 .< getVal(fg, :l1)[2,:] .< 110 )
84+
# @test 0.05*N < sum( -10 .< getVal(fg, :l1)[1,:] .< 10 )
85+
# @test 0.05*N < sum( 90 .< getVal(fg, :l1)[2,:] .< 110 )
7886

7987
voidsel1 = 10.0 .< getVal(fg, :l1)[1,:]
8088
@test sum( getVal(fg, :l1)[2,voidsel1] .< 70 ) < 0.35*N

0 commit comments

Comments
 (0)