Class Estimate

template<typename T, typename U = T>
class Estimate

Estimates with a value, \( x \), and a variance, \( \sigma^2 \).

Where \( y = f (x_1, x_2, ... x_n) \), then \( \sigma_y^2 = \sum_{i=1}^n ({\partial f \over \partial x_i})^2\sigma_i^2 \)

See http://mathworld.wolfram.com/ErrorPropagation.html

Note that all variables are assumed independent, even if identical. For example, the following code will underestimate the variance of xsq.

Estimate<double> x;
Estimate<double> xsq = x*x;

To correctly handle error propagation through equations in which variables appear more than once, please see the MEAL::ScalarMath class in the meal library.

Public Functions

inline Estimate(T _val = 0, U _var = 0)

Construct from a value, \( x \), and its variance, \( \sigma_x^2 \).

inline Estimate(const Estimate &d)

Copy constructor.

template<typename V, typename W>
inline Estimate(const Estimate<V, W> &d)

Construct from another Estimate.

template<typename V, typename W>
inline Estimate(const MeanEstimate<V, W> &m)

Construct from MeanEstimate.

template<typename V, typename W>
inline Estimate(const MeanRadian<V, W> &m)

Construct from MeanRadian.

inline const Estimate &operator=(const Estimate &d)

Assignment operator.

inline void set_value(const T &t)

Set the value.

inline T get_value() const

Get the value.

inline void set_variance(const U &u)

Set the variance.

inline U get_variance() const

Get the variance.

inline void set_error(const U &u)

Set the error.

inline U get_error() const

Get the error.

inline T &operator[](unsigned)

Array access to value.

inline T operator[](unsigned) const

Array access to value.

inline const Estimate &operator+=(const Estimate &d)

Addition operator.

inline const Estimate &operator-=(const Estimate &d)

Subtraction operator.

inline const Estimate &operator*=(const Estimate &d)

Multiplication operator.

Where \( r=x*y \), \( \sigma^2_r = y^2\sigma^2_x + x^2\sigma^2_y \)

inline const Estimate &operator/=(const Estimate &d)

Division operator.

inline bool operator==(const Estimate &d) const

Equality operator.

inline bool operator!=(const Estimate &d) const

Inequality operator.

inline bool operator<(const Estimate &d) const

Comparison operator.

inline bool operator>(const Estimate &d) const

Comparison operator.

inline const Estimate inverse() const

Inversion operator.

Where \( r=1/x \), \( \sigma_r=r^2\sigma_x/x^2 = \sigma_x/x^4 \)

Public Members

T val

The value, \( x \).

U var

The variance of the value, \( \sigma_x^2 \).

Friends

inline friend Estimate operator-(Estimate a)

Negation operator.

inline friend Estimate exp(const Estimate &u)

See http://mathworld.wolfram.com/ErrorPropagation.html Equation (15).

inline friend Estimate log(const Estimate &u)

See http://mathworld.wolfram.com/ErrorPropagation.html Equation (17).

inline friend Estimate sqrt(const Estimate &u)

\( {\partial\over\partial x} x^{1\over2} = {1\over2}x^{-{1\over2}} \)

inline friend Estimate sin(const Estimate &u)

\( \left({\partial\sin x\over\partial x}\right)^2 = (1-\sin^2x) \)

inline friend Estimate cos(const Estimate &u)

\( \left({\partial\cos x\over\partial x}\right)^2 = (1-\cos^2x) \)

inline friend Estimate acos(const Estimate &u)

\( {\partial\over\partial x} \cos^{-1} (x) = -(1-x^2)^{-1/2} \)

inline friend Estimate atan(const Estimate &u)

\( {\partial\over\partial x} \tan^{-1} (x) = (1+x^2)^{-1} \)

inline friend Estimate atan2(const Estimate &s, const Estimate &c)

\( {\partial\over\partial x} \tan^{-1} (x) = (1+x^2)^{-1} \)

inline friend Estimate sinh(const Estimate &u)

\( \left({\partial\sinh x\over\partial x}\right)^2 = 1+\sinh^2x \)

inline friend Estimate cosh(const Estimate &u)

\( \left({\partial\cosh x\over\partial x}\right)^2 = \cosh^2x-1 \)

inline friend Estimate atanh(const Estimate &u)

\( {\partial\over\partial x} \tanh^{-1} (x) = (1-x^2)^{-1} \)