|
EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
|
Streaming log-sum-exp: accumulates \( \log \sum_i e^{x_i} \) without overflow. More...
#include <EmrysFilter/Core/Weights.h>
Public Member Functions | |
| void | add (Scalar x) |
| Adds x to the sum, rescaling the running sum if x is the new maximum. | |
| template<typename Derived> | |
| void | add (Eigen::ArrayBase< Derived > const &xs) |
| Adds every element of xs, as if they had been added one by one, up to rounding. | |
| void | add (LogSumExp const &other) |
| Adds everything added to other, as if its inputs had been added one by one, up to rounding. | |
| Scalar | value () const |
Streaming log-sum-exp: accumulates \( \log \sum_i e^{x_i} \) without overflow.
Inputs of -inf contribute nothing; an empty sum is -inf.
The running maximum \( m \) and sum \( s = \sum_i e^{x_i - m} \) are rescaled when a larger input arrives, the one-pass form of the log-sum-exp trick.
Adding one input is not associative, but adding a whole sum is: the pairs combine as \( (m_1, s_1) \oplus (m_2, s_2) = (m, \; s_1 e^{m_1 - m} + s_2 e^{m_2 - m}) \) with \( m = \max(m_1, m_2) \), whose identity is the empty sum, \( (-\infty, 0) \). So a reduction streams the inputs of each chunk and combines the chunks' sums (logSumExp()).
|
inline |
Adds every element of xs, as if they had been added one by one, up to rounding.
For float and double the array's sum is taken whole, as its maximum and then the sum of its exponentials relative to that, two whole-array expressions that Eigen vectorizes, and joined to this sum as add(LogSumExp) joins two; other scalars add the elements one by one. A NaN gives NaN either way.
|
inline |
Adds everything added to other, as if its inputs had been added one by one, up to rounding.
Associative and commutative, with the empty sum as identity.
|
inlinenodiscard |