Skip to content

Commit 27e5a93

Browse files
author
Hendrik Muhs
committed
improve error message for splitting failure (#152)
improve the logging of the error message reported in #142. relates #142
1 parent 7410d96 commit 27e5a93

10 files changed

+72
-19
lines changed

include/maths/CAdaptiveBucketing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class MATHS_EXPORT CAdaptiveBucketing {
130130
TDoubleVec variances() const;
131131
//@}
132132

133+
//! Name of component
134+
virtual std::string name() const = 0;
135+
133136
protected:
134137
using TRestoreFunc = std::function<bool(core::CStateRestoreTraverser&)>;
135138
using TPersistFunc = std::function<void(core::CStatePersistInserter&)>;

include/maths/CCalendarComponentAdaptiveBucketing.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CSeasonalTime;
3232
//!
3333
//! DESCRIPTION:\n
3434
//! See CAdaptiveBucketing for details.
35-
class MATHS_EXPORT CCalendarComponentAdaptiveBucketing : public CAdaptiveBucketing {
35+
class MATHS_EXPORT CCalendarComponentAdaptiveBucketing final : public CAdaptiveBucketing {
3636
public:
3737
using TFloatMeanVarAccumulator = CBasicStatistics::SSampleMeanVar<CFloatStorage>::TAccumulator;
3838
using CAdaptiveBucketing::count;
@@ -97,6 +97,9 @@ class MATHS_EXPORT CCalendarComponentAdaptiveBucketing : public CAdaptiveBucketi
9797
//! Get the memory used by this component
9898
std::size_t memoryUsage() const;
9999

100+
//! Name of component
101+
std::string name() const override;
102+
100103
private:
101104
using TFloatMeanVarVec = std::vector<TFloatMeanVarAccumulator>;
102105

@@ -110,28 +113,28 @@ class MATHS_EXPORT CCalendarComponentAdaptiveBucketing : public CAdaptiveBucketi
110113
//! bucket configuration.
111114
//!
112115
//! \param[in] endpoints The old end points.
113-
void refresh(const TFloatVec& endpoints);
116+
void refresh(const TFloatVec& endpoints) override;
114117

115118
//! Check if \p time is in the this component's window.
116-
virtual bool inWindow(core_t::TTime time) const;
119+
bool inWindow(core_t::TTime time) const override;
117120

118121
//! Add the function value to \p bucket.
119-
virtual void add(std::size_t bucket, core_t::TTime time, double value, double weight);
122+
void add(std::size_t bucket, core_t::TTime time, double value, double weight) override;
120123

121124
//! Get the offset w.r.t. the start of the bucketing of \p time.
122-
virtual double offset(core_t::TTime time) const;
125+
double offset(core_t::TTime time) const override;
123126

124127
//! Get the count in \p bucket.
125-
virtual double bucketCount(std::size_t bucket) const;
128+
double bucketCount(std::size_t bucket) const override;
126129

127130
//! Get the predicted value for \p bucket at \p time.
128-
virtual double predict(std::size_t bucket, core_t::TTime time, double offset) const;
131+
double predict(std::size_t bucket, core_t::TTime time, double offset) const override;
129132

130133
//! Get the variance of \p bucket.
131-
virtual double variance(std::size_t bucket) const;
134+
double variance(std::size_t bucket) const override;
132135

133136
//! Split \p bucket.
134-
virtual void split(std::size_t bucket);
137+
void split(std::size_t bucket) override;
135138

136139
private:
137140
//! The time provider.

include/maths/CSeasonalComponentAdaptiveBucketing.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace maths {
3232
//!
3333
//! DESCRIPTION:\n
3434
//! See CAdaptiveBucketing for details.
35-
class MATHS_EXPORT CSeasonalComponentAdaptiveBucketing : public CAdaptiveBucketing {
35+
class MATHS_EXPORT CSeasonalComponentAdaptiveBucketing final : public CAdaptiveBucketing {
3636
public:
3737
using CAdaptiveBucketing::TFloatMeanAccumulatorVec;
3838
using TDoubleRegression = CRegression::CLeastSquaresOnline<1, double>;
@@ -130,6 +130,9 @@ class MATHS_EXPORT CSeasonalComponentAdaptiveBucketing : public CAdaptiveBucketi
130130
//! Get the memory used by this component
131131
std::size_t memoryUsage() const;
132132

133+
//! Name of component
134+
std::string name() const override;
135+
133136
private:
134137
using TSeasonalTimePtr = std::unique_ptr<CSeasonalTime>;
135138

@@ -163,28 +166,28 @@ class MATHS_EXPORT CSeasonalComponentAdaptiveBucketing : public CAdaptiveBucketi
163166
//! bucket configuration.
164167
//!
165168
//! \param[in] endpoints The old end points.
166-
void refresh(const TFloatVec& endpoints);
169+
void refresh(const TFloatVec& endpoints) override;
167170

168171
//! Check if \p time is in the this component's window.
169-
virtual bool inWindow(core_t::TTime time) const;
172+
bool inWindow(core_t::TTime time) const override;
170173

171174
//! Add the function value at \p time.
172-
virtual void add(std::size_t bucket, core_t::TTime time, double value, double weight);
175+
void add(std::size_t bucket, core_t::TTime time, double value, double weight) override;
173176

174177
//! Get the offset w.r.t. the start of the bucketing of \p time.
175-
virtual double offset(core_t::TTime time) const;
178+
double offset(core_t::TTime time) const override;
176179

177180
//! The count in \p bucket.
178-
virtual double bucketCount(std::size_t bucket) const;
181+
double bucketCount(std::size_t bucket) const override;
179182

180183
//! Get the predicted value for \p bucket at \p time.
181-
virtual double predict(std::size_t bucket, core_t::TTime time, double offset) const;
184+
double predict(std::size_t bucket, core_t::TTime time, double offset) const override;
182185

183186
//! Get the variance of \p bucket.
184-
virtual double variance(std::size_t bucket) const;
187+
double variance(std::size_t bucket) const override;
185188

186189
//! Split \p bucket.
187-
virtual void split(std::size_t bucket);
190+
void split(std::size_t bucket) override;
188191

189192
//! Get the interval which has been observed at \p time.
190193
double observedInterval(core_t::TTime time) const;

lib/maths/CAdaptiveBucketing.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ void CAdaptiveBucketing::maybeSplitBucket() {
673673
CTools::safeCdfComplement(binomial, m_LargeErrorCounts[i - 1])};
674674
m_LargeErrorCountSignificances.add({oneMinusCdf, i - 1});
675675
} catch (const std::exception& e) {
676-
LOG_ERROR(<< "Failed to calculate splitting significance: " << e.what());
676+
LOG_ERROR(<< "Failed to calculate splitting significance: " << e.what()
677+
<< " interval = " << interval << " period = " << period
678+
<< " type = " << this->name());
677679
}
678680
}
679681
if (m_LargeErrorCountSignificances.count() > 0) {

lib/maths/CCalendarComponentAdaptiveBucketing.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,10 @@ void CCalendarComponentAdaptiveBucketing::split(std::size_t bucket) {
351351
CBasicStatistics::scale(0.25, m_Values[bucket]);
352352
m_Values.insert(m_Values.begin() + bucket, m_Values[bucket]);
353353
}
354+
355+
std::string CCalendarComponentAdaptiveBucketing::name() const {
356+
return "Calendar[" + std::to_string(this->decayRate()) + "," +
357+
std::to_string(this->minimumBucketLength()) + "]";
358+
}
354359
}
355360
}

lib/maths/CSeasonalComponentAdaptiveBucketing.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ void CSeasonalComponentAdaptiveBucketing::split(std::size_t bucket) {
573573
m_Buckets.insert(m_Buckets.begin() + bucket, m_Buckets[bucket]);
574574
}
575575

576+
std::string CSeasonalComponentAdaptiveBucketing::name() const {
577+
return "Seasonal[" + std::to_string(this->decayRate()) + "," +
578+
std::to_string(this->minimumBucketLength()) + "]";
579+
}
580+
576581
double CSeasonalComponentAdaptiveBucketing::observedInterval(core_t::TTime time) const {
577582
return m_Time->regressionInterval(
578583
std::min_element(m_Buckets.begin(), m_Buckets.end(),

lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,18 @@ void CCalendarComponentAdaptiveBucketingTest::testPersist() {
472472
CPPUNIT_ASSERT_EQUAL(origXml, newXml);
473473
}
474474

475+
void CCalendarComponentAdaptiveBucketingTest::testName() {
476+
double decayRate{0.1};
477+
double minimumBucketLength{1.0};
478+
479+
maths::CCalendarFeature feature{maths::CCalendarFeature::DAYS_SINCE_START_OF_MONTH, 0};
480+
maths::CCalendarComponentAdaptiveBucketing bucketing{feature, decayRate, minimumBucketLength};
481+
482+
CPPUNIT_ASSERT_EQUAL(std::string("Calendar[") + std::to_string(decayRate) +
483+
"," + std::to_string(minimumBucketLength) + "]",
484+
bucketing.name());
485+
}
486+
475487
CppUnit::Test* CCalendarComponentAdaptiveBucketingTest::suite() {
476488
CppUnit::TestSuite* suiteOfTests =
477489
new CppUnit::TestSuite("CCalendarComponentAdaptiveBucketingTest");
@@ -500,6 +512,9 @@ CppUnit::Test* CCalendarComponentAdaptiveBucketingTest::suite() {
500512
suiteOfTests->addTest(new CppUnit::TestCaller<CCalendarComponentAdaptiveBucketingTest>(
501513
"CCalendarComponentAdaptiveBucketingTest::testPersist",
502514
&CCalendarComponentAdaptiveBucketingTest::testPersist));
515+
suiteOfTests->addTest(new CppUnit::TestCaller<CCalendarComponentAdaptiveBucketingTest>(
516+
"CCalendarComponentAdaptiveBucketingTest::testName",
517+
&CCalendarComponentAdaptiveBucketingTest::testName));
503518

504519
return suiteOfTests;
505520
}

lib/maths/unittest/CCalendarComponentAdaptiveBucketingTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CCalendarComponentAdaptiveBucketingTest : public CppUnit::TestFixture {
2121
void testUnintialized();
2222
void testKnots();
2323
void testPersist();
24+
void testName();
2425

2526
static CppUnit::Test* suite();
2627

lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,18 @@ void CSeasonalComponentAdaptiveBucketingTest::testUpgrade() {
786786
core::CContainerPrinter::print(restoredVariances));
787787
}
788788

789+
void CSeasonalComponentAdaptiveBucketingTest::testName() {
790+
double decayRate{0.1};
791+
double minimumBucketLength{1.0};
792+
793+
maths::CDiurnalTime time(0, 0, core::constants::WEEK, core::constants::DAY);
794+
maths::CSeasonalComponentAdaptiveBucketing bucketing(time, decayRate, minimumBucketLength);
795+
796+
CPPUNIT_ASSERT_EQUAL(std::string("Seasonal[") + std::to_string(decayRate) +
797+
"," + std::to_string(minimumBucketLength) + "]",
798+
bucketing.name());
799+
}
800+
789801
CppUnit::Test* CSeasonalComponentAdaptiveBucketingTest::suite() {
790802
CppUnit::TestSuite* suiteOfTests =
791803
new CppUnit::TestSuite("CSeasonalComponentAdaptiveBucketingTest");
@@ -826,6 +838,9 @@ CppUnit::Test* CSeasonalComponentAdaptiveBucketingTest::suite() {
826838
suiteOfTests->addTest(new CppUnit::TestCaller<CSeasonalComponentAdaptiveBucketingTest>(
827839
"CSeasonalComponentAdaptiveBucketingTest::testUpgrade",
828840
&CSeasonalComponentAdaptiveBucketingTest::testUpgrade));
841+
suiteOfTests->addTest(new CppUnit::TestCaller<CSeasonalComponentAdaptiveBucketingTest>(
842+
"CSeasonalComponentAdaptiveBucketingTest::testName",
843+
&CSeasonalComponentAdaptiveBucketingTest::testName));
829844

830845
return suiteOfTests;
831846
}

lib/maths/unittest/CSeasonalComponentAdaptiveBucketingTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CSeasonalComponentAdaptiveBucketingTest : public CppUnit::TestFixture {
2323
void testSlope();
2424
void testPersist();
2525
void testUpgrade();
26+
void testName();
2627

2728
static CppUnit::Test* suite();
2829
};

0 commit comments

Comments
 (0)