26 this->trimThreshold = trimThreshold;
27 this->maximumTrimPercentage = maximumTrimPercentage;
28 debugLog.setProceedingText(
"[DEBUG TimeSeriesTrimmer]");
29 warningLog.setProceedingText(
"[WARNING TimeSeriesTrimmer]");
30 errorLog.setProceedingText(
"[ERROR TimeSeriesTrimmer]");
37 const UINT M = timeSeries.getLength();
38 const UINT N = timeSeries.getNumDimensions();
41 warningLog <<
"trimTimeSeries(TimeSeriesClassificationSample &timeSeries) - can't trim data, the length of the input time series is 0!" << std::endl;
46 warningLog <<
"trimTimeSeries(TimeSeriesClassificationSample &timeSeries) - can't trim data, the number of dimensions in the input time series is 0!" << std::endl;
54 for(UINT i=1; i<M; i++){
55 for(UINT j=0; j<N; j++){
56 x[i] += fabs(timeSeries[i][j]-timeSeries[i-1][j]);
59 if( x[i] > maxValue ) maxValue = x[i];
65 for(UINT i=1; i<M; i++){
68 if( x[i] > trimThreshold && firstIndex == 0 ){
75 for(UINT i=M-1; i>firstIndex; i--){
76 if( x[i] > trimThreshold && lastIndex == 0 ){
82 if( firstIndex == 0 && lastIndex == 0 ){
83 warningLog <<
"Failed to find either the first index or the last index!" << std::endl;
87 if( firstIndex == lastIndex ){
88 warningLog <<
"The first index and last index are the same!" << std::endl;
92 if( firstIndex > lastIndex ){
93 warningLog <<
"The first index is greater than the last index!" << std::endl;
98 warningLog <<
"Failed to find the last index!" << std::endl;
103 UINT newM = lastIndex-firstIndex;
104 Float trimPercentage = (Float(newM) / Float(M)) * 100.0;
106 if( 100 - trimPercentage <= maximumTrimPercentage ){
110 for(UINT i=firstIndex; i<lastIndex; i++){
111 for(UINT j=0; j<N; j++){
112 newTimeSeries[index][j] = timeSeries[i][j];
117 timeSeries.setTrainingSample(timeSeries.getClassLabel(), newTimeSeries);
121 warningLog <<
"Maximum Trim Percentage Excedded, Can't Trim Sample!";
122 warningLog <<
" Original Timeseries Length: " << M <<
" Trimmed Timeseries Length: " << newM;
123 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()