From 4b110aa20032e2637055f3e8f237a206d249ae84 Mon Sep 17 00:00:00 2001 From: dehann Date: Wed, 4 Oct 2023 22:29:13 -0700 Subject: [PATCH 1/3] mini cleanup --- src/API.jl | 19 ++++++++++--------- src/services/ManifoldKernelDensity.jl | 9 +++++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/API.jl b/src/API.jl index 2c61f0d..7757de2 100644 --- a/src/API.jl +++ b/src/API.jl @@ -112,18 +112,19 @@ function manifoldProduct( ff::AbstractVector{<:ManifoldKernelDensity}, ## TODO check both _ff and inplace use a matrix of coordinates (columns) # expects Matrix with columns as samples and rows are coordinate dimensions pGM, = prodAppxMSGibbsS(inplace, _ff, - nothing, nothing, Niter=Niter, - partialDimMask=partialDimMask, + nothing, nothing; + Niter, + partialDimMask, addop=addopT, diffop=diffopT, getMu=getManiMu, - glbs=glbs, - addEntropy=addEntropy, - ndims=ndims, - Ndens=Ndens, - Np=Np, - maxNp=maxNp, - Nlevels=Nlevels, + glbs, + addEntropy, + ndims, + Ndens, + Np, + maxNp, + Nlevels, randU=_randU, randN=_randN ); # diff --git a/src/services/ManifoldKernelDensity.jl b/src/services/ManifoldKernelDensity.jl index b6e4bf6..ae5ae03 100644 --- a/src/services/ManifoldKernelDensity.jl +++ b/src/services/ManifoldKernelDensity.jl @@ -187,7 +187,12 @@ Random.rand(mkd::ManifoldKernelDensity, N::Integer=1) = sample(mkd, N)[1] function resample(x::ManifoldKernelDensity, N::Int) - pts, = sample(x, N) + pts = if N < Npts(x) + shuffle(getPoints(x))[1:N] + else + _pts, = sample(x, N) + _pts + end ManifoldKernelDensity(x.manifold, pts, x._u0, partial=x._partial, infoPerCoord=x.infoPerCoord) end @@ -296,7 +301,7 @@ function antimarginal(newM::AbstractManifold, ipc = zeros(manifold_dimension(newM)) ipc[finalpartial] .= getInfoPerCoord(mkd, true) - manikde!(newM, nPts, u0, bw=bw, partial=finalpartial, infoPerCoord=ipc) + manikde!(newM, nPts, u0; bw, partial=finalpartial, infoPerCoord=ipc) end From 6c7246eca6d112a8e136071e54eed0b8c6e7d543 Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 8 Oct 2023 23:57:47 -0700 Subject: [PATCH 2/3] some docs and cleanup --- src/entities/ManifoldKernelDensity.jl | 12 ++++ src/services/ManifoldKernelDensity.jl | 90 ++++++++++++++++++--------- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/entities/ManifoldKernelDensity.jl b/src/entities/ManifoldKernelDensity.jl index 8b022f4..1febefc 100644 --- a/src/entities/ManifoldKernelDensity.jl +++ b/src/entities/ManifoldKernelDensity.jl @@ -1,5 +1,17 @@ +""" + $TYPEDEF + +On-manifold kernel density belief. + +Notes +- Allows partials as identified by list of coordinate dimensions e.g. `._partial = [1;3]` + - When building a partial belief, use full points with necessary information in the specified partial coords. + +DevNotes +- WIP AMP issue 41, use generic retractions during manifold products. +""" struct ManifoldKernelDensity{M <: MB.AbstractManifold, B <: BallTreeDensity, L, P <: AbstractArray} manifold::M """ legacy expects matrix of coordinates (as columns) """ diff --git a/src/services/ManifoldKernelDensity.jl b/src/services/ManifoldKernelDensity.jl index ae5ae03..b563bad 100644 --- a/src/services/ManifoldKernelDensity.jl +++ b/src/services/ManifoldKernelDensity.jl @@ -4,18 +4,28 @@ ## ========================================================================================== -ManifoldKernelDensity(mani::M, - bel::B, - ::Nothing=nothing, - u0::P=zeros(manifold_dimension(mani)); - infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) ) where {M <: MB.AbstractManifold, B <: BallTreeDensity, P} = ManifoldKernelDensity{M,B,Nothing,P}(mani,bel,nothing,u0,infoPerCoord) +ManifoldKernelDensity( + mani::M, + bel::B, + ::Nothing=nothing, + u0::P=zeros(manifold_dimension(mani)); + infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) +) where {M <: MB.AbstractManifold, B <: BallTreeDensity, P} = ManifoldKernelDensity{M,B,Nothing,P}( + mani, + bel, + nothing, + u0, + infoPerCoord +) # -function ManifoldKernelDensity( mani::M, - bel::B, - partial::L, - u0::P=zeros(manifold_dimension(mani)); - infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) ) where {M <: MB.AbstractManifold, B <: BallTreeDensity, L<:AbstractVector{<:Integer}, P} +function ManifoldKernelDensity( + mani::M, + bel::B, + partial::L, + u0::P=zeros(manifold_dimension(mani)); + infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) +) where {M <: MB.AbstractManifold, B <: BallTreeDensity, L<:AbstractVector{<:Integer}, P} # if length(partial) != manifold_dimension(mani) # call the constructor direct @@ -26,26 +36,35 @@ function ManifoldKernelDensity( mani::M, end end -ManifoldKernelDensity(mani::M, - bel::B, - pl_mask::Union{<:BitVector,<:AbstractVector{<:Bool}}, - u0::P=zeros(manifold_dimension(mani)); - infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) ) where {M <: MB.AbstractManifold, B <: BallTreeDensity, P} = ManifoldKernelDensity(mani,bel,(1:manifold_dimension(mani))[pl_mask],u0;infoPerCoord=infoPerCoord) - - -function ManifoldKernelDensity( M::MB.AbstractManifold, - vecP::AbstractVector{P}, - u0=vecP[1], - ϵ = identity_element(M, vecP[1]); - partial::L=nothing, - infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(M, u0)), - dims::Int=manifold_dimension(M), - bw::Union{<:AbstractVector{<:Real},Nothing}=nothing ) where {P,L} +ManifoldKernelDensity( + mani::M, + bel::B, + pl_mask::Union{<:BitVector,<:AbstractVector{<:Bool}}, + u0::P=zeros(manifold_dimension(mani)); + infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(mani, u0)) +) where {M <: MB.AbstractManifold, B <: BallTreeDensity, P} = ManifoldKernelDensity( + mani, + bel, + (1:manifold_dimension(mani))[pl_mask], + u0; + infoPerCoord +) + + +function ManifoldKernelDensity( + M::MB.AbstractManifold, + vecP::AbstractVector{P}, + u0 = vecP[1], + ϵ = identity_element(M, u0); # vecP[1] + partial::L=nothing, + infoPerCoord::AbstractVector{<:Real}=ones(getNumberCoords(M, u0)), + dims::Int=manifold_dimension(M), + bw::Union{<:AbstractVector{<:Real},Nothing}=nothing +) where {P,L} # # FIXME obsolete arr = Matrix{Float64}(undef, dims, length(vecP)) - for j in 1:length(vecP) arr[:,j] = vee(M, ϵ, log(M, ϵ, vecP[j])) end @@ -66,10 +85,18 @@ end # MAYBE deprecate name -manikde!( M::MB.AbstractManifold, - vecP::AbstractVector{P}, - u0::P=vecP[1]; - kw... ) where P = ManifoldKernelDensity(M, vecP, u0; kw...) +manikde!( + M::MB.AbstractManifold, + vecP::AbstractVector{P}, + u0::P=vecP[1]; + kw... +) where P = ManifoldKernelDensity( + M, + vecP, + u0; + kw... +) + # @@ -188,7 +215,8 @@ Random.rand(mkd::ManifoldKernelDensity, N::Integer=1) = sample(mkd, N)[1] function resample(x::ManifoldKernelDensity, N::Int) pts = if N < Npts(x) - shuffle(getPoints(x))[1:N] + # get points with non-partial coord dims so that new MKD can be built + shuffle(getPoints(x, false))[1:N] else _pts, = sample(x, N) _pts From 1c3eb2e811d1ee1332d31177dcd3bdddb1cae49c Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 9 Oct 2023 00:48:25 -0700 Subject: [PATCH 3/3] bump v0.8.1 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4aef396..a21da1f 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.8.0" +version = "0.8.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"