@@ -1154,8 +1154,16 @@ CPeriodicityHypothesisTests::best(const TNestedHypothesesVec& hypotheses) const
1154
1154
THypothesisSummaryVec summaries;
1155
1155
summaries.reserve (hypotheses.size ());
1156
1156
1157
+ double meanMagnitude{CBasicStatistics::mean (std::accumulate (
1158
+ m_BucketValues.begin (), m_BucketValues.end (), TMeanAccumulator{},
1159
+ [](TMeanAccumulator partial, const TFloatMeanAccumulator& value) {
1160
+ partial.add (std::fabs (CBasicStatistics::mean (value)),
1161
+ CBasicStatistics::count (value));
1162
+ return partial;
1163
+ }))};
1164
+
1157
1165
for (const auto & hypothesis : hypotheses) {
1158
- STestStats stats;
1166
+ STestStats stats{meanMagnitude} ;
1159
1167
stats.s_TrendSegments = static_cast <double >(hypothesis.trendSegments ());
1160
1168
CPeriodicityHypothesisTestsResult resultForHypothesis{hypothesis.test (stats)};
1161
1169
if (stats.s_NonEmptyBuckets > stats.s_DF0 ) {
@@ -2195,13 +2203,14 @@ bool CPeriodicityHypothesisTests::testAmplitude(const TTimeTimePr2Vec& window,
2195
2203
const double CPeriodicityHypothesisTests::ACCURATE_TEST_POPULATED_FRACTION{0.9 };
2196
2204
const double CPeriodicityHypothesisTests::MINIMUM_COEFFICIENT_OF_VARIATION{1e-4 };
2197
2205
2198
- CPeriodicityHypothesisTests::STestStats::STestStats ()
2206
+ CPeriodicityHypothesisTests::STestStats::STestStats (double meanMagnitude )
2199
2207
: s_TrendSegments(1.0 ), s_HasPeriod(false ), s_HasPartition(false ),
2200
2208
s_VarianceThreshold (COMPONENT_SIGNIFICANT_VARIANCE_REDUCTION[E_HighThreshold]),
2201
2209
s_AmplitudeThreshold(SEASONAL_SIGNIFICANT_AMPLITUDE[E_HighThreshold]),
2202
2210
s_AutocorrelationThreshold(SEASONAL_SIGNIFICANT_AUTOCORRELATION[E_HighThreshold]),
2203
2211
s_Range(0.0 ), s_NonEmptyBuckets(0.0 ), s_MeasurementsPerBucket(0.0 ),
2204
- s_V0(0.0 ), s_R0(0.0 ), s_DF0(0.0 ), s_StartOfPartition(0 ) {
2212
+ s_MeanMagnitude(meanMagnitude), s_V0(0.0 ), s_R0(0.0 ), s_DF0(0.0 ),
2213
+ s_StartOfPartition(0 ) {
2205
2214
}
2206
2215
2207
2216
void CPeriodicityHypothesisTests::STestStats::setThresholds (double vt, double at, double Rt) {
@@ -2211,16 +2220,7 @@ void CPeriodicityHypothesisTests::STestStats::setThresholds(double vt, double at
2211
2220
}
2212
2221
2213
2222
bool CPeriodicityHypothesisTests::STestStats::nullHypothesisGoodEnough () const {
2214
- TMeanAccumulator mean;
2215
- for (const auto & t : s_T0) {
2216
- mean += std::accumulate (t.begin (), t.end (), TMeanAccumulator (),
2217
- [](TMeanAccumulator m, double x) {
2218
- m.add (std::fabs (x));
2219
- return m;
2220
- });
2221
- }
2222
- return std::sqrt (s_V0) <=
2223
- MINIMUM_COEFFICIENT_OF_VARIATION * CBasicStatistics::mean (mean);
2223
+ return std::sqrt (s_V0) <= MINIMUM_COEFFICIENT_OF_VARIATION * s_MeanMagnitude;
2224
2224
}
2225
2225
2226
2226
CPeriodicityHypothesisTests::CNestedHypotheses::CNestedHypotheses (TTestFunc test)
0 commit comments