#ifndef CHROMECAST_BASE_STATISTICS_WEIGHTED_MEAN_H_
#define CHROMECAST_BASE_STATISTICS_WEIGHTED_MEAN_H_
#include <stdint.h>
namespace chromecast {
class WeightedMean {
public:
WeightedMean();
double weighted_mean() const { return weighted_mean_; }
double variance_sum() const { return variance_sum_; }
double sum_weights() const { return sum_weights_; }
double sum_squared_weights() const { return sum_squared_weights_; }
template <typename T>
void AddSample(T value, double weight) {
AddDelta(value - weighted_mean_, weight);
}
void Reset();
private:
void AddDelta(double delta, double weight);
double weighted_mean_ = 0.0;
double variance_sum_ = 0.0;
double sum_weights_ = 0.0;
double sum_squared_weights_ = 0.0;
};
}
#endif