43
43
44
44
#include < algorithm>
45
45
#include < cmath>
46
+ #include < map>
47
+ #include < numeric>
46
48
#include < string>
47
49
#include < vector>
48
50
@@ -57,6 +59,7 @@ using TBoolVec = std::vector<bool>;
57
59
using TDoubleVec = std::vector<double >;
58
60
using TSizeVec = std::vector<std::size_t >;
59
61
using TSizeVecVec = std::vector<TSizeVec>;
62
+ using TSizeSizeMap = std::map<std::size_t , std::size_t >;
60
63
using TStrVec = std::vector<std::string>;
61
64
using TTimeVec = std::vector<core_t ::TTime>;
62
65
using TTimeTimePr = std::pair<core_t ::TTime, core_t ::TTime>;
@@ -307,7 +310,7 @@ const std::string LAST_UPDATE_OLD_TAG{"j"};
307
310
308
311
// ////////////////////// Upgrade to Version 6.3 ////////////////////////
309
312
310
- const double MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 {48.0 };
313
+ const double MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 {48.0 };
311
314
312
315
bool upgradeTrendModelToVersion6p3 (const core_t ::TTime bucketLength,
313
316
CTrendComponent& trend,
@@ -330,7 +333,7 @@ bool upgradeTrendModelToVersion6p3(const core_t::TTime bucketLength,
330
333
331
334
// Generate some samples from the old trend model.
332
335
333
- double weight{MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 *
336
+ double weight{MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 *
334
337
static_cast <double >(bucketLength) / static_cast <double >(4 * WEEK)};
335
338
336
339
CPRNG::CXorOShiro128Plus rng;
@@ -343,6 +346,18 @@ bool upgradeTrendModelToVersion6p3(const core_t::TTime bucketLength,
343
346
return true ;
344
347
}
345
348
349
+ // This implements the mapping from restored states to their best
350
+ // equivalents; specifically:
351
+ // SC_NEW_COMPONENTS |-> SC_NEW_COMPONENTS
352
+ // SC_NORMAL |-> SC_NORMAL
353
+ // SC_FORECASTING |-> SC_NORMAL
354
+ // SC_DISABLED |-> SC_DISABLED
355
+ // SC_ERROR |-> SC_ERROR
356
+ // Note that we don't try and restore the periodicity test state
357
+ // (see CTimeSeriesDecomposition::acceptRestoreTraverser) and the
358
+ // calendar test state is unchanged.
359
+ const TSizeSizeMap SC_STATES_UPGRADING_TO_VERSION_6_3{{0 , 0 }, {1 , 1 }, {2 , 1 }, {3 , 2 }, {4 , 3 }};
360
+
346
361
// //////////////////////////////////////////////////////////////////////
347
362
348
363
// Constants
@@ -482,8 +497,9 @@ bool CTimeSeriesDecompositionDetail::CPeriodicityTest::acceptRestoreTraverser(
482
497
do {
483
498
const std::string& name{traverser.name ()};
484
499
RESTORE (PERIODICITY_TEST_MACHINE_6_3_TAG,
485
- traverser.traverseSubLevel (boost::bind (
486
- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)))
500
+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
501
+ return m_Machine.acceptRestoreTraverser (traverser_);
502
+ }))
487
503
RESTORE_SETUP_TEARDOWN (
488
504
SHORT_WINDOW_6_3_TAG, m_Windows[E_Short].reset (this ->newWindow (E_Short)),
489
505
m_Windows[E_Short] && traverser.traverseSubLevel (boost::bind (
@@ -759,8 +775,9 @@ bool CTimeSeriesDecompositionDetail::CCalendarTest::acceptRestoreTraverser(core:
759
775
do {
760
776
const std::string& name{traverser.name ()};
761
777
RESTORE (CALENDAR_TEST_MACHINE_6_3_TAG,
762
- traverser.traverseSubLevel (boost::bind (
763
- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)))
778
+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
779
+ return m_Machine.acceptRestoreTraverser (traverser_);
780
+ }))
764
781
RESTORE_BUILT_IN (LAST_MONTH_6_3_TAG, m_LastMonth);
765
782
RESTORE_SETUP_TEARDOWN (
766
783
CALENDAR_TEST_6_3_TAG, m_Test.reset (new CCalendarCyclicTest (m_DecayRate)),
@@ -963,8 +980,9 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(core::C
963
980
while (traverser.next ()) {
964
981
const std::string& name{traverser.name ()};
965
982
RESTORE (COMPONENTS_MACHINE_6_3_TAG,
966
- traverser.traverseSubLevel (boost::bind (
967
- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)));
983
+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
984
+ return m_Machine.acceptRestoreTraverser (traverser_);
985
+ }))
968
986
RESTORE_BUILT_IN (DECAY_RATE_6_3_TAG, m_DecayRate);
969
987
RESTORE (TREND_6_3_TAG,
970
988
traverser.traverseSubLevel (boost::bind (
@@ -995,8 +1013,10 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(core::C
995
1013
do {
996
1014
const std::string& name{traverser.name ()};
997
1015
RESTORE (COMPONENTS_MACHINE_OLD_TAG,
998
- traverser.traverseSubLevel (boost::bind (
999
- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)));
1016
+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
1017
+ return m_Machine.acceptRestoreTraverser (
1018
+ traverser_, SC_STATES_UPGRADING_TO_VERSION_6_3);
1019
+ }))
1000
1020
RESTORE_SETUP_TEARDOWN (TREND_OLD_TAG,
1001
1021
/* */ ,
1002
1022
traverser.traverseSubLevel (boost::bind (
@@ -1017,7 +1037,7 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(core::C
1017
1037
/* */ )
1018
1038
} while (traverser.next ());
1019
1039
1020
- m_MeanVarianceScale.add (1.0 , MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 );
1040
+ m_MeanVarianceScale.add (1.0 , MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 );
1021
1041
}
1022
1042
return true ;
1023
1043
}
@@ -1679,6 +1699,7 @@ bool CTimeSeriesDecompositionDetail::CComponents::SSeasonal::acceptRestoreTraver
1679
1699
RESTORE (ERRORS_OLD_TAG,
1680
1700
core::CPersistUtils::restore (ERRORS_OLD_TAG, s_PredictionErrors, traverser))
1681
1701
} while (traverser.next ());
1702
+ s_PredictionErrors.resize (s_Components.size ());
1682
1703
}
1683
1704
return true ;
1684
1705
}
@@ -1907,6 +1928,7 @@ bool CTimeSeriesDecompositionDetail::CComponents::SCalendar::acceptRestoreTraver
1907
1928
RESTORE (ERRORS_OLD_TAG,
1908
1929
core::CPersistUtils::restore (ERRORS_OLD_TAG, s_PredictionErrors, traverser))
1909
1930
} while (traverser.next ());
1931
+ s_PredictionErrors.resize (s_Components.size ());
1910
1932
}
1911
1933
return true ;
1912
1934
}
0 commit comments