Skip to content

Commit 91c0057

Browse files
committed
More consistent naming in CTimeSeriesModel and avoid lots of overloads of the name prior
1 parent b8fa21c commit 91c0057

11 files changed

+546
-558
lines changed

include/core/Constants.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <core/CoreTypes.h>
1111

12+
#include <cmath>
1213
#include <limits>
13-
#include <math.h>
1414

1515
namespace ml
1616
{
@@ -19,38 +19,41 @@ namespace core
1919
namespace constants
2020
{
2121

22+
//! A minute in seconds.
23+
const core_t::TTime MINUTE{60};
24+
2225
//! An hour in seconds.
23-
const core_t::TTime HOUR = 3600;
26+
const core_t::TTime HOUR{3600};
2427

2528
//! A day in seconds.
26-
const core_t::TTime DAY = 86400;
29+
const core_t::TTime DAY{86400};
2730

2831
//! A (two day) weekend in seconds.
29-
const core_t::TTime WEEKEND = 172800;
32+
const core_t::TTime WEEKEND{172800};
3033

3134
//! Five weekdays in seconds.
32-
const core_t::TTime WEEKDAYS = 432000;
35+
const core_t::TTime WEEKDAYS{432000};
3336

3437
//! A week in seconds.
35-
const core_t::TTime WEEK = 604800;
38+
const core_t::TTime WEEK{604800};
3639

3740
//! A (364 day) year in seconds.
38-
const core_t::TTime YEAR = 31449600;
41+
const core_t::TTime YEAR{31449600};
3942

4043
//! Log of min double.
41-
const double LOG_MIN_DOUBLE = ::log(std::numeric_limits<double>::min());
44+
const double LOG_MIN_DOUBLE{std::log(std::numeric_limits<double>::min())};
4245

4346
//! Log of max double.
44-
const double LOG_MAX_DOUBLE = ::log(std::numeric_limits<double>::max());
47+
const double LOG_MAX_DOUBLE{std::log(std::numeric_limits<double>::max())};
4548

4649
//! Log of double epsilon.
47-
const double LOG_DOUBLE_EPSILON = ::log(std::numeric_limits<double>::epsilon());
50+
const double LOG_DOUBLE_EPSILON{std::log(std::numeric_limits<double>::epsilon())};
4851

4952
//! Log of two.
50-
const double LOG_TWO = 0.693147180559945;
53+
const double LOG_TWO{0.693147180559945};
5154

5255
//! Log of two pi.
53-
const double LOG_TWO_PI = 1.83787706640935;
56+
const double LOG_TWO_PI{1.83787706640935};
5457

5558
#ifdef Windows
5659
const char PATH_SEPARATOR = '\\';

include/maths/CTimeSeriesModel.h

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel
4141
public:
4242
//! \param[in] params The model parameters.
4343
//! \param[in] id The *unique* identifier for this time series.
44-
//! \param[in] trend The time series trend decomposition.
45-
//! \param[in] prior The time series residuals' prior.
44+
//! \param[in] trendModel The time series trend decomposition.
45+
//! \param[in] residualModel The prior for the time series residual model.
4646
//! \param[in] controllers Optional decay rate controllers for the trend
47-
//! and prior.
47+
//! and residual model.
4848
//! \param[in] modelAnomalies If true we use a separate model to capture
4949
//! the characteristics of anomalous time periods.
5050
CUnivariateTimeSeriesModel(const CModelParams &params,
5151
std::size_t id,
52-
const CTimeSeriesDecompositionInterface &trend,
53-
const CPrior &prior,
52+
const CTimeSeriesDecompositionInterface &trendModel,
53+
const CPrior &residualModel,
5454
const TDecayRateController2Ary *controllers = 0,
5555
bool modelAnomalies = true);
5656
CUnivariateTimeSeriesModel(const SModelRestoreParams &params,
@@ -63,7 +63,8 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel
6363
//! Create a copy of this model passing ownership to the caller.
6464
virtual CUnivariateTimeSeriesModel *clone(std::size_t id) const;
6565

66-
//! Create a copy of the state we need to persist passing ownership to the caller.
66+
//! Create a copy of the state we need to persist passing ownership
67+
//! to the caller.
6768
virtual CUnivariateTimeSeriesModel *cloneForPersistence(void) const;
6869

6970
//! Create a copy of the state we need to run forecasting.
@@ -93,8 +94,8 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel
9394
const maths_t::TWeightStyleVec &weightStyles,
9495
const TDouble2Vec4Vec &weights) const;
9596

96-
//! Get the most likely value for each correlate time series at
97-
//! \p time, if there are any.
97+
//! Get the most likely value for each correlate time series
98+
//! at \p time, if there are any.
9899
virtual TDouble2Vec1Vec correlateModes(core_t::TTime time,
99100
const maths_t::TWeightStyleVec &weightStyles,
100101
const TDouble2Vec4Vec1Vec &weights) const;
@@ -173,10 +174,10 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel
173174
const TTimeDoublePrCBuf &slidingWindow(void) const;
174175

175176
//! Get the trend.
176-
const CTimeSeriesDecompositionInterface &trend(void) const;
177+
const CTimeSeriesDecompositionInterface &trendModel(void) const;
177178

178-
//! Get the prior.
179-
const CPrior &prior(void) const;
179+
//! Get the residual model.
180+
const CPrior &residualModel(void) const;
180181
//@}
181182

182183
private:
@@ -224,18 +225,18 @@ class MATHS_EXPORT CUnivariateTimeSeriesModel : public CModel
224225
//! A random number generator for sampling the sliding window.
225226
CPRNG::CXorOShiro128Plus m_Rng;
226227

227-
//! These control the trend and prior decay rates (see CDecayRateController
228-
//! for more details).
228+
//! These control the trend and residual model decay rates (see
229+
//! CDecayRateController for more details).
229230
TDecayRateController2AryPtr m_Controllers;
230231

231232
//! The time series trend decomposition.
232-
TDecompositionPtr m_Trend;
233+
TDecompositionPtr m_TrendModel;
233234

234-
//! The prior for the time series' residual model.
235-
TPriorPtr m_Prior;
235+
//! The time series' residual model.
236+
TPriorPtr m_ResidualModel;
236237

237-
//! A model for time periods when the basic model can't predict the value
238-
//! of the time series.
238+
//! A model for time periods when the basic model can't predict the
239+
//! value of the time series.
239240
TAnomalyModelPtr m_AnomalyModel;
240241

241242
//! A sliding window of the recent samples (used to reinitialize the
@@ -318,9 +319,9 @@ class MATHS_EXPORT CTimeSeriesCorrelations
318319
TSize1Vec s_Tags;
319320
//! The sample weights.
320321
TDouble4Vec1Vec s_Weights;
321-
//! The interval by which to age the prior.
322+
//! The interval by which to age the correlation model.
322323
double s_Interval;
323-
//! The prior decay rate multiplier.
324+
//! The decay rate multiplier.
324325
double s_Multiplier;
325326
};
326327

@@ -333,7 +334,8 @@ class MATHS_EXPORT CTimeSeriesCorrelations
333334
//! Create a copy of this model passing ownership to the caller.
334335
CTimeSeriesCorrelations *clone(void) const;
335336

336-
//! Create a copy of the state we need to persist passing ownership to the caller.
337+
//! Create a copy of the state we need to persist passing ownership
338+
//! to the caller.
337339
CTimeSeriesCorrelations *cloneForPersistence(void) const;
338340

339341
//! Process all samples added from individual time series models.
@@ -350,7 +352,7 @@ class MATHS_EXPORT CTimeSeriesCorrelations
350352
void refresh(const CTimeSeriesCorrelateModelAllocator &allocator);
351353

352354
//! Get the correlation joint distribution models.
353-
const TSizeSizePrMultivariatePriorPtrDoublePrUMap &correlatePriors(void) const;
355+
const TSizeSizePrMultivariatePriorPtrDoublePrUMap &correlationModels(void) const;
354356

355357
//! Debug the memory used by this object.
356358
void debugMemoryUsage(core::CMemoryUsage::TMemoryUsagePtr mem) const;
@@ -377,20 +379,22 @@ class MATHS_EXPORT CTimeSeriesCorrelations
377379
CTimeSeriesCorrelations(const CTimeSeriesCorrelations &other,
378380
bool isForPersistence = false);
379381

380-
//! Restore the correlate priors reading state from \p traverser.
381-
bool restoreCorrelatePriors(const SDistributionRestoreParams &params,
382-
core::CStateRestoreTraverser &traverser);
382+
//! Restore the correlation distribution models reading state from
383+
//! \p traverser.
384+
bool restoreCorrelationModels(const SDistributionRestoreParams &params,
385+
core::CStateRestoreTraverser &traverser);
383386

384-
//! Persist the correlate priors passing information to \p inserter.
385-
void persistCorrelatePriors(core::CStatePersistInserter &inserter) const;
387+
//! Persist the correlation distribution models passing information
388+
//! to \p inserter.
389+
void persistCorrelationModels(core::CStatePersistInserter &inserter) const;
386390

387-
//! Restore the correlate priors reading state from \p traverser.
391+
//! Restore the \p model reading state from \p traverser.
388392
static bool restore(const SDistributionRestoreParams &params,
389-
TSizeSizePrMultivariatePriorPtrDoublePrPr &prior,
393+
TSizeSizePrMultivariatePriorPtrDoublePrPr &model,
390394
core::CStateRestoreTraverser &traverser);
391395

392-
//! Persist the correlate priors passing information to \p inserter.
393-
static void persist(const TSizeSizePrMultivariatePriorPtrDoublePrPr &prior,
396+
//! Persist the \p model passing information to \p inserter.
397+
static void persist(const TSizeSizePrMultivariatePriorPtrDoublePrPr &model,
394398
core::CStatePersistInserter &inserter);
395399

396400
//! Add the time series identified by \p id.
@@ -459,15 +463,15 @@ class MATHS_EXPORT CMultivariateTimeSeriesModel : public CModel
459463

460464
public:
461465
//! \param[in] params The model parameters.
462-
//! \param[in] trend The time series trend decomposition.
463-
//! \param[in] prior The time series residuals' prior.
466+
//! \param[in] trendModel The time series trend decomposition.
467+
//! \param[in] residualModel The prior for the time series residual model.
464468
//! \param[in] controllers Optional decay rate controllers for the trend
465-
//! and prior.
469+
//! and residual model.
466470
//! \param[in] modelAnomalies If true we use a separate model to capture
467471
//! the characteristics of anomalous time periods.
468472
CMultivariateTimeSeriesModel(const CModelParams &params,
469-
const CTimeSeriesDecompositionInterface &trend,
470-
const CMultivariatePrior &prior,
473+
const CTimeSeriesDecompositionInterface &trendModel,
474+
const CMultivariatePrior &residualModel,
471475
const TDecayRateController2Ary *controllers = 0,
472476
bool modelAnomalies = true);
473477
CMultivariateTimeSeriesModel(const CMultivariateTimeSeriesModel &other);
@@ -480,7 +484,8 @@ class MATHS_EXPORT CMultivariateTimeSeriesModel : public CModel
480484
//! Create a copy of this model passing ownership to the caller.
481485
virtual CMultivariateTimeSeriesModel *clone(std::size_t id) const;
482486

483-
//! Create a copy of the state we need to persist passing ownership to the caller.
487+
//! Create a copy of the state we need to persist passing ownership
488+
//! to the caller.
484489
virtual CMultivariateTimeSeriesModel *cloneForPersistence(void) const;
485490

486491
//! Create a copy of the state we need to run forecasting.
@@ -587,10 +592,10 @@ class MATHS_EXPORT CMultivariateTimeSeriesModel : public CModel
587592
const TTimeDouble2VecPrCBuf &slidingWindow(void) const;
588593

589594
//! Get the trend.
590-
const TDecompositionPtr10Vec &trend(void) const;
595+
const TDecompositionPtr10Vec &trendModel(void) const;
591596

592-
//! Get the prior.
593-
const CMultivariatePrior &prior(void) const;
597+
//! Get the residual model.
598+
const CMultivariatePrior &residualModel(void) const;
594599
//@}
595600

596601
private:
@@ -624,18 +629,18 @@ class MATHS_EXPORT CMultivariateTimeSeriesModel : public CModel
624629
//! A random number generator for sampling the sliding window.
625630
CPRNG::CXorOShiro128Plus m_Rng;
626631

627-
//! These control the trend and prior decay rates (see CDecayRateController
628-
//! for more details).
632+
//! These control the trend and residual model decay rates (see
633+
//! CDecayRateController for more details).
629634
TDecayRateController2AryPtr m_Controllers;
630635

631636
//! The time series trend decomposition.
632-
TDecompositionPtr10Vec m_Trend;
637+
TDecompositionPtr10Vec m_TrendModel;
633638

634-
//! The prior for the time series' residual model.
635-
TMultivariatePriorPtr m_Prior;
639+
//! The time series residual model.
640+
TMultivariatePriorPtr m_ResidualModel;
636641

637-
//! A model for time periods when the basic model can't predict the value
638-
//! of the time series.
642+
//! A model for time periods when the basic model can't predict the
643+
//! value of the time series.
639644
TAnomalyModelPtr m_AnomalyModel;
640645

641646
//! A sliding window of the recent samples (used to reinitialize the

0 commit comments

Comments
 (0)