Skip to content

Commit c32772a

Browse files
committed
Review comments
1 parent f4962df commit c32772a

File tree

5 files changed

+105
-104
lines changed

5 files changed

+105
-104
lines changed

include/model/CAnomalyDetectorModelConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class MODEL_EXPORT CAnomalyDetectorModelConfig {
164164

165165
//! The default number of time buckets used to generate multibucket features
166166
//! for anomaly detection.
167-
static const std::size_t MULTIBUCKET_FEATURE_WINDOW_LENGTH;
167+
static const std::size_t MULTIBUCKET_FEATURES_WINDOW_LENGTH;
168168

169169
//! The maximum number of times we'll update a model in a bucketing
170170
//! interval. This only applies to our metric statistics, which are

lib/maths/unittest/CTimeSeriesMultibucketFeaturesTest.cc

Lines changed: 99 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -19,103 +19,101 @@ using TDouble1Vec = core::CSmallVector<double, 1>;
1919
using TDouble10Vec = core::CSmallVector<double, 10>;
2020
using TDouble10Vec1Vec = core::CSmallVector<TDouble10Vec, 1>;
2121

22-
void CTimeSeriesMultibucketFeaturesTest::testMean() {
23-
// Test we get the value and weight we expect.
24-
25-
LOG_DEBUG(<< "Univariate");
26-
{
27-
using TMeanAccumulator = maths::CBasicStatistics::SSampleMean<double>::TAccumulator;
28-
using TTimeMeanAccumulatorPr = std::pair<core_t::TTime, TMeanAccumulator>;
29-
using TTimeMeanAccumulatorPrVec = std::vector<TTimeMeanAccumulatorPr>;
30-
31-
TTimeMeanAccumulatorPrVec buf;
32-
33-
TDouble1Vec mean;
34-
maths_t::TDoubleWeightsAry1Vec weight;
35-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
36-
buf.begin(), buf.end());
37-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
38-
CPPUNIT_ASSERT(mean.empty());
39-
CPPUNIT_ASSERT(weight.empty());
40-
41-
buf.emplace_back(10, maths::CBasicStatistics::accumulator(1.1, 5.0));
42-
buf.emplace_back(20, maths::CBasicStatistics::accumulator(0.3, 7.0));
43-
buf.emplace_back(30, maths::CBasicStatistics::accumulator(0.6, 3.0));
44-
45-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
46-
buf.begin(), buf.begin() + 1);
47-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
48-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
49-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
50-
CPPUNIT_ASSERT_EQUAL(5.0, mean[0]);
51-
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::seasonalVarianceScale(weight[0]));
52-
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::countVarianceScale(weight[0]));
53-
CPPUNIT_ASSERT_EQUAL(1.1, maths_t::countForUpdate(weight[0]));
54-
55-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
56-
buf.begin(), buf.end());
57-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
58-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
59-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
60-
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.6252, mean[0], 5e-5);
61-
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::seasonalVarianceScale(weight[0]));
62-
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::countVarianceScale(weight[0]));
63-
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.807, maths_t::countForUpdate(weight[0]), 5e-5);
64-
}
22+
void CTimeSeriesMultibucketFeaturesTest::testUnivariateMean() {
23+
// Test we get the values and weights we expect.
24+
25+
using TMeanAccumulator = maths::CBasicStatistics::SSampleMean<double>::TAccumulator;
26+
using TTimeMeanAccumulatorPr = std::pair<core_t::TTime, TMeanAccumulator>;
27+
using TTimeMeanAccumulatorPrVec = std::vector<TTimeMeanAccumulatorPr>;
28+
29+
TTimeMeanAccumulatorPrVec buf;
30+
31+
TDouble1Vec mean;
32+
maths_t::TDoubleWeightsAry1Vec weight;
33+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
34+
buf.begin(), buf.end());
35+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
36+
CPPUNIT_ASSERT(mean.empty());
37+
CPPUNIT_ASSERT(weight.empty());
38+
39+
buf.emplace_back(10, maths::CBasicStatistics::accumulator(1.1, 5.0));
40+
buf.emplace_back(20, maths::CBasicStatistics::accumulator(0.3, 7.0));
41+
buf.emplace_back(30, maths::CBasicStatistics::accumulator(0.6, 3.0));
42+
43+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
44+
buf.begin(), buf.begin() + 1);
45+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
46+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
47+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
48+
CPPUNIT_ASSERT_EQUAL(5.0, mean[0]);
49+
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::seasonalVarianceScale(weight[0]));
50+
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::countVarianceScale(weight[0]));
51+
CPPUNIT_ASSERT_EQUAL(1.1, maths_t::countForUpdate(weight[0]));
52+
53+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<double>(
54+
buf.begin(), buf.end());
55+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
56+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
57+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
58+
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.6252, mean[0], 5e-5);
59+
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::seasonalVarianceScale(weight[0]));
60+
CPPUNIT_ASSERT_EQUAL(1.0, maths_t::countVarianceScale(weight[0]));
61+
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.807, maths_t::countForUpdate(weight[0]), 5e-5);
62+
}
6563

