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

The record of a HiddenMarkovFilter's forward pass that a smoother runs backward over: one CategoricalPredictedJoint per prediction, each with room for its smoothed distribution. More...

#include <EmrysFilter/Smoothers/CategoricalHistory.h>

Classes

struct  Step
 One recorded prediction and its smoothed distribution. More...

Public Types

using Scalar = Scalar_
 the scalar type
using SpaceType = Space_
 the discrete space
using CategoricalType = CategoricalParams<Space_, Scalar_>
 the smoothed distribution's type
using JointType = CategoricalPredictedJoint<Space_, Scalar_>
 what each step records
using allocator_type = Allocator_
 the allocator the steps come from
using Index = Eigen::Index
 Eigen's index type.
using const_iterator = typename ListType::const_iterator
 iterates the steps, oldest first

Public Member Functions

 CategoricalHistory ()=default
 An empty history that keeps every step.
 CategoricalHistory (Allocator_ const &allocator)
 An empty history that keeps every step, with nodes from allocator.
 CategoricalHistory (Lag lag, Allocator_ const &allocator={})
 An empty history that keeps the newest lag steps, with nodes from allocator.
 CategoricalHistory (CategoricalHistory const &other)
 Copies the steps into nodes from other's allocator (see Allocation).
 CategoricalHistory (CategoricalHistory const &other, Allocator_ const &allocator)
 Copies other's steps into nodes from allocator.
 CategoricalHistory (CategoricalHistory &&other)=default
 Takes other's steps.
 CategoricalHistory (CategoricalHistory &&other, Allocator_ const &allocator)
 Moves other's steps into nodes from allocator, taking its nodes when the allocators are equal.
CategoricalHistory & operator= (CategoricalHistory const &other)=default
 Copies other's steps and lag.
CategoricalHistory & operator= (CategoricalHistory &&other)=default
 Takes other's steps and lag, as std::list's move assignment does.
allocator_type get_allocator () const
std::optional< Index > lag () const
Index size () const
bool empty () const
Step const & front () const
Step const & back () const
const_iterator begin () const
const_iterator end () const
void push (JointType joint)
 Records joint as the newest step.
void smooth (CategoricalType const &latest)
 Fills every step's smoothed distribution by smoothStep(), from the newest back, given latest, the filter's state after the newest step: its posterior \( p(x_N \mid z_{1:N}) \), which is its own smoothed distribution.
void clear ()
 Drops every step, keeping the lag.

Detailed Description

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
class Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >

The record of a HiddenMarkovFilter's forward pass that a smoother runs backward over: one CategoricalPredictedJoint per prediction, each with room for its smoothed distribution.

GaussianHistory for a discrete state (decisions.md [smoothing], [emissions]), with the same interface: push() records the joint a filter's predictJoint() returns, smooth() takes the filter's current state and fills every step's smoothed distribution by smoothStep(), from the newest step back, and a Lag makes it a fixed-lag window that recycles its oldest node. Updates between predictions need no recording. The same record gives the most probable sequence (mostProbableSequence()) and the pairwise transition posteriors (transitionPosterior()).

for (auto const & z : observations)
{
history.push(filter.predictJoint());
static_cast<void>(filter.update(table.observe(z)));
}
history.smooth(filter.state());
for (auto const & step : history) { use(step.smoothed); } // p(x_k | z_{1:N}), oldest first
auto const path = mostProbableSequence(history, filter.state()); // Viterbi
CategoricalHistory()=default
An empty history that keeps every step.
void push(JointType joint)
Records joint as the newest step.
Definition CategoricalHistory.h:333
void smooth(CategoricalType const &latest)
Fills every step's smoothed distribution by smoothStep(), from the newest back, given latest,...
Definition CategoricalHistory.h:354
ValueSequence< Space, Scalar, Allocator > mostProbableSequence(CategoricalHistory< Space, Scalar, Allocator > const &history, CategoricalParams< Space, Scalar > const &latest)
Definition CategoricalHistory.h:419
constexpr TagPath< Tags... > path
The path TagPath<Tags...> as a value, for a call that takes its paths as arguments rather than as tem...
Definition TagPath.h:372

For a bounded space every step is inline in its node, so a fixed-lag history allocates nothing once full.

Template Parameters
Space_the discrete space
Scalar_scalar type of the probabilities, double by default
Allocator_allocator for the steps, re-bound to the list's nodes (see Allocation)
See also
smoothStep(), CategoricalPredictedJoint, HiddenMarkovFilter::predictJoint(), Smoothers

Member Function Documentation

◆ back()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Step const & Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::back ( ) const
inlinenodiscard
Returns
the newest step; the history must not be empty

◆ begin()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
const_iterator Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::begin ( ) const
inlinenodiscard
Returns
an iterator to the oldest step

◆ empty()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
bool Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::empty ( ) const
inlinenodiscard
Returns
whether no step is recorded

◆ end()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
const_iterator Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::end ( ) const
inlinenodiscard
Returns
an iterator past the newest step

◆ front()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Step const & Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::front ( ) const
inlinenodiscard
Returns
the oldest step kept; the history must not be empty

◆ get_allocator()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
allocator_type Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::get_allocator ( ) const
inlinenodiscard
Returns
the allocator the steps come from

◆ lag()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
std::optional< Index > Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::lag ( ) const
inlinenodiscard
Returns
the most steps a fixed-lag history keeps, or nothing if it keeps every step

◆ push()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
void Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::push ( JointType joint)
inline

Records joint as the newest step.

A full fixed-lag history drops its oldest step and reuses its node.

◆ size()

template<DiscreteSpace Space_, RealScalar Scalar_ = double, typename Allocator_ = DefaultAllocator>
Index Emrys::CategoricalHistory< Space_, Scalar_, Allocator_ >::size ( ) const
inlinenodiscard
Returns
the number of steps recorded, at most lag()

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