21 #define GRT_DLL_EXPORTS
27 this->trimThreshold = trimThreshold;
28 this->maximumTrimPercentage = maximumTrimPercentage;
29 debugLog.setProceedingText(
"[DEBUG TimeSeriesTrimmer]");
30 warningLog.setProceedingText(
"[WARNING TimeSeriesTrimmer]");
31 errorLog.setProceedingText(
"[ERROR TimeSeriesTrimmer]");
38 const UINT M = timeSeries.getLength();
39 const UINT N = timeSeries.getNumDimensions();
42 warningLog <<
"trimTimeSeries(TimeSeriesClassificationSample &timeSeries) - can't trim data, the length of the input time series is 0!" << std::endl;
47 warningLog <<
"trimTimeSeries(TimeSeriesClassificationSample &timeSeries) - can't trim data, the number of dimensions in the input time series is 0!" << std::endl;
55 for(UINT i=1; i<M; i++){
56 for(UINT j=0; j<N; j++){
57 x[i] += fabs(timeSeries[i][j]-timeSeries[i-1][j]);
60 if( x[i] > maxValue ) maxValue = x[i];
66 for(UINT i=1; i<M; i++){
69 if( x[i] > trimThreshold && firstIndex == 0 ){
76 for(UINT i=M-1; i>firstIndex; i--){
77 if( x[i] > trimThreshold && lastIndex == 0 ){
83 if( firstIndex == 0 && lastIndex == 0 ){
84 warningLog <<
"Failed to find either the first index or the last index!" << std::endl;
88 if( firstIndex == lastIndex ){
89 warningLog <<
"The first index and last index are the same!" << std::endl;
93 if( firstIndex > lastIndex ){
94 warningLog <<
"The first index is greater than the last index!" << std::endl;
99 warningLog <<
"Failed to find the last index!" << std::endl;
104 UINT newM = lastIndex-firstIndex;
105 Float trimPercentage = (Float(newM) / Float(M)) * 100.0;
107 if( 100 - trimPercentage <= maximumTrimPercentage ){
111 for(UINT i=firstIndex; i<lastIndex; i++){
112 for(UINT j=0; j<N; j++){
113 newTimeSeries[index][j] = timeSeries[i][j];
118 timeSeries.setTrainingSample(timeSeries.getClassLabel(), newTimeSeries);
122 warningLog <<
"Maximum Trim Percentage Excedded, Can't Trim Sample!";
123 warningLog <<
" Original Timeseries Length: " << M <<
" Trimmed Timeseries Length: " << newM;
124 warningLog <<
" Percentage: " << (100-trimPercentage) <<
" MaximumTrimPercentage: " << maximumTrimPercentage << std::endl;
TimeSeriesClassificationSampleTrimmer(Float trimThreshold=0.1, Float maximumTrimPercentage=80)
This class provides a useful tool to automatically trim timeseries data.
bool trimTimeSeries(TimeSeriesClassificationSample &timeSeries)
~TimeSeriesClassificationSampleTrimmer()