66-
LOG_DEBUG(<< "Multivariate");
67-
{
68-
using TVector = maths::CVector<double>;
69-
using TMeanAccumulator = maths::CBasicStatistics::SSampleMean<TVector>::TAccumulator;
70-
using TTimeMeanAccumulatorPr = std::pair<core_t::TTime, TMeanAccumulator>;
71-
using TTimeMeanAccumulatorPrVec = std::vector<TTimeMeanAccumulatorPr>;
72-
73-
TTimeMeanAccumulatorPrVec buf;
74-
75-
TDouble10Vec1Vec mean;
76-
maths_t::TDouble10VecWeightsAry1Vec weight;
77-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
78-
buf.begin(), buf.end());
79-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
80-
CPPUNIT_ASSERT(mean.empty());
81-
CPPUNIT_ASSERT(weight.empty());
82-
83-
buf.emplace_back(1, maths::CBasicStatistics::accumulator(
84-
1.1, TVector(TDouble1Vec{5.0, 4.0})));
85-
buf.emplace_back(2, maths::CBasicStatistics::accumulator(
86-
0.3, TVector(TDouble1Vec{7.0, 6.0})));
87-
buf.emplace_back(3, maths::CBasicStatistics::accumulator(
88-
0.6, TVector(TDouble1Vec{3.0, 2.0})));
89-
90-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
91-
buf.begin(), buf.begin() + 1);
92-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
93-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
94-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
95-
CPPUNIT_ASSERT_EQUAL(std::string("[5, 4]"),
96-
core::CContainerPrinter::print(mean[0]));
97-
CPPUNIT_ASSERT_EQUAL(std::string("[1, 1]"),
98-
core::CContainerPrinter::print(
99-
maths_t::seasonalVarianceScale(weight[0])));
100-
CPPUNIT_ASSERT_EQUAL(
101-
std::string("[1, 1]"),
102-
core::CContainerPrinter::print(maths_t::countVarianceScale(weight[0])));
103-
CPPUNIT_ASSERT_EQUAL(
104-
std::string("[1.1, 1.1]"),
105-
core::CContainerPrinter::print(maths_t::countForUpdate(weight[0])));
106-
107-
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
108-
buf.begin(), buf.end());
109-
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
110-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
111-
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
112-
CPPUNIT_ASSERT_EQUAL(std::size_t(2), mean[0].size());
113-
CPPUNIT_ASSERT_EQUAL(std::size_t(2), maths_t::countForUpdate(weight[0]).size());
114-
double expectedMean[]{4.6252, 3.6252};
115-
for (std::size_t i = 0; i < 2; ++i) {
116-
CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedMean[i], mean[0][i], 5e-5);
117-
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.807, maths_t::countForUpdate(weight[0])[i], 5e-5);
118-
}
64+
void CTimeSeriesMultibucketFeaturesTest::testMultivariateMean() {
65+
// Test we get the values and weights we expect.
66+
67+
using TVector = maths::CVector<double>;
68+
using TMeanAccumulator = maths::CBasicStatistics::SSampleMean<TVector>::TAccumulator;
69+
using TTimeMeanAccumulatorPr = std::pair<core_t::TTime, TMeanAccumulator>;
70+
using TTimeMeanAccumulatorPrVec = std::vector<TTimeMeanAccumulatorPr>;
71+
72+
TTimeMeanAccumulatorPrVec buf;
73+
74+
TDouble10Vec1Vec mean;
75+
maths_t::TDouble10VecWeightsAry1Vec weight;
76+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
77+
buf.begin(), buf.end());
78+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
79+
CPPUNIT_ASSERT(mean.empty());
80+
CPPUNIT_ASSERT(weight.empty());
81+
82+
buf.emplace_back(1, maths::CBasicStatistics::accumulator(
83+
1.1, TVector(TDouble1Vec{5.0, 4.0})));
84+
buf.emplace_back(2, maths::CBasicStatistics::accumulator(
85+
0.3, TVector(TDouble1Vec{7.0, 6.0})));
86+
buf.emplace_back(3, maths::CBasicStatistics::accumulator(
87+
0.6, TVector(TDouble1Vec{3.0, 2.0})));
88+
89+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
90+
buf.begin(), buf.begin() + 1);
91+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
92+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
93+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
94+
CPPUNIT_ASSERT_EQUAL(std::string("[5, 4]"),
95+
core::CContainerPrinter::print(mean[0]));
96+
CPPUNIT_ASSERT_EQUAL(std::string("[1, 1]"),
97+
core::CContainerPrinter::print(
98+
maths_t::seasonalVarianceScale(weight[0])));
99+
CPPUNIT_ASSERT_EQUAL(
100+
std::string("[1, 1]"),
101+
core::CContainerPrinter::print(maths_t::countVarianceScale(weight[0])));
102+
CPPUNIT_ASSERT_EQUAL(
103+
std::string("[1.1, 1.1]"),
104+
core::CContainerPrinter::print(maths_t::countForUpdate(weight[0])));
105+
106+
std::tie(mean, weight) = maths::CTimeSeriesMultibucketFeatures::mean<TDouble10Vec>(
107+
buf.begin(), buf.end());
108+
LOG_DEBUG(<< "mean = " << mean << " weight = " << weight);
109+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), mean.size());
110+
CPPUNIT_ASSERT_EQUAL(std::size_t(1), weight.size());
111+
CPPUNIT_ASSERT_EQUAL(std::size_t(2), mean[0].size());
112+
CPPUNIT_ASSERT_EQUAL(std::size_t(2), maths_t::countForUpdate(weight[0]).size());
113+
double expectedMean[]{4.6252, 3.6252};
114+
for (std::size_t i = 0; i < 2; ++i) {
115+
CPPUNIT_ASSERT_DOUBLES_EQUAL(expectedMean[i], mean[0][i], 5e-5);
116+
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.807, maths_t::countForUpdate(weight[0])[i], 5e-5);
119117
}
120118
}
121119

