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.8.1-rc1 #251

Merged
merged 5 commits into from
Oct 9, 2023
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
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.8.0"
version = "0.8.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
19 changes: 10 additions & 9 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
#
Expand Down
12 changes: 12 additions & 0 deletions src/entities/ManifoldKernelDensity.jl
Original file line number Diff line number Diff line change
@@ -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) """
Expand Down
97 changes: 65 additions & 32 deletions src/services/ManifoldKernelDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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...
)

#


Expand Down Expand Up @@ -187,7 +214,13 @@ 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)
# 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
end
ManifoldKernelDensity(x.manifold, pts, x._u0, partial=x._partial, infoPerCoord=x.infoPerCoord)
end

Expand Down Expand Up @@ -296,7 +329,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


Expand Down
Loading