Skip to content

Commit

Permalink
Manellic products are now multiscale (also for unbalanced trees) (#282)
Browse files Browse the repository at this point in the history
* refactor prods w label_sets

* use BT labels toward multiscale sampling

* multiscale functional, untested, suspect permute issue

* refac manellic util fncs toward multiscale tests

* refac manellic left right index

* manellic multiscale prod cov_cont functional, but not yet

* manellic multiscale product working and few tests
  • Loading branch information
dehann committed Apr 24, 2024
1 parent 696d29c commit 0f4b8db
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 220 deletions.
2 changes: 1 addition & 1 deletion src/ApproxManifoldProducts.jl
Expand Up @@ -29,7 +29,7 @@ using Distributions

import Random: rand

import Base: *, isapprox, convert, show, eltype
import Base: *, isapprox, convert, show, eltype, length
import LinearAlgebra: rotate!, det
import Statistics: mean, std, cov, var, entropy
import KernelDensityEstimate: getPoints, getBW, evalAvgLogL, entropy, evaluate
Expand Down
27 changes: 13 additions & 14 deletions src/CommonUtils.jl
Expand Up @@ -116,6 +116,10 @@ Notes
- calc lambdas first and use to calculate mean product second.
- https://ccrma.stanford.edu/~jos/sasp/Product_Two_Gaussian_PDFs.html
- Pennec, X. Intrinsic Statistics on Riemannian Manifolds: Basic Tools for Geometric Measurements, HAL Archive, 2011, Inria, France.
DevNotes:
- FIXME is parallel transport needed as products involve covariances from different tangent spaces?
- TODO avoid recomputing covariance matrix inverses all the time
"""
function calcProductGaussians(
M::AbstractManifold,
Expand Down Expand Up @@ -166,7 +170,14 @@ calcProductGaussians(
) where {N,P} = calcProductGaussians(M, μ_, nothing; dim, Λ_=Λ_ )


"""
$SIGNATURES
EXPERIMENTAL: On-manifold product of Gaussians.
DevNotes
- FIXME is parallel transport needed when multiplying with covariances from difffent tangent spaces?
"""
function calcProductGaussians(
M::AbstractManifold,
comps::AbstractVector{<:MvNormalKernel},
Expand All @@ -175,23 +186,11 @@ function calcProductGaussians(
μ_ = mean.(comps)
Σ_ = cov.(comps)

# FIXME is parallel transport needed here for covariances from different tangent spaces?

_μ, _Σ = calcProductGaussians(M, μ_, Σ_)

return MvNormalKernel(_μ, _Σ)
# d = manifold_dimension(M)
# # TODO avoid recomputing covariance matrix inverses all the time
# _Sigma2 = zeros(d,d)
# _Sig2mu = zeros(d)
# for c in comps
# concentration = inv(cov(c))
# _Sigma2 += concentration
# _Sig2mu += concentration * mean(c)
# end

# Sigma2 = inv(_Sigma2)
# mu = Sigma2 * _Sig2mu

# return MvNormalKernel(mu, Sigma2)
end


Expand Down
1 change: 1 addition & 0 deletions src/entities/ManellicTree.jl
Expand Up @@ -31,5 +31,6 @@ struct ManellicTree{M,D<:AbstractVector,N,HL,HT}

# workaround to overcome bug for StaticArrays `isdefined() != false` issue
_workaround_isdef_treekernel::Set{Int}
_workaround_isdef_leafkernel::Set{Int}
end

2 changes: 1 addition & 1 deletion src/services/KernelEval.jl
Expand Up @@ -7,7 +7,7 @@ function projectSymPosDef(c::AbstractMatrix)
issymmetric(_c) ? _c : project(SymmetricPositiveDefinite(s[1]),_c,_c)
end

# FIXME, REMOVE TYPE DISPLACEMENT
# FIXME ON FIRE, REMOVE TYPE DISPLACEMENT
Base.eltype(mt::MvNormalKernel) = eltype(mt.p)

function MvNormalKernel(
Expand Down

0 comments on commit 0f4b8db

Please sign in to comment.