Class Estimate
Defined in File estimate.hpp
Class Documentation
-
class Estimate
Represents a numerical estimate with an associated uncertainty.
The
Estimate
class stores a value along with its uncertainty and provides operations for weighted averaging, arithmetic updates, and comparisons.Public Functions
-
inline Estimate()
Default constructor initializing value and uncertainty to NaN.
-
inline Estimate(double value, double uncertainty = 0)
Constructs an estimate with a specified value and optional uncertainty.
- Parameters:
value – The estimated value.
uncertainty – The uncertainty associated with the estimate (default is 0).
-
inline bool operator<(const Estimate &other) const
Less-than comparison operator.
Compares estimates based only on their values (ignores uncertainty).
- Parameters:
other – The estimate to compare against.
- Returns:
True if this estimate’s value is less than the other.
-
inline bool operator==(const Estimate &other) const
Equality comparison operator.
Two estimates are considered equal if both their values and uncertainties match.
- Parameters:
other – The estimate to compare against.
- Returns:
True if both value and uncertainty are equal.
-
inline bool operator!=(const Estimate &other) const
Inequality comparison operator.
- Parameters:
other – The estimate to compare against.
- Returns:
True if either the value or uncertainty differs.
-
inline Estimate &operator+=(const Estimate &estimate)
Adds another estimate to this one using weighted averaging.
The new estimate is computed using weighted averaging, where the weight is determined by the inverse variance (1 / uncertainty^2).
- Parameters:
estimate – The estimate to add.
- Returns:
Reference to the updated estimate.
-
inline void add_value(double value)
Adds a raw value to the estimate (without modifying uncertainty).
- Parameters:
value – The value to add.
-
inline bool finite() const
Checks if the estimate’s value and uncertainty are finite.
- Returns:
True if both value and uncertainty are finite.
-
inline double min_value()
Computes the minimum possible value given the uncertainty.
- Returns:
The minimum value (value - uncertainty).
-
inline double max_value()
Computes the maximum possible value given the uncertainty.
- Returns:
The maximum value (value + uncertainty).
-
inline double get_value() const
Gets the estimated value.
- Returns:
The estimate’s value.
-
inline void set_value(double value)
Sets the estimated value.
- Parameters:
value – The new value.
-
inline double get_weight() const
Computes the weight of the estimate.
The weight is defined as
1 / uncertainty^2
.- Returns:
The computed weight.
-
inline double get_uncertainty() const
Gets the uncertainty associated with the estimate.
- Returns:
The uncertainty value.
-
inline void set_uncertainty(double uncertainty)
Sets the uncertainty value.
- Parameters:
uncertainty – The new uncertainty.
-
inline void set(double value, double uncertainty)
Sets both the value and uncertainty.
- Parameters:
value – The new value.
uncertainty – The new uncertainty.
Public Static Functions
-
static Estimate weighted_average(const std::vector<Estimate> &estimates)
Computes the weighted average of a list of estimates.
- Parameters:
estimates – A vector of
Estimate
objects.- Returns:
The weighted average estimate.
-
static inline std::string get_header()
Returns the header used in CSV-style output.
- Returns:
A string representing the header (“x,x_bar”).
-
inline Estimate()