22#include <Eigen/Cholesky>
52template <
typename Space,
typename MeasurementSpace,
typename Scalar =
double>
87struct MixtureEvidenceAccess;
103 typename MeasurementSpace,
104 std::size_t Count = std::dynamic_extent,
105 typename Scalar_ = double,
119 Count == std::dynamic_extent,
120 internal::Buffer<BranchType, Allocator>,
121 std::array<BranchType, Count>>;
134 , m_mixtureLogLikelihood{mixtureLogLikelihood}
141 if constexpr (Count == 1)
143 return branches.front().logLikelihood();
147 return m_mixtureLogLikelihood;
152 [[nodiscard]] Eigen::Index
155 return branches.front().innovation.differenceDimension();
161 [[nodiscard]] Allocator
164 if constexpr (Count == std::dynamic_extent)
166 return Allocator(
branches.get_allocator());
176 friend struct internal::MixtureEvidenceAccess;
181 Scalar m_mixtureLogLikelihood = 0;
189inline constexpr bool isMeasurementUpdate =
false;
192template <
typename Space,
typename MeasurementSpace, std::
size_t Count,
typename Scalar,
typename Allocator>
193inline constexpr bool isMeasurementUpdate<MeasurementUpdate<Space, MeasurementSpace, Count, Scalar, Allocator>> =
true;
205template <
typename MeasurementSpace,
typename Scalar =
double>
246 typename MeasurementSpace,
247 std::size_t Count = std::dynamic_extent,
248 typename Scalar_ = double,
261 Count == std::dynamic_extent,
262 internal::Buffer<BranchType, Allocator>,
263 std::array<BranchType, Count>>;
279 , m_mixtureLogLikelihood{mixtureLogLikelihood}
286 if constexpr (Count == 1)
288 return branches.front().logLikelihood();
292 return m_mixtureLogLikelihood;
297 [[nodiscard]] Eigen::Index
300 return branches.front().innovation.differenceDimension();
306 [[nodiscard]] Allocator
309 if constexpr (Count == std::dynamic_extent)
311 return Allocator(
branches.get_allocator());
321 friend struct internal::MixtureEvidenceAccess;
326 Scalar m_mixtureLogLikelihood = 0;
332 Scalar m_logKeptWeight = 0;
343struct MixtureEvidenceAccess
348 template <
typename U>
350 setLogKeptWeight(U &
update,
typename U::Scalar value)
352 update.m_logKeptWeight = value;
358 template <
typename U>
359 [[nodiscard]]
static typename U::Scalar
360 logKeptWeight(U
const &
update)
362 return update.m_logKeptWeight;
366 template <
typename U>
368 setMixtureLogLikelihood(U &
update,
typename U::Scalar value)
370 update.m_mixtureLogLikelihood = value;
374 template <
typename U>
375 [[nodiscard]]
static typename U::Scalar
376 mixtureLogLikelihood(U
const &
update)
378 return update.m_mixtureLogLikelihood;
400template <
typename Space,
typename MeasurementSpace,
typename Scalar =
double,
typename Allocator = DefaultAllocator>
423 internal::MixtureEvidenceAccess::mixtureLogLikelihood(other),
428 other.measured.branches,
431 internal::MixtureEvidenceAccess::mixtureLogLikelihood(other.measured)
434 internal::MixtureEvidenceAccess::setLogKeptWeight(*
this, internal::MixtureEvidenceAccess::logKeptWeight(other));
443 internal::MixtureEvidenceAccess::mixtureLogLikelihood(other),
451 internal::MixtureEvidenceAccess::mixtureLogLikelihood(other.
measured)
454 internal::MixtureEvidenceAccess::setLogKeptWeight(*
this, internal::MixtureEvidenceAccess::logKeptWeight(other));
472template <
typename MeasurementSpace, std::
size_t Count,
typename Scalar,
typename Allocator>
478isFilterUpdateTest(
void const *);
482inline constexpr bool isFilterUpdate =
decltype(isFilterUpdateTest(
static_cast<U
const *
>(
nullptr)))::value;
487template <
typename Space,
typename MeasurementSpace, std::
size_t Count,
typename Scalar,
typename Allocator>
488struct FilterUpdateWithScratchOf
495template <
typename Space,
typename MeasurementSpace,
typename Scalar,
typename Allocator>
496struct FilterUpdateWithScratchOf<
Space, MeasurementSpace, std::dynamic_extent,
Scalar, Allocator>
504template <
typename Space,
typename MeasurementSpace, std::
size_t Count,
typename Scalar,
typename Allocator>
505using FilterUpdateWithScratch =
506 typename FilterUpdateWithScratchOf<Space, MeasurementSpace, Count, Scalar, Allocator>::type;
514template <
typename Update,
typename Allocator>
515struct RebindUpdateAllocatorOf
522template <
typename Space,
typename MeasurementSpace,
typename Scalar,
typename Old,
typename Allocator>
528template <
typename Update,
typename Error,
typename Allocator>
529struct RebindUpdateAllocatorOf<std::expected<Update, Error>, Allocator>
531 using type = std::expected<typename RebindUpdateAllocatorOf<Update, Allocator>::type, Error>;
539template <
typename Update,
typename Allocator>
540using RebindUpdateAllocator =
typename RebindUpdateAllocatorOf<Update, Allocator>::type;
546template <
typename Update,
typename Allocator>
547concept EmptyFromAllocator = std::is_constructible_v<Update, Allocator const &>;
552template <
typename Update,
typename Allocator>
553 requires EmptyFromAllocator<Update, Allocator>
555emptyUpdate(Allocator
const & allocator)
557 return Update(allocator);
The allocator conventions of decisions.md [allocation]: DefaultAllocator, Capacity,...
Spaces built from other spaces (decisions.md [sizes-and-dimensions], [several-resizable-blocks]): Com...
The coordinate types (decisions.md [no-bounded-coordinates]): Linear, plain coordinates,...
Execution policies (decisions.md [execution-policies]): execution::sequential, the ExecutionPolicy co...
The Gaussian: its parameters GaussianParams, the Gaussian that evaluates the density,...
What marginals and conditionals are built from: resolving Eigen index sets against a space; the share...
What a transform returns and what a measurement update reads from it (decisions.md [linearization-for...
The macros every header includes first.
The mixture: the parameters MixtureParams of weighted components of one type (decisions....
Products of fixed-size matrices by Eigen's fixed-size product at every size: multiply() is by Eigen'...
Product: the product of independent densities, each on its own block of a space, built with on<Path>(...
Solving by a factorization of a small matrix: transposedSolve() gives , the shape of a Kalman gain an...
The Space concept and what every continuous space shares (decisions.md [sizes-and-dimensions]): the t...
Subspaces, and growing and shrinking blocks (decisions.md [several-resizable-blocks]).
Tag paths and the index utilities (decisions.md [tag-addressing], [index-names]): TagPath and TagPath...
Log-weights: the WeightError a normalization can fail with (NumericError.h), and the streaming log-su...
A Gaussian distribution: a mean and covariance in a space.
Definition Gaussian.h:259
The innovation of an update: the residual of the observation from the predicted output,...
Definition Linearization.h:536
Scalar nis() const
Definition Linearization.h:608
Scalar logLikelihood() const
Definition Linearization.h:615
A type usable as the space of a distribution.
Definition Space.h:186
std::allocator< std::byte > DefaultAllocator
The allocator a type with a run-time count uses unless given one.
Definition Allocation.h:47
std::expected< CategoricalUpdate< Space, Scalar >, WeightError > update(CategoricalParams< Space, Scalar > const &prior, E const &emission)
Definition Emission.h:97
One branch of a filter's update (see FilterUpdate): its weight, its innovation, and its labels,...
Definition MeasurementUpdate.h:207
Eigen::Index component
Definition MeasurementUpdate.h:211
bool converged
Definition MeasurementUpdate.h:213
Innovation< MeasurementSpace, Scalar > innovation
Definition MeasurementUpdate.h:209
Scalar logLikelihood() const
Definition MeasurementUpdate.h:217
Scalar nis() const
Definition MeasurementUpdate.h:224
std::size_t iterations
Definition MeasurementUpdate.h:212
Eigen::Index mode
Definition MeasurementUpdate.h:210
Scalar logWeight
Definition MeasurementUpdate.h:208
static constexpr std::size_t BranchCount
Definition MeasurementUpdate.h:265
FilterUpdate()=default
no branches, not accepted
MeasurementSpace MeasurementSpaceType
the measurement space
Definition MeasurementUpdate.h:253
Allocator get_allocator() const
Definition MeasurementUpdate.h:307
bool accepted
Definition MeasurementUpdate.h:269
Container branches
Definition MeasurementUpdate.h:267
std::conditional_t< Count==std::dynamic_extent, internal::Buffer< BranchType, Allocator >, std::array< BranchType, Count > > Container
The branches' container: an array when their number is known at compile time, and otherwise a buffer ...
Definition MeasurementUpdate.h:260
Scalar logLikelihood() const
Definition MeasurementUpdate.h:284
Eigen::Index innovationSize() const
Definition MeasurementUpdate.h:298
Allocator allocator_type
where a run-time number of branches comes from
Definition MeasurementUpdate.h:255
FilterBranch< MeasurementSpace, Scalar > BranchType
one branch
Definition MeasurementUpdate.h:254
FilterUpdate(Container branches, Scalar mixtureLogLikelihood=0, bool accepted=false)
The branches branches, as MeasurementUpdate(branches, mixtureLogLikelihood), and whether the policy a...
Definition MeasurementUpdate.h:276
Scalar_ Scalar
the scalar type
Definition MeasurementUpdate.h:252
The result of update(): weighted branches, one per noise component, and the observation's log-likelih...
Definition MeasurementUpdate.h:108
static constexpr std::size_t BranchCount
Definition MeasurementUpdate.h:123
Allocator get_allocator() const
Definition MeasurementUpdate.h:162
MeasurementUpdate(Container branches, Scalar mixtureLogLikelihood=0)
The branches branches of an observation whose log-likelihood, where they are more than the one a sing...
Definition MeasurementUpdate.h:132
Space SpaceType
the state's space
Definition MeasurementUpdate.h:110
MeasurementUpdate()=default
no branches
Scalar logLikelihood() const
Definition MeasurementUpdate.h:139
Scalar_ Scalar
the scalar type
Definition MeasurementUpdate.h:109
Allocator allocator_type
where a run-time number of branches comes from
Definition MeasurementUpdate.h:113
Eigen::Index innovationSize() const
Definition MeasurementUpdate.h:153
MeasurementSpace MeasurementSpaceType
the measurement space
Definition MeasurementUpdate.h:111
Container branches
Definition MeasurementUpdate.h:125
UpdateBranch< Space, MeasurementSpace, Scalar > BranchType
one branch
Definition MeasurementUpdate.h:112
std::conditional_t< Count==std::dynamic_extent, internal::Buffer< BranchType, Allocator >, std::array< BranchType, Count > > Container
The branches' container: an array when their number is known at compile time, and otherwise a buffer ...
Definition MeasurementUpdate.h:118
A FilterUpdate of a run-time number of branches that keeps the MeasurementUpdate it was last filled f...
Definition MeasurementUpdate.h:402
ReusableFilterUpdate(Allocator const &allocator)
Empty, with its branches and scratch from allocator.
Definition MeasurementUpdate.h:411
ReusableFilterUpdate(ReusableFilterUpdate &&) noexcept=default
takes other's storage
MeasurementUpdate< Space, MeasurementSpace, std::dynamic_extent, Scalar, Allocator > MeasuredType
The measurement's branches it keeps.
Definition MeasurementUpdate.h:406
ReusableFilterUpdate(ReusableFilterUpdate const &)=default
copies, keeping the source's allocator
ReusableFilterUpdate & operator=(ReusableFilterUpdate const &)=default
copies, keeping this allocator
MeasuredType measured
the branches of the last fill, posteriors included, reused by the next
Definition MeasurementUpdate.h:465
FilterUpdate< MeasurementSpace, std::dynamic_extent, Scalar, Allocator > Base
the update it is
Definition MeasurementUpdate.h:403
ReusableFilterUpdate()=default
empty, from a default-constructed allocator
ReusableFilterUpdate & operator=(ReusableFilterUpdate &&) noexcept=default
takes other's storage
ReusableFilterUpdate(ReusableFilterUpdate &&other, Allocator const &allocator)
Moves other into storage from allocator, taking its storage when the allocators are equal.
Definition MeasurementUpdate.h:440
One outcome of an update: a posterior, how probable it is, and its innovation, from which the observa...
Definition MeasurementUpdate.h:54
Eigen::Index component
Definition MeasurementUpdate.h:59
Scalar nis() const
Definition MeasurementUpdate.h:78
Scalar logWeight
Definition MeasurementUpdate.h:55
std::size_t iterations
Definition MeasurementUpdate.h:62
Scalar logLikelihood() const
Definition MeasurementUpdate.h:69
bool converged
Definition MeasurementUpdate.h:65
GaussianParams< Space, Scalar > posterior
Definition MeasurementUpdate.h:56
Eigen::Index mode
Definition MeasurementUpdate.h:58
Innovation< MeasurementSpace, Scalar > innovation
Definition MeasurementUpdate.h:57