Skip to content

Commit

Permalink
Merge pull request #250 from JuliaRobotics/23Q4/docs/andcleanup
Browse files Browse the repository at this point in the history
some docs and cleanup
  • Loading branch information
dehann authored Oct 9, 2023
2 parents 8bf8254 + 6c7246e commit fa3454d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
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
90 changes: 59 additions & 31 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 @@ -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
Expand Down

0 comments on commit fa3454d

Please sign in to comment.