From 6b25f756362522bdb79025160e2ce6528857b6f2 Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 15 Oct 2021 12:49:40 -0400 Subject: [PATCH 1/6] small fixes and updates --- src/Interface.jl | 13 +++++++++---- src/KernelHilbertEmbeddings.jl | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Interface.jl b/src/Interface.jl index 8e321dc..ed662ca 100644 --- a/src/Interface.jl +++ b/src/Interface.jl @@ -17,11 +17,15 @@ Manifolds.identity_element(::Circle, val::AbstractVector{T}) where {T <: Real} = Helper function to convert coordinates to a desired on-manifold point. +DevNotes +- FIXME need much better consolidation or even removal of this function entirely. + - This function makes too strong an assumption of groups + Notes - `u0` is used to identify the data type for a point - Pass in a different `exp` if needed. """ -makePointFromCoords(M::MB.AbstractManifold, +makePointFromCoords(M::MB.AbstractManifold, # Manifolds.AbstractGroupManifold coords::AbstractVector{<:Real}, u0=zeros(manifold_dimension(M)), ϵ=identity_element(M,u0), @@ -29,11 +33,12 @@ makePointFromCoords(M::MB.AbstractManifold, # # should perhaps just be dispatched for <:AbstractGroupManifold +# only works for AbstractGroupManifold (have an identity) function makeCoordsFromPoint( M::MB.AbstractManifold, - pt::P ) where P + pt::P, + ϵ = identity_element(M, pt) ) where P # - # only works for manifold which have an identity (eg groups) - ϵ = identity_element(M, pt) + vee(M, ϵ, log(M, ϵ, pt)) end diff --git a/src/KernelHilbertEmbeddings.jl b/src/KernelHilbertEmbeddings.jl index ce52ef2..84c83dc 100644 --- a/src/KernelHilbertEmbeddings.jl +++ b/src/KernelHilbertEmbeddings.jl @@ -12,6 +12,11 @@ Normal kernel used for Hilbert space embeddings. """ ker(M::MB.AbstractManifold, p, q, sigma::Real=0.001) = exp( -sigma*(distance(M, p, q)^2) ) +# overwrite non-symmetric with alternate implementations +# ker(M::MB.AbstractManifold, p, q, sigma::Real=0.001) = exp( -sigma*(distance(M, p, q)^2) ) + + + """ $SIGNATURES From f32e311e929c953ffbacc821da99fd50043a87d4 Mon Sep 17 00:00:00 2001 From: dehann Date: Thu, 21 Oct 2021 08:10:18 -0400 Subject: [PATCH 2/6] new test symmetry of distances Mjl --- Project.toml | 3 ++- test/runtests.jl | 1 + test/testSymmetry.jl | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/testSymmetry.jl diff --git a/Project.toml b/Project.toml index f731019..9084ac9 100644 --- a/Project.toml +++ b/Project.toml @@ -53,7 +53,8 @@ julia = "1.4" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["DataFrames", "FileIO", "JLD2", "Test"] +test = ["DataFrames", "FileIO", "JLD2", "Rotations", "Test"] diff --git a/test/runtests.jl b/test/runtests.jl index f0fdb29..7ff305b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,5 +13,6 @@ include("testMarginalProducts.jl") include("testMMD.jl") include("testPartialProductSE2.jl") include("basic_se3.jl") +include("testSymmetry.jl") # diff --git a/test/testSymmetry.jl b/test/testSymmetry.jl new file mode 100644 index 0000000..4f7020e --- /dev/null +++ b/test/testSymmetry.jl @@ -0,0 +1,34 @@ +# test for symmetry on distances + +using Manifolds +using Test + +import Rotations as _Rot + +## +@testset "test symmetry of Manifolds.distance" begin +## + +M = TranslationGroup(2) +a,b = randn(2), randn(2) +@test isapprox( distance(M, a, b), distance(M, b, a), atol = 1e-5) + + +M = SpecialOrthogonal(2) +a,b = _Rot.RotMatrix(randn()), _Rot.RotMatrix(randn()) +@test isapprox( distance(M, a, b), distance(M, b, a), atol = 1e-5) + + +M = SpecialEuclidean(2) +a = ProductRepr(randn(2),_Rot.RotMatrix(randn())) +b = ProductRepr(randn(2),_Rot.RotMatrix(randn())) +@test isapprox( distance(M, a, b), distance(M, b, a), atol = 1e-5) + + +M = SpecialOrthogonal(3) +a = _Rot.RotZ(randn())*_Rot.RotY(randn())*_Rot.RotX(randn()) +b = _Rot.RotZ(randn())*_Rot.RotY(randn())*_Rot.RotX(randn()) +@test isapprox( distance(M, a, b), distance(M, b, a), atol = 1e-5) + +## +end \ No newline at end of file From 37f558efa91b2ffaa10bf410c86279d06df41634 Mon Sep 17 00:00:00 2001 From: dehann Date: Tue, 2 Nov 2021 20:11:27 -0400 Subject: [PATCH 3/6] small API default enhancements --- src/KernelHilbertEmbeddings.jl | 2 +- src/services/ManifoldKernelDensity.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KernelHilbertEmbeddings.jl b/src/KernelHilbertEmbeddings.jl index 84c83dc..f751641 100644 --- a/src/KernelHilbertEmbeddings.jl +++ b/src/KernelHilbertEmbeddings.jl @@ -105,6 +105,6 @@ function mmd(a::ManifoldKernelDensity{M}, b::ManifoldKernelDensity{M}; bw::Vecto end -function isapprox(a::ManifoldKernelDensity, b::ManifoldKernelDensity; atol::Real=0.1) +function isapprox(a::ManifoldKernelDensity, b::ManifoldKernelDensity; mmd_tol::Real=1e-1, atol::Real=mmd_tol) mmd(a,b) < atol end diff --git a/src/services/ManifoldKernelDensity.jl b/src/services/ManifoldKernelDensity.jl index 9f1ed57..b09b061 100644 --- a/src/services/ManifoldKernelDensity.jl +++ b/src/services/ManifoldKernelDensity.jl @@ -196,7 +196,7 @@ end # TODO check that partials / marginals are sampled correctly -function sample(x::ManifoldKernelDensity{M,B,L,P}, N::Int) where {M,B,L,P} +function sample(x::ManifoldKernelDensity{M,B,L,P}, N::Integer=1) where {M,B,L,P} # get legacy matrix of coordinates and selected labels coords, lbls = sample(x.belief, N) From faf4ee2b03e0169810b3267808d7184c823fd600 Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 7 Nov 2021 09:40:41 -0500 Subject: [PATCH 4/6] add test of Manifolds.jl convention SE2 --- test/runtests.jl | 1 + test/testManifoldConventions.jl | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/testManifoldConventions.jl diff --git a/test/runtests.jl b/test/runtests.jl index 7ff305b..e723a5f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,7 @@ using Test include("basics.jl") include("ex_1D.jl") include("ex_2D_rot.jl") +include("testManifoldConventions.jl") include("testManifoldPartial.jl") include("testManiProductBigSmall.jl") include("testBasicManiProduct.jl") diff --git a/test/testManifoldConventions.jl b/test/testManifoldConventions.jl new file mode 100644 index 0000000..94b2fc4 --- /dev/null +++ b/test/testManifoldConventions.jl @@ -0,0 +1,67 @@ +# test manifold conventions + + +using Test +using Manifolds + +import Rotations as _Rot + +## +@testset "test Manifolds.jl conventions" begin +## + +M = SpecialEuclidean(2) +e0 = identity_element(M) + +# body to body next +bTb_ = ProductRepr([10.0;0], _Rot.RotMatrix(pi/2)) + +# drive in a clockwise square from the origin +wTb0 = ProductRepr([100.0;0], _Rot.RotMatrix(0.0)) +wTb1 = Manifolds.compose(M, wTb0, bTb_) # right +wTb2 = Manifolds.compose(M, wTb1, bTb_) # top right +wTb3 = Manifolds.compose(M, wTb2, bTb_) # top +wTb4 = Manifolds.compose(M, wTb3, bTb_) # origin + +wCb0 = vee(M, e0, log(M, e0, wTb0)) +wCb1 = vee(M, e0, log(M, e0, wTb1)) +wCb2 = vee(M, e0, log(M, e0, wTb2)) +wCb3 = vee(M, e0, log(M, e0, wTb3)) +wCb4 = vee(M, e0, log(M, e0, wTb4)) + +## + +# check the favorable result +@test isapprox( [100,0.,0], wCb0 ; atol=1e-6 ) +@test isapprox( [110,0.,pi/2], wCb1 ; atol=1e-6 ) +@test isapprox( [110.,10,pi], wCb2 ; atol=1e-6 ) || isapprox( [110,10,-pi], wCb2 ; atol=1e-6 ) +@test isapprox( [100.,10,-pi/2], wCb3 ; atol=1e-6 ) +@test isapprox( [100,0,0.], wCb4 ; atol=1e-6 ) + + +## check that the inverse breaks + + +# Use opposite convention from above to show it is wrong +wTb0 = ProductRepr([100.0;0], _Rot.RotMatrix(0.0)) +wTb1 = Manifolds.compose(M, bTb_, wTb0) # right +wTb2 = Manifolds.compose(M, bTb_, wTb1) # top right +wTb3 = Manifolds.compose(M, bTb_, wTb2) # top +wTb4 = Manifolds.compose(M, bTb_, wTb3) # origin + +wCb0 = vee(M, e0, log(M, e0, wTb0)) +wCb1 = vee(M, e0, log(M, e0, wTb1)) +wCb2 = vee(M, e0, log(M, e0, wTb2)) +wCb3 = vee(M, e0, log(M, e0, wTb3)) +wCb4 = vee(M, e0, log(M, e0, wTb4)) + +# check the negative result +@test isapprox( [100,0.,0], wCb0 ; atol=1e-6 ) +@test !isapprox( [110,0.,pi/2], wCb1 ; atol=1e-6 ) +@test !isapprox( [110.,10,pi], wCb2 ; atol=1e-6 ) || isapprox( [110,10,-pi], wCb2 ; atol=1e-6 ) +@test !isapprox( [100.,10,-pi/2], wCb3 ; atol=1e-6 ) +@test isapprox( [100,0,0.], wCb4 ; atol=1e-6 ) + + +## +end \ No newline at end of file From 006a14ce15cec86ac77eca1d145254bbc9ac5bd0 Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 7 Nov 2021 09:42:36 -0500 Subject: [PATCH 5/6] oops, fix test --- test/testManifoldConventions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testManifoldConventions.jl b/test/testManifoldConventions.jl index 94b2fc4..8e4adcc 100644 --- a/test/testManifoldConventions.jl +++ b/test/testManifoldConventions.jl @@ -58,7 +58,7 @@ wCb4 = vee(M, e0, log(M, e0, wTb4)) # check the negative result @test isapprox( [100,0.,0], wCb0 ; atol=1e-6 ) @test !isapprox( [110,0.,pi/2], wCb1 ; atol=1e-6 ) -@test !isapprox( [110.,10,pi], wCb2 ; atol=1e-6 ) || isapprox( [110,10,-pi], wCb2 ; atol=1e-6 ) +@test !(isapprox( [110.,10,pi], wCb2 ; atol=1e-6 ) || isapprox( [110,10,-pi], wCb2 ; atol=1e-6 )) @test !isapprox( [100.,10,-pi/2], wCb3 ; atol=1e-6 ) @test isapprox( [100,0,0.], wCb4 ; atol=1e-6 ) From f158f6a780f3b3b1b695c38747ba7838a9308510 Mon Sep 17 00:00:00 2001 From: Dehann Fourie <6412556+dehann@users.noreply.github.com> Date: Sun, 7 Nov 2021 23:39:36 -0500 Subject: [PATCH 6/6] bump v0.4.19 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 01c2d7c..f0eef77 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ApproxManifoldProducts" uuid = "9bbbb610-88a1-53cd-9763-118ce10c1f89" keywords = ["MM-iSAMv2", "SLAM", "inference", "sum-product", "belief-propagation", "nonparametric", "manifolds", "functional"] -version = "0.4.18" +version = "0.4.19" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"