src/Generic/patterns/PatternMatcher.cpp
/* \brief for an element of an array return a smoothed optimistic version of its value.
	Optimistic smoothing is done by taking maximum of weighted neighbors within a window;
	currently following window-lengths are supported: 1 (no smoothing), 3, 5 and 7
	\param array array to get a smoothed value from
	\param index index of the element in the array
	\param filter_size window length
	\return smoothed value
*/
\brief for an element of an array return a smoothed optimistic version of its value.
Optimistic smoothing is done by taking maximum of weighted neighbors within a window;
currently following window-lengths are supported: 1 (no smoothing), 3, 5 and 7
\param array array to get a smoothed value from
\param index index of the element in the array
\param filter_size window length
\return smoothed value
\ brief for an element of an array return a smoothed optimistic version of its value . Optimistic smoothing is done by taking maximum of weighted neighbors within a window ; currently following window - lengths are supported : 1 ( no smoothing ) 3 5 and 7 \ param array array to get a smoothed value from \ param index index of the element in the array \ param filter_size window length \ return smoothed value
float PatternMatcher::getFilteredScore(const std::vector<float>& array, int index, int filter_size) {
	int size = (int)array.size();
	if (index >= size) {
		throw InternalInconsistencyException::arrayIndexException(
		"PatternMatcher::getFilteredScore()", size, index);
	} else if ( index < 0 ) {
		throw InternalInconsistencyException::arrayIndexException(
		"PatternMatcher::getFilteredScore()", 0, index); 
	}
	float COEFFS_1[]={1};
	float COEFFS_3[]={1, (float)0.5};
	float COEFFS_5[]={1, (float)0.8, (float)0.5};
	float COEFFS_7[]={1, (float)0.9, (float)0.75, (float)0.5};
	float COEFFS_9[]={1, (float)0.95, (float)0.82, (float)0.70, (float)0.5};
	float COEFFS_11[]={1, (float)0.98, (float)0.90, (float)0.82, (float)0.7, (float)0.5};
	float* smoothArray;
	switch ( filter_size ) {
	case 1: smoothArray = COEFFS_1; break;
	case 3: smoothArray = COEFFS_3; break;
	case 5: smoothArray = COEFFS_5; break;
	case 7: smoothArray = COEFFS_7; break;
	case 9: smoothArray = COEFFS_9; break;
	case 11: smoothArray = COEFFS_11; break;
	default: 
		SessionLogger::info("SERIF") << "smoothing filter of size " << filter_size << " is not implemented; reverse to unfiltered version\n";
		smoothArray = COEFFS_1;
		filter_size = 1;
	}
	float result=0.0;
	for ( int i=std::max(0,index-(filter_size-1)/2); i < std::min(size,index+(filter_size+1)/2); i++ ) {
		result = (float)std::max(result,	smoothArray[std::abs(index-i)]*array[i]);
	}
	return result;
}
float PatternMatcher :: getFilteredScore ( const std :: vector < float > & array , int index , int filter_size ) { int size = ( int ) array . size ( ) ; if ( index >= size ) { throw InternalInconsistencyException :: arrayIndexException ( " " , size , index ) ; } else if ( index < 0 ) { throw InternalInconsistencyException :: arrayIndexException ( " " , 0 , index ) ; } float COEFFS_1 [ ] = { 1 } ; float COEFFS_3 [ ] = { 1 , ( float ) 0.5 } ; float COEFFS_5 [ ] = { 1 , ( float ) 0.8 , ( float ) 0.5 } ; float COEFFS_7 [ ] = { 1 , ( float ) 0.9 , ( float ) 0.75 , ( float ) 0.5 } ; float COEFFS_9 [ ] = { 1 , ( float ) 0.95 , ( float ) 0.82 , ( float ) 0.70 , ( float ) 0.5 } ; float COEFFS_11 [ ] = { 1 , ( float ) 0.98 , ( float ) 0.90 , ( float ) 0.82 , ( float ) 0.7 , ( float ) 0.5 } ; float * smoothArray ; switch ( filter_size ) { case 1 : smoothArray = COEFFS_1 ; break ; case 3 : smoothArray = COEFFS_3 ; break ; case 5 : smoothArray = COEFFS_5 ; break ; case 7 : smoothArray = COEFFS_7 ; break ; case 9 : smoothArray = COEFFS_9 ; break ; case 11 : smoothArray = COEFFS_11 ; break ; default : SessionLogger :: info ( " " ) << " " << filter_size << " \n " ; smoothArray = COEFFS_1 ; filter_size = 1 ; } float result = 0.0 ; for ( int i = std :: max ( 0 , index - ( filter_size - 1 ) / 2 ) ; i < std :: min ( size , index + ( filter_size + 1 ) / 2 ) ; i ++ ) { result = ( float ) std :: max ( result , smoothArray [ std :: abs ( index - i ) ] * array [ i ] ) ; } return result ; }
\brief for an element of an array return a smoothed optimistic version of its value.
\ brief for an element of an array return a smoothed optimistic version of its value .