Skip to content

Commit

Permalink
Merge pull request #220 from JuliaRobotics/22Q4/refac/consolwmanicov
Browse files Browse the repository at this point in the history
consolidation towards Manifolds.jl cov
  • Loading branch information
Affie committed Dec 11, 2022
2 parents ec8fc4f + bd5f860 commit f6dd5f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/CommonUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,23 @@ function updateProductSample( dest::BallTreeDensity,
manikde!(pts, manifolds)
end

# Returns the covariance (square), not deviation
function calcCovarianceBasic(M::AbstractManifold, ptsArr::Vector{P}) where P
#TODO double check the maths,. it looks like its working at least for groups
μ = mean(M, ptsArr)
Xcs = vee.(Ref(M), Ref(μ), log.(Ref(M), Ref(μ), ptsArr))
Σ = mean(Xcs .* transpose.(Xcs))
@debug "calcCovarianceBasic" μ
@debug "calcCovarianceBasic" Σ
# TODO don't know what to do here so keeping as before, #FIXME it will break
# a change between this and previous is that a full covariance matrix is returned
msst = Σ
msst_ = 0 < sum(1e-10 .< msst) ? maximum(msst) : 1.0
return msst_
function Statistics.cov(mkd::ManifoldKernelDensity, args...; kwargs...)
cov(mkd.manifold, getPoints(mkd), args...; kwargs...)
end

function Statistics.mean(mkd::ManifoldKernelDensity, args...; kwargs...)
return mean(mkd.manifold, getPoints(mkd), args...; kwargs...)
end

function Statistics.std(mkd::ManifoldKernelDensity, args...; kwargs...)
return std(mkd.manifold, getPoints(mkd), args...; kwargs...)
end

function Statistics.var(mkd::ManifoldKernelDensity, args...; kwargs...)
return var(mkd.manifold, getPoints(mkd), args...; kwargs...)
end


"""
$SIGNATURES
Expand Down
11 changes: 11 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
@deprecate R(th::Real) _Rot.RotMatrix2(th).mat # = [[cos(th);-sin(th)]';[sin(th);cos(th)]'];
@deprecate R(;x::Real=0.0,y::Real=0.0,z::Real=0.0) (M=SpecialOrthogonal(3);exp(M,identity_element(M),hat(M,Identity(M),[x,y,z]))) # convert(SO3, so3([x,y,z]))

export calcCovarianceBasic
# Returns the covariance (square), not deviation
function calcCovarianceBasic(M::AbstractManifold, ptsArr::Vector{P}) where P
@warn "`calcCovarianceBasic` is deprecated. Replace with IIF.calcSTDBasicSpread from IIF or `cov` or `var` from Manifolds. See issue AMP#150."
μ = mean(M, ptsArr)
Xcs = vee.(Ref(M), Ref(μ), log.(Ref(M), Ref(μ), ptsArr))
Σ = mean(Xcs .* transpose.(Xcs))
msst = Σ
msst_ = 0 < sum(1e-10 .< msst) ? maximum(msst) : 1.0
return msst_
end

## ======================================================================================================
## Remove below before v0.7
Expand Down
1 change: 0 additions & 1 deletion src/ExportAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export
getKDEManifoldBandwidths,
manifoldProduct,
manikde!,
calcCovarianceBasic,
isPartial,
calcProductGaussians

Expand Down

0 comments on commit f6dd5f1

Please sign in to comment.