aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/linear_regression
diff options
context:
space:
mode:
authornkmakarov <nkmakarov@yandex-team.ru>2022-02-10 16:49:06 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:06 +0300
commitf1803fa4ac9e2ee6cbfde317571ec330013392ff (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/linear_regression
parent324348a37ed08cf66897faefb0ec4bebfe7804e1 (diff)
downloadydb-f1803fa4ac9e2ee6cbfde317571ec330013392ff.tar.gz
Restoring authorship annotation for <nkmakarov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/linear_regression')
-rw-r--r--library/cpp/linear_regression/linear_model.h4
-rw-r--r--library/cpp/linear_regression/linear_regression_ut.cpp140
-rw-r--r--library/cpp/linear_regression/welford.cpp26
-rw-r--r--library/cpp/linear_regression/welford.h10
4 files changed, 90 insertions, 90 deletions
diff --git a/library/cpp/linear_regression/linear_model.h b/library/cpp/linear_regression/linear_model.h
index 4efd857374..8bb050cff7 100644
--- a/library/cpp/linear_regression/linear_model.h
+++ b/library/cpp/linear_regression/linear_model.h
@@ -5,8 +5,8 @@
#include <util/ysaveload.h>
-#include <utility>
-
+#include <utility>
+
class TLinearModel {
private:
TVector<double> Coefficients;
diff --git a/library/cpp/linear_regression/linear_regression_ut.cpp b/library/cpp/linear_regression/linear_regression_ut.cpp
index 0a31a6e25c..e71a16b67a 100644
--- a/library/cpp/linear_regression/linear_regression_ut.cpp
+++ b/library/cpp/linear_regression/linear_regression_ut.cpp
@@ -298,77 +298,77 @@ Y_UNIT_TEST_SUITE(TLinearRegressionTest) {
Y_UNIT_TEST(SigmaTest10000000) {
TransformationTest(ETransformationType::TT_SIGMA, 10000000);
}
-
+
Y_UNIT_TEST(ResetCalculatorTest) {
TVector<double> arguments;
TVector<double> weights;
- const double eps = 1e-10;
-
- const size_t argumentsCount = 100;
- for (size_t i = 0; i < argumentsCount; ++i) {
- arguments.push_back(i);
- weights.push_back(i);
- }
-
- TDeviationCalculator deviationCalculator1, deviationCalculator2;
- TMeanCalculator meanCalculator1, meanCalculator2;
- TCovariationCalculator covariationCalculator1, covariationCalculator2;
- for (size_t i = 0; i < arguments.size(); ++i) {
- meanCalculator1.Add(arguments[i], weights[i]);
- meanCalculator2.Add(arguments[i], weights[i]);
- deviationCalculator1.Add(arguments[i], weights[i]);
- deviationCalculator2.Add(arguments[i], weights[i]);
- covariationCalculator1.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
- covariationCalculator2.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
- }
-
- UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetMean(), meanCalculator2.GetMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetSumWeights(), meanCalculator2.GetSumWeights(), eps);
-
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetMean(), deviationCalculator2.GetMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetDeviation(), deviationCalculator2.GetDeviation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetStdDev(), deviationCalculator2.GetStdDev(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetSumWeights(), deviationCalculator2.GetSumWeights(), eps);
-
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetFirstValueMean(), covariationCalculator2.GetFirstValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSecondValueMean(), covariationCalculator2.GetSecondValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetCovariation(), covariationCalculator2.GetCovariation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSumWeights(), covariationCalculator2.GetSumWeights(), eps);
-
- meanCalculator2.Reset();
- deviationCalculator2.Reset();
- covariationCalculator2.Reset();
-
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, meanCalculator2.GetMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, meanCalculator2.GetSumWeights(), eps);
-
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetDeviation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetStdDev(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetSumWeights(), eps);
-
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetFirstValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetSecondValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetCovariation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetSumWeights(), eps);
-
- for (size_t i = 0; i < arguments.size(); ++i) {
- meanCalculator2.Add(arguments[i], weights[i]);
- deviationCalculator2.Add(arguments[i], weights[i]);
- covariationCalculator2.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
- }
-
- UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetMean(), meanCalculator2.GetMean(), 1e-10);
- UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetSumWeights(), meanCalculator2.GetSumWeights(), 1e-10);
-
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetMean(), deviationCalculator2.GetMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetDeviation(), deviationCalculator2.GetDeviation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetStdDev(), deviationCalculator2.GetStdDev(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetSumWeights(), deviationCalculator2.GetSumWeights(), eps);
-
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetFirstValueMean(), covariationCalculator2.GetFirstValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSecondValueMean(), covariationCalculator2.GetSecondValueMean(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetCovariation(), covariationCalculator2.GetCovariation(), eps);
- UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSumWeights(), covariationCalculator2.GetSumWeights(), eps);
- }
+ const double eps = 1e-10;
+
+ const size_t argumentsCount = 100;
+ for (size_t i = 0; i < argumentsCount; ++i) {
+ arguments.push_back(i);
+ weights.push_back(i);
+ }
+
+ TDeviationCalculator deviationCalculator1, deviationCalculator2;
+ TMeanCalculator meanCalculator1, meanCalculator2;
+ TCovariationCalculator covariationCalculator1, covariationCalculator2;
+ for (size_t i = 0; i < arguments.size(); ++i) {
+ meanCalculator1.Add(arguments[i], weights[i]);
+ meanCalculator2.Add(arguments[i], weights[i]);
+ deviationCalculator1.Add(arguments[i], weights[i]);
+ deviationCalculator2.Add(arguments[i], weights[i]);
+ covariationCalculator1.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
+ covariationCalculator2.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
+ }
+
+ UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetMean(), meanCalculator2.GetMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetSumWeights(), meanCalculator2.GetSumWeights(), eps);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetMean(), deviationCalculator2.GetMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetDeviation(), deviationCalculator2.GetDeviation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetStdDev(), deviationCalculator2.GetStdDev(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetSumWeights(), deviationCalculator2.GetSumWeights(), eps);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetFirstValueMean(), covariationCalculator2.GetFirstValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSecondValueMean(), covariationCalculator2.GetSecondValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetCovariation(), covariationCalculator2.GetCovariation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSumWeights(), covariationCalculator2.GetSumWeights(), eps);
+
+ meanCalculator2.Reset();
+ deviationCalculator2.Reset();
+ covariationCalculator2.Reset();
+
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, meanCalculator2.GetMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, meanCalculator2.GetSumWeights(), eps);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetDeviation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetStdDev(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, deviationCalculator2.GetSumWeights(), eps);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetFirstValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetSecondValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetCovariation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(0.0, covariationCalculator2.GetSumWeights(), eps);
+
+ for (size_t i = 0; i < arguments.size(); ++i) {
+ meanCalculator2.Add(arguments[i], weights[i]);
+ deviationCalculator2.Add(arguments[i], weights[i]);
+ covariationCalculator2.Add(arguments[i], arguments[arguments.size() - i - 1], weights[i]);
+ }
+
+ UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetMean(), meanCalculator2.GetMean(), 1e-10);
+ UNIT_ASSERT_DOUBLES_EQUAL(meanCalculator1.GetSumWeights(), meanCalculator2.GetSumWeights(), 1e-10);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetMean(), deviationCalculator2.GetMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetDeviation(), deviationCalculator2.GetDeviation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetStdDev(), deviationCalculator2.GetStdDev(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(deviationCalculator1.GetSumWeights(), deviationCalculator2.GetSumWeights(), eps);
+
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetFirstValueMean(), covariationCalculator2.GetFirstValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSecondValueMean(), covariationCalculator2.GetSecondValueMean(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetCovariation(), covariationCalculator2.GetCovariation(), eps);
+ UNIT_ASSERT_DOUBLES_EQUAL(covariationCalculator1.GetSumWeights(), covariationCalculator2.GetSumWeights(), eps);
+ }
}
diff --git a/library/cpp/linear_regression/welford.cpp b/library/cpp/linear_regression/welford.cpp
index 509e80e970..e27b1994f6 100644
--- a/library/cpp/linear_regression/welford.cpp
+++ b/library/cpp/linear_regression/welford.cpp
@@ -1,5 +1,5 @@
#include "welford.h"
-
+
#include <util/generic/ymath.h>
void TMeanCalculator::Multiply(const double value) {
@@ -28,10 +28,10 @@ double TMeanCalculator::GetSumWeights() const {
return SumWeights.Get();
}
-void TMeanCalculator::Reset() {
- *this = TMeanCalculator();
-}
-
+void TMeanCalculator::Reset() {
+ *this = TMeanCalculator();
+}
+
void TCovariationCalculator::Add(const double firstValue, const double secondValue, const double weight /*= 1.*/) {
SumWeights += weight;
if (SumWeights.Get()) {
@@ -66,10 +66,10 @@ double TCovariationCalculator::GetSumWeights() const {
return SumWeights.Get();
}
-void TCovariationCalculator::Reset() {
- *this = TCovariationCalculator();
-}
-
+void TCovariationCalculator::Reset() {
+ *this = TCovariationCalculator();
+}
+
void TDeviationCalculator::Add(const double value, const double weight /*= 1.*/) {
const double lastMean = MeanCalculator.GetMean();
MeanCalculator.Add(value, weight);
@@ -101,7 +101,7 @@ double TDeviationCalculator::GetStdDev() const {
double TDeviationCalculator::GetSumWeights() const {
return MeanCalculator.GetSumWeights();
}
-
-void TDeviationCalculator::Reset() {
- *this = TDeviationCalculator();
-}
+
+void TDeviationCalculator::Reset() {
+ *this = TDeviationCalculator();
+}
diff --git a/library/cpp/linear_regression/welford.h b/library/cpp/linear_regression/welford.h
index 0706ac2cfa..ee865d6693 100644
--- a/library/cpp/linear_regression/welford.h
+++ b/library/cpp/linear_regression/welford.h
@@ -18,7 +18,7 @@ public:
void Remove(const double value, const double weight = 1.);
double GetMean() const;
double GetSumWeights() const;
- void Reset();
+ void Reset();
bool operator<(const TMeanCalculator& other) const {
return Mean < other.Mean;
@@ -51,8 +51,8 @@ public:
double GetCovariation() const;
double GetSumWeights() const;
-
- void Reset();
+
+ 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)
@@ -72,6 +72,6 @@ public:
double GetStdDev() const;
double GetSumWeights() const;
-
- void Reset();
+
+ void Reset();
};