4646
4747#include < algorithm>
4848#include < cmath>
49+ #include < map>
4950#include < numeric>
5051#include < string>
5152#include < vector>
@@ -61,6 +62,7 @@ using TBoolVec = std::vector<bool>;
6162using TDoubleVec = std::vector<double >;
6263using TSizeVec = std::vector<std::size_t >;
6364using TSizeVecVec = std::vector<TSizeVec>;
65+ using TSizeSizeMap = std::map<std::size_t , std::size_t >;
6466using TStrVec = std::vector<std::string>;
6567using TTimeVec = std::vector<core_t ::TTime>;
6668using TTimeTimePr = std::pair<core_t ::TTime, core_t ::TTime>;
@@ -319,7 +321,7 @@ const std::string LAST_UPDATE_OLD_TAG{"j"};
319321
320322// ////////////////////// Upgrade to Version 6.3 ////////////////////////
321323
322- const double MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 {48.0 };
324+ const double MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 {48.0 };
323325
324326bool upgradeTrendModelToVersion6p3 (const core_t ::TTime bucketLength,
325327 CTrendComponent& trend,
@@ -342,7 +344,7 @@ bool upgradeTrendModelToVersion6p3(const core_t::TTime bucketLength,
342344
343345 // Generate some samples from the old trend model.
344346
345- double weight{MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 *
347+ double weight{MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 *
346348 static_cast <double >(bucketLength) / static_cast <double >(4 * WEEK)};
347349
348350 CPRNG::CXorOShiro128Plus rng;
@@ -355,6 +357,18 @@ bool upgradeTrendModelToVersion6p3(const core_t::TTime bucketLength,
355357 return true ;
356358}
357359
360+ // This implements the mapping from restored states to their best
361+ // equivalents; specifically:
362+ // SC_NEW_COMPONENTS |-> SC_NEW_COMPONENTS
363+ // SC_NORMAL |-> SC_NORMAL
364+ // SC_FORECASTING |-> SC_NORMAL
365+ // SC_DISABLED |-> SC_DISABLED
366+ // SC_ERROR |-> SC_ERROR
367+ // Note that we don't try and restore the periodicity test state
368+ // (see CTimeSeriesDecomposition::acceptRestoreTraverser) and the
369+ // calendar test state is unchanged.
370+ const TSizeSizeMap SC_STATES_UPGRADING_TO_VERSION_6_3{{0 , 0 }, {1 , 1 }, {2 , 1 }, {3 , 2 }, {4 , 3 }};
371+
358372// //////////////////////////////////////////////////////////////////////
359373
360374// Constants
@@ -490,8 +504,9 @@ bool CTimeSeriesDecompositionDetail::CPeriodicityTest::acceptRestoreTraverser(
490504 do {
491505 const std::string& name{traverser.name ()};
492506 RESTORE (PERIODICITY_TEST_MACHINE_6_3_TAG,
493- traverser.traverseSubLevel (boost::bind (
494- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)))
507+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
508+ return m_Machine.acceptRestoreTraverser (traverser_);
509+ }))
495510 RESTORE_SETUP_TEARDOWN (
496511 SHORT_WINDOW_6_3_TAG, m_Windows[E_Short].reset (this ->newWindow (E_Short)),
497512 m_Windows[E_Short] && traverser.traverseSubLevel (boost::bind (
@@ -792,8 +807,9 @@ bool CTimeSeriesDecompositionDetail::CCalendarTest::acceptRestoreTraverser(core:
792807 do {
793808 const std::string& name{traverser.name ()};
794809 RESTORE (CALENDAR_TEST_MACHINE_6_3_TAG,
795- traverser.traverseSubLevel (boost::bind (
796- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)))
810+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
811+ return m_Machine.acceptRestoreTraverser (traverser_);
812+ }))
797813 RESTORE_BUILT_IN (LAST_MONTH_6_3_TAG, m_LastMonth);
798814 RESTORE_SETUP_TEARDOWN (
799815 CALENDAR_TEST_6_3_TAG,
@@ -999,8 +1015,9 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(
9991015 while (traverser.next ()) {
10001016 const std::string& name{traverser.name ()};
10011017 RESTORE (COMPONENTS_MACHINE_6_3_TAG,
1002- traverser.traverseSubLevel (boost::bind (
1003- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)));
1018+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
1019+ return m_Machine.acceptRestoreTraverser (traverser_);
1020+ }))
10041021 RESTORE_BUILT_IN (DECAY_RATE_6_3_TAG, m_DecayRate);
10051022 RESTORE (GAIN_CONTROLLER_6_3_TAG,
10061023 traverser.traverseSubLevel (boost::bind (&CGainController::acceptRestoreTraverser,
@@ -1035,8 +1052,10 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(
10351052 do {
10361053 const std::string& name{traverser.name ()};
10371054 RESTORE (COMPONENTS_MACHINE_OLD_TAG,
1038- traverser.traverseSubLevel (boost::bind (
1039- &core::CStateMachine::acceptRestoreTraverser, &m_Machine, _1)));
1055+ traverser.traverseSubLevel ([this ](core::CStateRestoreTraverser& traverser_) {
1056+ return m_Machine.acceptRestoreTraverser (
1057+ traverser_, SC_STATES_UPGRADING_TO_VERSION_6_3);
1058+ }))
10401059 RESTORE_SETUP_TEARDOWN (TREND_OLD_TAG,
10411060 /* */ ,
10421061 traverser.traverseSubLevel (boost::bind (
@@ -1057,7 +1076,7 @@ bool CTimeSeriesDecompositionDetail::CComponents::acceptRestoreTraverser(
10571076 /* */ )
10581077 } while (traverser.next ());
10591078
1060- m_MeanVarianceScale.add (1.0 , MODEL_WEIGHT_UPGRADING_TO_VERSION_6p3 );
1079+ m_MeanVarianceScale.add (1.0 , MODEL_WEIGHT_UPGRADING_TO_VERSION_6_3 );
10611080 }
10621081 return true ;
10631082}
@@ -1951,13 +1970,15 @@ bool CTimeSeriesDecompositionDetail::CComponents::CSeasonal::acceptRestoreTraver
19511970 RESTORE_NO_ERROR (COMPONENT_6_3_TAG,
19521971 m_Components.emplace_back (decayRate, bucketLength, traverser))
19531972 }
1973+ m_PredictionErrors.resize (m_Components.size ());
19541974 } else {
19551975 // There is no version string this is historic state.
19561976 do {
19571977 const std::string& name{traverser.name ()};
19581978 RESTORE_NO_ERROR (COMPONENT_OLD_TAG,
19591979 m_Components.emplace_back (decayRate, bucketLength, traverser))
19601980 } while (traverser.next ());
1981+ m_PredictionErrors.resize (m_Components.size ());
19611982 }
19621983 return true ;
19631984}
@@ -2253,13 +2274,15 @@ bool CTimeSeriesDecompositionDetail::CComponents::CCalendar::acceptRestoreTraver
22532274 RESTORE_NO_ERROR (COMPONENT_6_3_TAG,
22542275 m_Components.emplace_back (decayRate, bucketLength, traverser))
22552276 }
2277+ m_PredictionErrors.resize (m_Components.size ());
22562278 } else {
22572279 // There is no version string this is historic state.
22582280 do {
22592281 const std::string& name{traverser.name ()};
22602282 RESTORE_NO_ERROR (COMPONENT_OLD_TAG,
22612283 m_Components.emplace_back (decayRate, bucketLength, traverser))
22622284 } while (traverser.next ());
2285+ m_PredictionErrors.resize (m_Components.size ());
22632286 }
22642287 return true ;
22652288}
0 commit comments