summaryrefslogtreecommitdiffstats
path: root/library/cpp/linear_regression/welford.h
diff options
context:
space:
mode:
authoralex-sh <[email protected]>2022-02-10 16:50:03 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:50:03 +0300
commit3196904c9f5bf7aff7374eeadcb0671589581f61 (patch)
treed13114a178799aeb203a4b3b43dd7fb0c4f6975f /library/cpp/linear_regression/welford.h
parentd154d11651ea533127249184148c3f023e2c6d0a (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/linear_regression/welford.h')
-rw-r--r--library/cpp/linear_regression/welford.h132
1 files changed, 66 insertions, 66 deletions
diff --git a/library/cpp/linear_regression/welford.h b/library/cpp/linear_regression/welford.h
index ee865d66937..32c30f0a9a2 100644
--- a/library/cpp/linear_regression/welford.h
+++ b/library/cpp/linear_regression/welford.h
@@ -1,77 +1,77 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/accurate_accumulate/accurate_accumulate.h>
-
-#include <util/ysaveload.h>
-
-// accurately computes (w_1 * x_1 + w_2 * x_2 + ... + w_n * x_n) / (w_1 + w_2 + ... + w_n)
-class TMeanCalculator {
-private:
- double Mean = 0.;
- TKahanAccumulator<double> SumWeights;
-
-public:
+
+#include <util/ysaveload.h>
+
+// accurately computes (w_1 * x_1 + w_2 * x_2 + ... + w_n * x_n) / (w_1 + w_2 + ... + w_n)
+class TMeanCalculator {
+private:
+ double Mean = 0.;
+ TKahanAccumulator<double> SumWeights;
+
+public:
Y_SAVELOAD_DEFINE(Mean, SumWeights);
-
- void Multiply(const double value);
- void Add(const double value, const double weight = 1.);
- void Remove(const double value, const double weight = 1.);
- double GetMean() const;
- double GetSumWeights() const;
+
+ void Multiply(const double value);
+ void Add(const double value, const double weight = 1.);
+ void Remove(const double value, const double weight = 1.);
+ double GetMean() const;
+ double GetSumWeights() const;
void Reset();
-
+
bool operator<(const TMeanCalculator& other) const {
- return Mean < other.Mean;
- }
-
+ return Mean < other.Mean;
+ }
+
bool operator>(const TMeanCalculator& other) const {
- return Mean > other.Mean;
- }
-};
-
-// accurately computes (w_1 * x_1 * y_1 + w_2 * x_2 * y_2 + ... + w_n * x_n * y_n) / (w_1 + w_2 + ... + w_n)
-class TCovariationCalculator {
-private:
- double Covariation = 0.;
-
- double FirstValueMean = 0.;
- double SecondValueMean = 0.;
-
- TKahanAccumulator<double> SumWeights;
-
-public:
+ return Mean > other.Mean;
+ }
+};
+
+// accurately computes (w_1 * x_1 * y_1 + w_2 * x_2 * y_2 + ... + w_n * x_n * y_n) / (w_1 + w_2 + ... + w_n)
+class TCovariationCalculator {
+private:
+ double Covariation = 0.;
+
+ double FirstValueMean = 0.;
+ double SecondValueMean = 0.;
+
+ TKahanAccumulator<double> SumWeights;
+
+public:
Y_SAVELOAD_DEFINE(Covariation, FirstValueMean, SecondValueMean, SumWeights);
-
- void Add(const double firstValue, const double secondValue, const double weight = 1.);
- void Remove(const double firstValue, const double secondValue, const double weight = 1.);
-
- double GetFirstValueMean() const;
- double GetSecondValueMean() const;
-
- double GetCovariation() const;
-
- double GetSumWeights() const;
+
+ void Add(const double firstValue, const double secondValue, const double weight = 1.);
+ void Remove(const double firstValue, const double secondValue, const double weight = 1.);
+
+ double GetFirstValueMean() const;
+ double GetSecondValueMean() const;
+
+ double GetCovariation() const;
+
+ double GetSumWeights() const;
void Reset();
-};
-
-// accurately computes (w_1 * x_1 * x_1 + w_2 * x_2 * x_2 + ... + w_n * x_n * x_n) / (w_1 + w_2 + ... + w_n)
-class TDeviationCalculator {
-private:
- double Deviation = 0.;
- TMeanCalculator MeanCalculator;
-
-public:
+};
+
+// accurately computes (w_1 * x_1 * x_1 + w_2 * x_2 * x_2 + ... + w_n * x_n * x_n) / (w_1 + w_2 + ... + w_n)
+class TDeviationCalculator {
+private:
+ double Deviation = 0.;
+ TMeanCalculator MeanCalculator;
+
+public:
Y_SAVELOAD_DEFINE(Deviation, MeanCalculator);
-
- void Add(const double value, const double weight = 1.);
- void Remove(const double value, const double weight = 1.);
-
- double GetMean() const;
- double GetDeviation() const;
- double GetStdDev() const;
-
- double GetSumWeights() const;
+
+ void Add(const double value, const double weight = 1.);
+ void Remove(const double value, const double weight = 1.);
+
+ double GetMean() const;
+ double GetDeviation() const;
+ double GetStdDev() const;
+
+ double GetSumWeights() const;
void Reset();
-};
+};