예제 #1
0
//!Perform traceback through trellis
//!\return [out] path trackback_path
void simpleTrellis::traceback(traceback_path& path) {

    if (ending.viti!=-INFINITY) {
        path.setScore(ending.viti);
        int pointer=ending.ptr;
        path.push_back(ending.ptr);

        size_t seq_length = seq->getLength();
        if (seq_length==0) {
            return;
        }

        for(size_t position=seq_length -1 ; position>0; position--) {
            pointer=trell[position][pointer].ptr;
            path.push_back(pointer);

            if (pointer==-2) {
                path.clear();
                return;
            }
        }
    }

    return;
}
예제 #2
0
//!Perform traceback through trellis
//!\return [out] path trackback_path
void simpleTrellis::traceback(traceback_path& path,size_t n) {
    if (n<=ending.nth_viterbi_scores->size()) {
        if (ending.viti!=-INFINITY) {
            path.setScore((*ending.nth_viterbi_scores)[n].viterbi_score);

            int state_pointer=(*ending.nth_viterbi_scores)[n].traceback_state;
            size_t score_pointer = (*ending.nth_viterbi_scores)[n].traceback_state_score;

            path.push_back(state_pointer);

            size_t seq_length = seq->getLength();
            if (seq_length==0) {
                return;
            }

            for(size_t position=seq_length -1 ; position>0; position--) {
                state_pointer = (*trell[position][state_pointer].nth_viterbi_scores)[score_pointer].traceback_state;
                score_pointer = (*trell[position][state_pointer].nth_viterbi_scores)[score_pointer].traceback_state_score;

                path.push_back(state_pointer);

                if (state_pointer==-2) {
                    path.clear();
                    return;
                }
            }
        }
    }
    return;
}
예제 #3
0
	//!Perform traceback through trellis
    //!\return path trackback_path
    void trellis::traceback(traceback_path& path){
				
		if (seq_size==0 || traceback_table == NULL){
			return;
		}
		
		if (ending_viterbi_score == -INFINITY){
			return;
		}
        else{
            path.setScore(ending_viterbi_score);
            path.push_back(ending_viterbi_tb);
            
			int16_t pointer = ending_viterbi_tb;
			
            for( size_t position = seq_size -1 ; position>0 ; position--){
				pointer = (*traceback_table)[position][pointer];
				
				if (pointer == -1){
					std::cerr << "No valid path at Position: " << position << std::endl;
					return;
				}
				
				path.push_back(pointer);
            }
        }
        return;
    }
예제 #4
0
파일: trellis.cpp 프로젝트: B-Rich/StochHMM
	//!Perform a traceback starting at position and state given
	//! \param [out] traceback_path
	//! \param position Position to start traceback
	//! \param state State to begin traceback
	void trellis::traceback(traceback_path& path, size_t position, size_t state){
		if (seq_size == 0 || traceback_table == NULL){
			return;
		}
		
		if (path.getModel() == NULL){
			path.setModel(hmm);
		}
		
		int16_t pointer = (*traceback_table)[position][state];
		if (pointer == -1){
			std::cerr << "No valid path at State: " << state <<  " from Position: " << position << std::endl;
			return;
		}
		
		for( size_t pos = position - 1 ; pos>0 ; pos--){
			pointer = (*traceback_table)[pos][pointer];
			
			if (pointer == -1){
				std::cerr << "No valid path at State: " << state <<  " from Position: " << position << std::endl;
				return;
			}
			
			path.push_back(pointer);
		}
		
		return;
	}
예제 #5
0
	//TODO: Finish nth traceback function
	void trellis::traceback_nth(traceback_path& path, size_t n){
		if (seq_size == 0 || n > nth_size || (nth_traceback_table == NULL && naive_nth_scores == NULL)){
			return;
		}
		
		if (nth_traceback_table != NULL){
			int16_t st_pointer = (*ending_nth_viterbi)[n].st_tb;
			int16_t sc_pointer = (*ending_nth_viterbi)[n].score_tb;
			
			path.setScore((*ending_nth_viterbi)[n].score);
			path.push_back(st_pointer);
			
			
			for( size_t position = seq_size -1 ; position>0 ; position--){
				(*nth_traceback_table)[position].get(st_pointer,sc_pointer);
				
				if (st_pointer == -1){
					std::cerr << "No valid path at Position: " << position << std::endl;
					return;
				}
				
				path.push_back(st_pointer);
            }
			
		}
		else{
			int16_t st_pointer = (*ending_nth_viterbi)[n].st_tb;
			int16_t sc_pointer = (*ending_nth_viterbi)[n].score_tb;
			
			path.setScore((*ending_nth_viterbi)[n].score);
			path.push_back(st_pointer);
			
			for( size_t position = seq_size -1 ; position>0 ; position--){
				nthScore& temp = (*(*naive_nth_scores)[position][st_pointer])[sc_pointer];
				st_pointer = temp.st_tb;
				sc_pointer = temp.score_tb;
				if (st_pointer == -1){
					std::cerr << "No valid path at Position: " << position << std::endl;
					return;
				}
				path.push_back(st_pointer);
            }
		}
		return;
	}
예제 #6
0
 //!Tracing posterior not currently supported on simpleTrellis
 void basicTrellis::tracePosterior(traceback_path& path){
     
     size_t seq_length = seq->getLength();
     if (seq_length==0){
         return;
     }
     
     for (size_t position = seq_length-1;position!=SIZE_MAX;--position){
         path.push_back((*posterior_pointer)[position]);
     }
     return;
 }
예제 #7
0
 void basicTrellis::traceStochPosterior(traceback_path& path){
     
     size_t states = hmm->state_size();
     size_t seq_length = seq->getLength();
     if (seq_length==0){
         return;
     }
     
     for (size_t position = seq_length-1;position!=SIZE_MAX;--position){
         
         double random=((double)rand()/((double)(RAND_MAX)+(double)(1)));
         double cumulative_prob(0.0);
         for (int state = 0; state<states ; ++state){
             cumulative_prob+=(*posterior)[position][state];
             if (random<cumulative_prob){
                 path.push_back(state);
                 break;
             }
         }
     }
     return;
 }