src/Generic/discTagger/PDecoder.cpp
// forwardPass was fixed to take the advantage of the grouping of the feature types.
// Due to this, the way it loops over the previous tags and current tags is rearranged,
// and, hence, different from the other decoding rountine.

forwardPass was fixed to take the advantage of the grouping of the feature types.
Due to this, the way it loops over the previous tags and current tags is rearranged,
and, hence, different from the other decoding rountine.
forwardPass was fixed to take the advantage of the grouping of the feature types . Due to this the way it loops over the previous tags and current tags is rearranged and hence different from the other decoding rountine .
void PDecoder::forwardPass(vector<DTObservation *> & observations,
				 		   int *traceback, double* f_score,
						   bool* f_active, int* constraints)
{
	int n_obs = static_cast<int>(observations.size());
	int n_tags = _tagSet->getNTags();
	int n_regular_tags = _tagSet->getNRegularTags();
	initFeatureBuffers();
	for (int i = 0; i < n_obs; i++) {
		for (int j = 0; j < n_tags; j++) {
			f_active[n_tags*i + j] = false;
		}
	}
	int start_tag = _tagSet->getStartTagIndex();
	f_active[start_tag] = true;
	f_score[start_tag] = 0;
	Symbol fakePrevTag;
	for (int prev_index = 0; prev_index < n_obs - 2; prev_index++) {
		int index = prev_index + 1;
		bool is_first_active_tag = true;
		for (int tag = 0; tag < n_regular_tags; tag++) {
			if (constraints != NULL && !isAllowableTag(tag, constraints[index])) 
						continue;
			std::set<int> prev_tags = _tagSet->getPredecessorTags(tag);
			if (prev_tags.size() <= 0)
				continue;
			const Symbol &rTag = _tagSet->getReducedTagSymbol(tag);
			const Symbol &srTag = _tagSet->getSemiReducedTagSymbol(tag);			
			bool at_least_one_predecessor = false;
			BOOST_FOREACH(int prev_tag, prev_tags) {
				if (constraints != NULL && !isAllowableTag(prev_tag, constraints[prev_index])) 
						continue;
				if (f_active[n_tags*prev_index + prev_tag]) {
					DTState curState(_tagSet->getTagSymbol(tag), rTag, srTag,
									_tagSet->getTagSymbol(prev_tag), index,
									observations);
					if (_use_buffered_features) {
						loadWithPrevTagFeatureBuffer(curState, _withPrevTagFeatureTypes, _n_with_prev_tag_feature_types);
					}
					double score = f_score[n_tags*prev_index + prev_tag]
						+ scoreWithPrevTagState(curState, _withPrevTagFeatureTypes, _n_with_prev_tag_feature_types);
					if ( !f_active[n_tags*index + tag] ||
						score > f_score[n_tags*index + tag])
					{
						f_score[n_tags*index + tag] = score;
						traceback[n_tags*index + tag] = prev_tag;
						f_active[n_tags*index + tag] = true;
						at_least_one_predecessor = true;
					}
				}
			}
			if (at_least_one_predecessor) {
				DTState state(_tagSet->getTagSymbol(tag), rTag, srTag,
							fakePrevTag, index,
							observations);
				if (_use_buffered_features && is_first_active_tag) {
					loadObservationOnlyFeatureBuffer(state, _observationOnlyFeatureTypes, _n_observation_only_feature_types);
					is_first_active_tag = false;
				}
				f_score[n_tags*index + tag] += scoreObservationOnlyState(state, _observationOnlyFeatureTypes, _n_observation_only_feature_types);
			}
		}
	}
	int prev_index = n_obs - 2;
	int index = prev_index + 1;
	int tag = _tagSet->getEndTagIndex();
	std::set<int> prev_tags = _tagSet->getPredecessorTags(tag);
	BOOST_FOREACH(int prev_tag, prev_tags) {
		if (f_active[n_tags*prev_index + prev_tag]) {
			double score = f_score[n_tags*prev_index + prev_tag];
			if ( !f_active[n_tags*index + tag] ||
				score > f_score[n_tags*index + tag])
			{
				f_score[n_tags*index + tag] = score;
				traceback[n_tags*index + tag] = prev_tag;
				f_active[n_tags*index + tag] = true;
			}
		}
	}
}
void PDecoder :: forwardPass ( vector < DTObservation * > & observations , int * traceback , double * f_score , bool * f_active , int * constraints ) { int n_obs = static_cast < int > ( observations . size ( ) ) ; int n_tags = _tagSet -> getNTags ( ) ; int n_regular_tags = _tagSet -> getNRegularTags ( ) ; initFeatureBuffers ( ) ; for ( int i = 0 ; i < n_obs ; i ++ ) { for ( int j = 0 ; j < n_tags ; j ++ ) { f_active [ n_tags * i + j ] = false ; } } int start_tag = _tagSet -> getStartTagIndex ( ) ; f_active [ start_tag ] = true ; f_score [ start_tag ] = 0 ; Symbol fakePrevTag ; for ( int prev_index = 0 ; prev_index < n_obs - 2 ; prev_index ++ ) { int index = prev_index + 1 ; bool is_first_active_tag = true ; for ( int tag = 0 ; tag < n_regular_tags ; tag ++ ) { if ( constraints != NULL && ! isAllowableTag ( tag , constraints [ index ] ) ) continue ; std :: set < int > prev_tags = _tagSet -> getPredecessorTags ( tag ) ; if ( prev_tags . size ( ) <= 0 ) continue ; const Symbol & rTag = _tagSet -> getReducedTagSymbol ( tag ) ; const Symbol & srTag = _tagSet -> getSemiReducedTagSymbol ( tag ) ; bool at_least_one_predecessor = false ; BOOST_FOREACH ( int prev_tag , prev_tags ) { if ( constraints != NULL && ! isAllowableTag ( prev_tag , constraints [ prev_index ] ) ) continue ; if ( f_active [ n_tags * prev_index + prev_tag ] ) { DTState curState ( _tagSet -> getTagSymbol ( tag ) , rTag , srTag , _tagSet -> getTagSymbol ( prev_tag ) , index , observations ) ; if ( _use_buffered_features ) { loadWithPrevTagFeatureBuffer ( curState , _withPrevTagFeatureTypes , _n_with_prev_tag_feature_types ) ; } double score = f_score [ n_tags * prev_index + prev_tag ] + scoreWithPrevTagState ( curState , _withPrevTagFeatureTypes , _n_with_prev_tag_feature_types ) ; if ( ! f_active [ n_tags * index + tag ] || score > f_score [ n_tags * index + tag ] ) { f_score [ n_tags * index + tag ] = score ; traceback [ n_tags * index + tag ] = prev_tag ; f_active [ n_tags * index + tag ] = true ; at_least_one_predecessor = true ; } } } if ( at_least_one_predecessor ) { DTState state ( _tagSet -> getTagSymbol ( tag ) , rTag , srTag , fakePrevTag , index , observations ) ; if ( _use_buffered_features && is_first_active_tag ) { loadObservationOnlyFeatureBuffer ( state , _observationOnlyFeatureTypes , _n_observation_only_feature_types ) ; is_first_active_tag = false ; } f_score [ n_tags * index + tag ] += scoreObservationOnlyState ( state , _observationOnlyFeatureTypes , _n_observation_only_feature_types ) ; } } } int prev_index = n_obs - 2 ; int index = prev_index + 1 ; int tag = _tagSet -> getEndTagIndex ( ) ; std :: set < int > prev_tags = _tagSet -> getPredecessorTags ( tag ) ; BOOST_FOREACH ( int prev_tag , prev_tags ) { if ( f_active [ n_tags * prev_index + prev_tag ] ) { double score = f_score [ n_tags * prev_index + prev_tag ] ; if ( ! f_active [ n_tags * index + tag ] || score > f_score [ n_tags * index + tag ] ) { f_score [ n_tags * index + tag ] = score ; traceback [ n_tags * index + tag ] = prev_tag ; f_active [ n_tags * index + tag ] = true ; } } } }
forwardPass was fixed to take the advantage of the grouping of the feature types.
forwardPass was fixed to take the advantage of the grouping of the feature types .
// Process all but the last (END) observation - do that one separately
 // Process the last observation on its own.  The only valid tag is "END",
 // so we don't need to score, just update the traceback to the highest prev tag
