Skip to content

Commit

Permalink
Merge pull request #224 from JuliaRobotics/master
Browse files Browse the repository at this point in the history
release v0.6.2-rc1
  • Loading branch information
dehann committed Dec 27, 2022
2 parents e41bd63 + 249e9dc commit 7d6c9e1
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
version:
- '1.6'
- '1.8'
- '~1.9.0-0'
- 'nightly'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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.6.1"
version = "0.6.2"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
54 changes: 41 additions & 13 deletions src/CommonUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,49 @@ function updateProductSample( dest::BallTreeDensity,
manikde!(pts, manifolds)
end

# Returns the covariance (square), not deviation
function calcCovarianceBasic(M::AbstractManifold, ptsArr::Vector{P}) where P
#TODO double check the maths,. it looks like its working at least for groups
μ = mean(M, ptsArr)
Xcs = vee.(Ref(M), Ref(μ), log.(Ref(M), Ref(μ), ptsArr))
Σ = mean(Xcs .* transpose.(Xcs))
@debug "calcCovarianceBasic" μ
@debug "calcCovarianceBasic" Σ
# TODO don't know what to do here so keeping as before, #FIXME it will break
# a change between this and previous is that a full covariance matrix is returned
msst = Σ
msst_ = 0 < sum(1e-10 .< msst) ? maximum(msst) : 1.0
return msst_

# TODO this should be a public method relating to getManifold
function _getManifoldFullOrPart(mkd::ManifoldKernelDensity, aspartial::Bool=true)
if aspartial && isPartial(mkd)
getManifoldPartial(mkd.manifold, mkd._partial)
else
mkd.manifold
end
end

function Statistics.mean(mkd::ManifoldKernelDensity, aspartial::Bool=true; kwargs...)
return mean(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); kwargs...)
end
"""
$SIGNATURES
Alias for overloaded `Statistics.mean`.
"""
calcMean(mkd::ManifoldKernelDensity, aspartial::Bool=true) = mean(mkd, aspartial)

function Statistics.std(mkd::ManifoldKernelDensity, aspartial::Bool=true; kwargs...)
std(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); kwargs...)
end
function Statistics.var(mkd::ManifoldKernelDensity, aspartial::Bool=true; kwargs...)
var(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); kwargs...)
end
function Statistics.cov(mkd::ManifoldKernelDensity, aspartial::Bool=true; basis::Manifolds.AbstractBasis = Manifolds.DefaultOrthogonalBasis(), kwargs...)
return cov(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); basis, kwargs... )
end
# function Statistics.mean(mkd::ManifoldKernelDensity; kwargs...)
# return mean(mkd.manifold, getPoints(mkd); kwargs...)
# end
# function Statistics.cov(mkd::ManifoldKernelDensity; kwargs...)
# cov(mkd.manifold, getPoints(mkd); kwargs...)
# end
# function Statistics.std(mkd::ManifoldKernelDensity; kwargs...)
# return std(mkd.manifold, getPoints(mkd); kwargs...)
# end
# function Statistics.var(mkd::ManifoldKernelDensity; kwargs...)
# return var(mkd.manifold, getPoints(mkd); kwargs...)
# end


"""
$SIGNATURES
Expand Down
11 changes: 11 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
@deprecate R(th::Real) _Rot.RotMatrix2(th).mat # = [[cos(th);-sin(th)]';[sin(th);cos(th)]'];
@deprecate R(;x::Real=0.0,y::Real=0.0,z::Real=0.0) (M=SpecialOrthogonal(3);exp(M,identity_element(M),hat(M,Identity(M),[x,y,z]))) # convert(SO3, so3([x,y,z]))

export calcCovarianceBasic
# Returns the covariance (square), not deviation
function calcCovarianceBasic(M::AbstractManifold, ptsArr::Vector{P}) where P
@warn "`calcCovarianceBasic` is deprecated. Replace with IIF.calcSTDBasicSpread from IIF or `cov` or `var` from Manifolds. See issue AMP#150."
μ = mean(M, ptsArr)
Xcs = vee.(Ref(M), Ref(μ), log.(Ref(M), Ref(μ), ptsArr))
Σ = mean(Xcs .* transpose.(Xcs))
msst = Σ
msst_ = 0 < sum(1e-10 .< msst) ? maximum(msst) : 1.0
return msst_
end

## ======================================================================================================
## Remove below before v0.7
Expand Down
1 change: 0 additions & 1 deletion src/ExportAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export
getKDEManifoldBandwidths,
manifoldProduct,
manikde!,
calcCovarianceBasic,
isPartial,
calcProductGaussians

Expand Down
33 changes: 0 additions & 33 deletions src/services/ManifoldKernelDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,6 @@ manikde!( M::MB.AbstractManifold,
## a few utilities
## ==========================================================================================

# TODO this should be a public method relating to getManifold
function _getManifoldFullOrPart(mkd::ManifoldKernelDensity, aspartial::Bool=true)
if aspartial && isPartial(mkd)
getManifoldPartial(mkd.manifold, mkd._partial)
else
mkd.manifold
end
end

function Statistics.mean(mkd::ManifoldKernelDensity, aspartial::Bool=true)
M = _getManifoldFullOrPart(mkd, aspartial)
mean(M, getPoints(mkd, aspartial))
end

"""
$SIGNATURES
Alias for overloaded `Statistics.mean`.
"""
calcMean(mkd::ManifoldKernelDensity, aspartial::Bool=true) = mean(mkd, aspartial)

function Statistics.std(mkd::ManifoldKernelDensity, aspartial::Bool=true; kwargs...)
std(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); kwargs...)
end
function Statistics.var(mkd::ManifoldKernelDensity, aspartial::Bool=true; kwargs...)
var(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); kwargs...)
end

function Statistics.cov(mkd::ManifoldKernelDensity, aspartial::Bool=true; basis::Manifolds.AbstractBasis = Manifolds.DefaultOrthogonalBasis(), kwargs...)
return cov(_getManifoldFullOrPart(mkd,aspartial), getPoints(mkd, aspartial); basis, kwargs... )
end



_getFieldPartials(mkd::ManifoldKernelDensity{M,B,Nothing}, field::Function, aspartial::Bool=true) where {M,B} = field(mkd)

Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ include("testPartialProductSE2.jl")
include("basic_se3.jl")
include("testSymmetry.jl")
include("testUpdateMKD.jl")
include("testMKDStats.jl")

#
26 changes: 26 additions & 0 deletions test/testMKDStats.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Test
using ApproxManifoldProducts
using Manifolds

##

@testset "Test basic MKD statistics" begin
##

M = SpecialEuclidean(2)
u0 = ArrayPartition(zeros(2),[1 0; 0 1.0])
ϵ = identity_element(M, u0)

pts = [exp(M, ϵ, hat(M, ϵ, [0.05*randn(2);0.75*randn()])) for i in 1:100]

P = manikde!(M, pts)

@test isapprox(M, mean(P), mean(M, pts))
@test isapprox(var(P), var(M, pts))
@test isapprox(std(P), std(M, pts))
@test_broken isapprox(cov(P), cov(M, pts))
@test isapprox(cov(P), cov(M, pts; basis=DefaultOrthogonalBasis()))
@test isapprox(cov(P; basis=DefaultOrthonormalBasis()), cov(M, pts))

##
end

0 comments on commit 7d6c9e1

Please sign in to comment.