Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.4.18-rc1 #167

Merged
merged 9 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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.4.17"
version = "0.4.18"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down Expand Up @@ -37,7 +37,7 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
CoordinateTransformations = "0.5, 0.6"
DocStringExtensions = "0.7, 0.8, 0.9"
KernelDensityEstimate = "0.5.9"
Manifolds = "0.6"
Manifolds = "0.6, 0.7"
ManifoldsBase = "0.11, 0.12"
NLsolve = "3, 4"
Optim = "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ApproxManifoldProducts.jl

[![Build Status](https://travis-ci.org/JuliaRobotics/ApproxManifoldProducts.jl.svg?branch=master)](https://travis-ci.org/JuliaRobotics/ApproxManifoldProducts.jl)
[![CI](https://github.com/JuliaRobotics/ApproxManifoldProducts.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaRobotics/ApproxManifoldProducts.jl/actions/workflows/ci.yml)
[![codecov.io](https://codecov.io/github/JuliaRobotics/ApproxManifoldProducts.jl/coverage.svg?branch=master)](https://codecov.io/github/JuliaRobotics/ApproxManifoldProducts.jl?branch=master)


Expand Down
40 changes: 27 additions & 13 deletions src/KernelHilbertEmbeddings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export
mmd!, # KED
mmd

"""
$SIGNATURES

Normal kernel used for Hilbert space embeddings.
"""
ker(M::MB.AbstractManifold, p, q, sigma::Real=0.001) = exp( -sigma*(distance(M, p, q)^2) )

"""
Expand All @@ -17,37 +21,47 @@ Notes:
- This is the in-place version (well more in-place than mmd)

DevNotes:
- TODO make work for different sizes N,M
- TODO dont assume equally weighted particles
- TODO profile SIMD vs SLEEF
- TODO optimize memory
- TODO make multithreaded

Related

mmd, ker
See also: [`mmd`](@ref), [`ker`](@ref)
"""
function mmd!(MF::MB.AbstractManifold,
val::AbstractVector{<:Real},
a::AbstractVector,
b::AbstractVector,
N::Int=length(a), M::Int=length(b);
N::Integer=length(a), M::Integer=length(b);
bw::AbstractVector{<:Real}=[0.001;] )
#
# TODO allow unequal data too
@assert N == M "mmd! currently requires input vectors be the same length"
val[1] = 0.0
_N = 1.0/N
_M = 1.0/M
_val1 = 0.0
_val2 = 0.0
_val3 = 0.0
@inbounds @fastmath for i in 1:N
@simd for j in 1:M
val[1] -= ker(MF, a[i], b[j], bw[1])
_val1 -= ker(MF, a[i], b[j], bw[1])
end
end
val .*= 2.0
_val1 *= 2.0*_N*_M
@inbounds @fastmath for i in 1:N
@simd for j in 1:N
_val2 += ker(MF, a[i], a[j], bw[1])
end
end
_val2 *= (_N*_N)
@inbounds @fastmath for i in 1:M
@simd for j in 1:M
val[1] += ker(MF, a[i], a[j], bw[1])
val[1] += ker(MF, b[i], b[j], bw[1])
_val3 += ker(MF, b[i], b[j], bw[1])
end
end
val ./= N
val ./= M
_val3 *= (_M*_M)

# accumulate all terms
val[1] = _val1 + _val2 + _val3
return val
end

Expand Down
11 changes: 10 additions & 1 deletion src/services/ManifoldKernelDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,20 @@ function Base.show(io::IO, mkd::ManifoldKernelDensity{M,B,L,P}) where {M,B,L,P}
pvec = isPartial(mkd) ? mkd._partial : collect(1:length(bw))
println(io, " bws: ", getBandwidth(mkd, true) .|> x->round(x,digits=4))
println(io, " ipc: ", getInfoPerCoord(mkd, true) .|> x->round(x,digits=4))
print(io, " mean: ")
try
# mn = mean(mkd.manifold, getPoints(mkd, false))
mn = mean(mkd)
println(io, " mean: ", round.(mn',digits=4))
if mn isa ProductRepr
println(io)
for prt in mn.parts
println(io, " ", round.(prt,digits=4))
end
else
println(io, round.(mn',digits=4))
end
catch
println(io, "----")
end
println(io, ")")
nothing
Expand Down