@@ -124,8 +122,11 @@ CppUnit::Test* CTimeSeriesMultibucketFeaturesTest::suite() {
124122
new CppUnit::TestSuite("CTimeSeriesMultibucketFeaturesTest");
125123

126124
suiteOfTests->addTest(new CppUnit::TestCaller<CTimeSeriesMultibucketFeaturesTest>(
127-
"CTimeSeriesMultibucketFeaturesTest::testMean",
128-
&CTimeSeriesMultibucketFeaturesTest::testMean));
125+
"CTimeSeriesMultibucketFeaturesTest::testUnivariateMean",
126+
&CTimeSeriesMultibucketFeaturesTest::testUnivariateMean));
127+
suiteOfTests->addTest(new CppUnit::TestCaller<CTimeSeriesMultibucketFeaturesTest>(
128+
"CTimeSeriesMultibucketFeaturesTest::testMultivariateMean",
129+
&CTimeSeriesMultibucketFeaturesTest::testMultivariateMean));
129130

130131
return suiteOfTests;
131132
}

lib/maths/unittest/CTimeSeriesMultibucketFeaturesTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class CTimeSeriesMultibucketFeaturesTest : public CppUnit::TestFixture {
1313
public:
14-
void testMean();
15-
void testContrast();
14+
void testUnivariateMean();
15+
void testMultivariateMean();
1616

1717
static CppUnit::Test* suite();
1818
};

lib/model/CAnomalyDetectorModelConfig.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const core_t::TTime
7373
CAnomalyDetectorModelConfig::DEFAULT_MINIMUM_TIME_TO_DETECT_CHANGE(16 * core::constants::HOUR);
7474
const core_t::TTime
7575
CAnomalyDetectorModelConfig::DEFAULT_MAXIMUM_TIME_TO_TEST_FOR_CHANGE(core::constants::DAY);
76-
const std::size_t CAnomalyDetectorModelConfig::MULTIBUCKET_FEATURE_WINDOW_LENGTH(12);
76+
const std::size_t CAnomalyDetectorModelConfig::MULTIBUCKET_FEATURES_WINDOW_LENGTH(12);
7777
const double CAnomalyDetectorModelConfig::DEFAULT_MAXIMUM_UPDATES_PER_BUCKET(1.0);
7878
const double CAnomalyDetectorModelConfig::DEFAULT_INFLUENCE_CUTOFF(0.4);
7979
const double CAnomalyDetectorModelConfig::DEFAULT_PRUNE_WINDOW_SCALE_MINIMUM(0.25);
@@ -201,7 +201,7 @@ void CAnomalyDetectorModelConfig::interimBucketCorrector(const TInterimBucketCor
201201
void CAnomalyDetectorModelConfig::useMultibucketFeatures(bool enabled) {
202202
for (auto& factory : m_Factories) {
203203
factory.second->multibucketFeaturesWindowLength(
204-
enabled ? MULTIBUCKET_FEATURE_WINDOW_LENGTH : 0);
204+
enabled ? MULTIBUCKET_FEATURES_WINDOW_LENGTH : 0);
205205
}
206206
}
207207

lib/model/CModelParams.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SModelParams::SModelParams(core_t::TTime bucketLength)
3434
s_ComponentSize(CAnomalyDetectorModelConfig::DEFAULT_COMPONENT_SIZE),
3535
s_MinimumTimeToDetectChange(CAnomalyDetectorModelConfig::DEFAULT_MINIMUM_TIME_TO_DETECT_CHANGE),
3636
s_MaximumTimeToTestForChange(CAnomalyDetectorModelConfig::DEFAULT_MAXIMUM_TIME_TO_TEST_FOR_CHANGE),
37-
s_MultibucketFeaturesWindowLength(CAnomalyDetectorModelConfig::MULTIBUCKET_FEATURE_WINDOW_LENGTH),
37+
s_MultibucketFeaturesWindowLength(CAnomalyDetectorModelConfig::MULTIBUCKET_FEATURES_WINDOW_LENGTH),
3838
s_MultivariateByFields(false),
3939
s_CorrelationModelsOverhead(CAnomalyDetectorModelConfig::DEFAULT_CORRELATION_MODELS_OVERHEAD),
4040
s_MinimumSignificantCorrelation(

0 commit comments

Comments
 (0)