EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Emrys::KernelDensity< Space_, Scalar_, Allocator_ > Class Template Reference

Gaussian kernel density estimate over a ParticleSet. More...

#include <EmrysFilter/Distributions/KernelDensity.h>

Public Types

using SpaceType = Space_
 the particles' space
using ParamsType = ParticleSet<Space_, Scalar_, Allocator_>
 the particles it reads
using allocator_type = Allocator_
 the particles' allocator
using KernelType
 The zero-mean kernel, in the linear tangent space of Space_.
using MomentsType = typename ParamsType::MomentsType
 a mean and covariance together
using Scalar = typename ParamsType::Scalar
 the scalar type
using Index = typename ParamsType::Index
 Eigen's index type.
using VectorType = typename ParamsType::VectorType
 a value, such as a state
using DifferenceVectorType = typename ParamsType::DifferenceVectorType
 a difference
using MatrixType = typename ParamsType::MatrixType
 a matrix over differences
using SampleSetType = typename ParamsType::SampleSetType
 states as columns

Public Member Functions

Index size () const
Index valueDimension () const
Index differenceDimension () const
Space_ const & space () const
ParamsType const & particles () const
Scalar logTotalWeight () const
MatrixType const & bandwidth () const
KernelType::DensityType kernel () const
MomentsType moments () const
template<ExecutionPolicy P>
MomentsType moments (P &&policy) const
 moments() under policy: the particles' moments are reductions over them (see Execution policies).
template<typename Derived>
Scalar logDensity (Eigen::MatrixBase< Derived > const &x) const
template<ExecutionPolicy P, typename Derived>
Scalar logDensity (P &&policy, Eigen::MatrixBase< Derived > const &x) const
 logDensity() under policy: a log-sum-exp over the particles, reduced over chunks of them (see Execution policies).
template<typename Derived>
Scalar density (Eigen::MatrixBase< Derived > const &x) const

Static Public Attributes

static constexpr int ValueDimensionAtCompileTime = ParamsType::ValueDimensionAtCompileTime
 the length of a state, or Eigen::Dynamic
static constexpr int MaxValueDimensionAtCompileTime = ParamsType::MaxValueDimensionAtCompileTime
 a bound on the length of a state, or Eigen::Dynamic
static constexpr int DifferenceDimensionAtCompileTime = ParamsType::DifferenceDimensionAtCompileTime
 the length of a difference and the rows of the bandwidth, or Eigen::Dynamic
static constexpr int MaxDifferenceDimensionAtCompileTime = ParamsType::MaxDifferenceDimensionAtCompileTime
 a bound on the length of a difference, or Eigen::Dynamic

Detailed Description

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
class Emrys::KernelDensity< Space_, Scalar_, Allocator_ >

Gaussian kernel density estimate over a ParticleSet.

Represents the density

\[ \hat p(x) = \sum_i \hat w_i \, \mathcal{N}(x; x_i, H), \]

where \( x_i \) are the particles, \( \hat w_i \) their normalized weights, and \( H \) the bandwidth (kernel covariance), which is factorized once and shared by every kernel: a weighted kernel density estimate with a multivariate Gaussian kernel (Silverman (1986), as given in Multivariate KDE).

Created by ParticleSet::toDensity(). It checks the source set for changes, as its copies do: reading it after the set has changed is a programmer error (decisions.md [view-stamp]). A KernelDensity must not outlive its source.

See also
ParticleSet::toDensity(), silvermanBandwidth()

Member Typedef Documentation

◆ KernelType

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
using Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::KernelType
Initial value:
A Gaussian distribution: a mean and covariance in a space.
Definition Gaussian.h:259

The zero-mean kernel, in the linear tangent space of Space_.

Member Function Documentation

◆ bandwidth()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
MatrixType const & Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::bandwidth ( ) const
inlinenodiscard
Returns
the kernel covariance \( H \)

◆ density()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
template<typename Derived>
Scalar Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::density ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the density \( \hat p(x) \) at x
Warning
Underflows easily in high dimensions; prefer logDensity().
See also
logDensity()

◆ differenceDimension()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Index Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::differenceDimension ( ) const
inlinenodiscard
Returns
the number of rows and columns of the bandwidth

◆ kernel()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
KernelType::DensityType Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::kernel ( ) const
inlinenodiscard
Returns
a view of the zero-mean kernel \( \mathcal{N}(0, H) \). It must not outlive this estimate.

◆ logDensity()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
template<typename Derived>
Scalar Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::logDensity ( Eigen::MatrixBase< Derived > const & x) const
inlinenodiscard
Returns
the log of the density at x

Costs one triangular solve per particle, each into a vector sized by the space, so it allocates nothing for a bounded space. It writes nothing, so it may be evaluated at several points at once.

See also
density()

◆ logTotalWeight()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Scalar Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::logTotalWeight ( ) const
inlinenodiscard
Returns
the log of the sum of the (unnormalized) particle weights

◆ moments()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
MomentsType Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::moments ( ) const
inlinenodiscard
Returns
the mean and covariance of the estimate: the particles' mean, and their weighted covariance plus \( H \).

◆ particles()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
ParamsType const & Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::particles ( ) const
inlinenodiscard
Returns
the particles; a programmer error if they have changed since toDensity()

◆ size()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Index Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::size ( ) const
inlinenodiscard
Returns
the number of particles

◆ space()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Space_ const & Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::space ( ) const
inlinenodiscard
Returns
the particles' space

◆ valueDimension()

template<Space Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Index Emrys::KernelDensity< Space_, Scalar_, Allocator_ >::valueDimension ( ) const
inlinenodiscard
Returns
the number of coordinates of every particle state

The documentation for this class was generated from the following file: