@@ -19,103 +19,101 @@ using TDouble1Vec = core::CSmallVector<double, 1>;
1919using TDouble10Vec = core::CSmallVector<double , 10 >;
2020using 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}
0 commit comments