Skip to content

Commit adf36b7

Browse files
committed
Update/test calcVariableDistanceExpectedFractional
1 parent ff2931d commit adf36b7

File tree

2 files changed

+104
-15
lines changed

2 files changed

+104
-15
lines changed

src/services/EvalFactor.jl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,18 @@ function calcVariableDistanceExpectedFractional(ccwl::CommonConvWrapper,
7777
# get mean of all fractional variables
7878
# ccwl.params::Vector{Vector{P}}
7979
uncertainidx = setdiff(1:length(ccwl.params), certainidx)
80-
uncMeans = zeros(length(ccwl.params[sfidx][1]), length(uncertainidx))
8180
dists = zeros(length(uncertainidx)+length(certainidx))
82-
dims = length(ccwl.params[sfidx][1])
81+
82+
dims = manifold_dimension(getManifold(ccwl.vartypes[sfidx]))
83+
84+
uncMeans = zeros(dims, length(uncertainidx))
8385
for (count,i) in enumerate(uncertainidx)
84-
# uncMeans[:,count] = Statistics.mean(ccwl.params[i], dims=2)[:]
85-
for pr in ccwl.params[i]
86-
uncMeans[:,count] .+= pr
87-
end
88-
uncMeans[:,count] ./= length(ccwl.params[i])
86+
u = mean(getManifold(ccwl.vartypes[i]), ccwl.params[i])
87+
uncMeans[:,count] .= getCoordinates(ccwl.vartypes[i], u)
8988
end
9089
count = 0
91-
# refMean = Statistics.mean(ccwl.params[sfidx], dims=2)[:]
92-
refMean = zeros(length(ccwl.params[sfidx][1]))
93-
for pr in ccwl.params[sfidx]
94-
refMean .+= pr
95-
end
96-
refMean ./= length(ccwl.params[sfidx])
90+
91+
refMean = getCoordinates(ccwl.vartypes[sfidx], mean(getManifold(ccwl.vartypes[sfidx]), ccwl.params[sfidx]))
9792

9893
# calc for uncertain and certain
9994
for i in uncertainidx

test/testSpecialEuclidean2Mani.jl

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import IncrementalInference: HeatmapDensityRegular
88

99
## define new local variable types for testing
1010

11-
@defVariable Point2 TranslationGroup(2) [0.0, 0.0]
11+
@defVariable TranslationGroup2 TranslationGroup(2) [0.0, 0.0]
1212

1313
# @defVariable SpecialEuclidean2 SpecialEuclidean(2) ProductRepr(@MVector([0.0,0.0]), @MMatrix([1.0 0.0; 0.0 1.0]))
1414
@defVariable SpecialEuclidean2 SpecialEuclidean(2) ProductRepr([0.0,0.0], [1.0 0.0; 0.0 1.0])
@@ -195,7 +195,7 @@ mp = ManifoldPrior(SpecialEuclidean(2), ProductRepr(@MVector([0.0,0.0]), @MMatri
195195
p = addFactor!(fg, [:x0], mp)
196196

197197
##
198-
v1 = addVariable!(fg, :x1, Point2)
198+
v1 = addVariable!(fg, :x1, TranslationGroup2)
199199
mf = ManiPose2Point2(MvNormal([1,2], [0.01,0.01]))
200200
f = addFactor!(fg, [:x0, :x1], mf)
201201

@@ -376,4 +376,98 @@ initAll!(fg)
376376
end
377377

378378

379+
@testset "Test SpecialEuclidean(2) to TranslationGroup(2) multihypo" begin
380+
381+
##
382+
fg = initfg()
383+
# fg.solverParams.attemptGradients=false
384+
385+
v0 = addVariable!(fg, :x0, SpecialEuclidean2)
386+
387+
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]))
388+
p = addFactor!(fg, [:x0], mp)
389+
390+
##
391+
addVariable!(fg, :x1a, TranslationGroup2)
392+
addVariable!(fg, :x1b, TranslationGroup2)
393+
mf = ManiPose2Point2(MvNormal([1,2], [0.01,0.01]))
394+
f = addFactor!(fg, [:x0, :x1a, :x1b], mf; multihypo=[1,0.5,0.5])
395+
396+
solveTree!(fg)
397+
398+
vnd = getVariableSolverData(fg, :x0)
399+
@test isapprox(SpecialEuclidean(2), mean(SpecialEuclidean(2), vnd.val), ProductRepr([0.0,0.0], [1.0 0; 0 1]), atol=0.1)
400+
401+
#FIXME I would expect close to 50% of particles to land on the correct place
402+
pnt = getPoints(fg, :x1a)
403+
@test sum(isapprox.(pnt, Ref([1.0,2.0]), atol=0.1)) > 25
404+
405+
#FIXME I would expect close to 50% of particles to land on the correct place
406+
pnt = getPoints(fg, :x1b)
407+
@test sum(isapprox.(pnt, Ref([1.0,2.0]), atol=0.1)) > 25
408+
409+
410+
## other way around
411+
412+
fg = initfg()
413+
fg.solverParams.attemptGradients=false
414+
415+
addVariable!(fg, :x0, SpecialEuclidean2)
416+
addVariable!(fg, :x1a, TranslationGroup2)
417+
addVariable!(fg, :x1b, TranslationGroup2)
418+
419+
mp = ManifoldPrior(SpecialEuclidean(2), ProductRepr(@MVector([0.0,0.0]), @MMatrix([1.0 0.0; 0.0 1.0])), MvNormal([10, 10, 0.01]))
420+
p = addFactor!(fg, [:x0], mp)
421+
mp = ManifoldPrior(TranslationGroup(2), [1.,1], MvNormal([0.01, 0.01]))
422+
p = addFactor!(fg, [:x1a], mp)
423+
mp = ManifoldPrior(TranslationGroup(2), [-1.,1], MvNormal([0.01, 0.01]))
424+
p = addFactor!(fg, [:x1b], mp)
425+
426+
mf = ManiPose2Point2(MvNormal([0., 1], [0.01,0.01]))
427+
f = addFactor!(fg, [:x0, :x1a, :x1b], mf; multihypo=[1,0.5,0.5])
428+
429+
solveTree!(fg)
430+
431+
# pnts = getPoints(fg, :x0)
432+
# c = getCoordinates.(SpecialEuclidean2, pnts)
433+
# @cast p[i,j] := c[i][j]
434+
# scatter(p[:,1], p[:,2])
435+
436+
#FIXME
437+
@test 10 < sum(isapprox.(Ref(SpecialEuclidean(2)), pnts, Ref(ProductRepr([-1.0,0.0], [1.0 0; 0 1])), atol=0.5))
438+
@test 10 < sum(isapprox.(Ref(SpecialEuclidean(2)), pnts, Ref(ProductRepr([1.0,0.0], [1.0 0; 0 1])), atol=0.5))
439+
440+
441+
end
442+
443+
@testset "Test SpecialEuclidean(2) to SpecialEuclidean(2) multihypo" begin
444+
##
445+
fg = initfg()
446+
# fg.solverParams.attemptGradients=false
447+
448+
v0 = addVariable!(fg, :x0, SpecialEuclidean2)
449+
450+
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]))
451+
p = addFactor!(fg, [:x0], mp)
452+
453+
##
454+
addVariable!(fg, :x1a, SpecialEuclidean2)
455+
addVariable!(fg, :x1b, SpecialEuclidean2)
456+
mf = ManifoldFactor(SpecialEuclidean(2), MvNormal([1,2,pi/4], [0.01,0.01,0.01]))
457+
f = addFactor!(fg, [:x0, :x1a, :x1b], mf; multihypo=[1,0.5,0.5])
458+
459+
solveTree!(fg)
460+
461+
vnd = getVariableSolverData(fg, :x0)
462+
@test isapprox(SpecialEuclidean(2), mean(SpecialEuclidean(2), vnd.val), ProductRepr([0.0,0.0], [1.0 0; 0 1]), atol=0.1)
463+
464+
#FIXME I would expect close to 50% of particles to land on the correct place
465+
pnt = getPoints(fg, :x1a)
466+
@test sum(isapprox.(Ref(SpecialEuclidean(2)), pnt, Ref(ProductRepr([1.0,2.0], [0.7071 -0.7071; 0.7071 0.7071])), atol=0.1)) > 25
467+
468+
#FIXME I would expect close to 50% of particles to land on the correct place
469+
pnt = getPoints(fg, :x1b)
470+
@test sum(isapprox.(Ref(SpecialEuclidean(2)), pnt, Ref(ProductRepr([1.0,2.0], [0.7071 -0.7071; 0.7071 0.7071])), atol=0.1)) > 25
471+
472+
end
379473
#

0 commit comments

Comments
 (0)