EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Emrys::upkeep::Roughen< G, Scalar_, Policy_ > Class Template Reference

Action that moves each particle by an independent draw from a Gaussian kernel, to restore the diversity resampling removes: the regularized particle filter. More...

#include <EmrysFilter/Distributions/Upkeep.h>

Public Member Functions

constexpr Roughen (G &generator, Scalar_ scale=1, Policy_ policy={})
 Draws from generator a kernel of covariance scale times the bandwidth, under policy.
template<typename Space, typename Scalar, typename Allocator>
std::expected< bool, WeightError > operator() (ParticleSet< Space, Scalar, Allocator > &particles) const
 Moves each of particles by a draw from the kernel.
template<typename State>
requires requires(State & state) { state.setParticleStates(state.particles().states()); }
std::expected< bool, WeightError > operator() (State &state) const
 Roughens the particles of a Rao-Blackwellized state, such as a ParticleGaussianParams, by their own bandwidth.
constexpr G & generator () const noexcept
constexpr Scalar_ scale () const noexcept
constexpr Policy_ const & policy () const noexcept

Detailed Description

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
class Emrys::upkeep::Roughen< G, Scalar_, Policy_ >

Action that moves each particle by an independent draw from a Gaussian kernel, to restore the diversity resampling removes: the regularized particle filter.

The kernel's covariance is scale times the set's kdeBandwidth(), Silverman's rule unless a bandwidth is stored, so after an equal-weight resample the particles become a draw from their kernel density estimate. resample() clears a stored bandwidth, so one stored before it is not used after it. A smaller scale adds less noise than the estimate would. The draws are added in the tangent space and normalized. A stored bandwidth is kept, as it is when the states change other than by resampling. Scalar_ is the type of scale, deduced from the one given (upkeep::roughen(rng, 0.25f) holds a float), so that a float filter holds no double. A scale of zero turns roughening off: upkeep::roughen(rng, 0) checks the weights and returns false, drawing nothing from the generator and leaving the states as they were, so that a run with it is the run without it.

The action draws from the generator G, which it holds by reference and which must outlive it, under the execution policy Policy_ (sequential by default): the bandwidth is a reduction over the particles, and the moves are a for-each over them (see Execution policies). Sequential draws each particle's normals as it moves it, so it allocates nothing; another policy draws them all first, in the same order, into scratch from the policy [execution-policies].

The weights need not be equal: Silverman's rule weights by the effective sample size, so roughening before a resample takes the weighted spread.

See also
Resample, ParticleSet::kdeBandwidth()

Member Function Documentation

◆ generator()

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
G & Emrys::upkeep::Roughen< G, Scalar_, Policy_ >::generator ( ) const
inlinenodiscardconstexprnoexcept
Returns
the generator drawn from

◆ operator()() [1/2]

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
template<typename Space, typename Scalar, typename Allocator>
std::expected< bool, WeightError > Emrys::upkeep::Roughen< G, Scalar_, Policy_ >::operator() ( ParticleSet< Space, Scalar, Allocator > & particles) const
inlinenodiscard

Moves each of particles by a draw from the kernel.

Returns
whether it moved them, false only for a zero scale, or a WeightError if the weights are invalid

◆ operator()() [2/2]

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
template<typename State>
requires requires(State & state) { state.setParticleStates(state.particles().states()); }
std::expected< bool, WeightError > Emrys::upkeep::Roughen< G, Scalar_, Policy_ >::operator() ( State & state) const
inlinenodiscard

Roughens the particles of a Rao-Blackwellized state, such as a ParticleGaussianParams, by their own bandwidth.

Their Gaussians are left as they were, as if each particle had always been where it is moved to: an approximation, as roughening always is. It roughens a copy of the particle set and writes the states back, so it allocates the copy at each call.

◆ policy()

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
Policy_ const & Emrys::upkeep::Roughen< G, Scalar_, Policy_ >::policy ( ) const
inlinenodiscardconstexprnoexcept
Returns
the execution policy

◆ scale()

template<std::uniform_random_bit_generator G, RealScalar Scalar_ = double, ExecutionPolicy Policy_ = execution::Sequential>
Scalar_ Emrys::upkeep::Roughen< G, Scalar_, Policy_ >::scale ( ) const
inlinenodiscardconstexprnoexcept
Returns
the kernel covariance as a multiple of the bandwidth

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