18 sort(nth_scores.begin(), nth_scores.end(),
_vec_sort );
33 std::cerr <<
"Model isn't a simple/basic HMM. Use complex algorithms\n";
49 std::cerr <<
"Can't allocate Viterbi score and traceback table. OUT OF MEMORY" << std::endl;
54 std::bitset<STATE_MAX> next_states;
55 std::bitset<STATE_MAX> current_states;
57 double viterbi_temp(-INFINITY);
58 double emission(-INFINITY);
59 double trans(-INFINITY);
60 bool exDef_position(
false);
66 std::bitset<STATE_MAX>* from_trans(NULL);
70 if ((*initial_to)[st]){
72 viterbi_temp = (*hmm)[st]->get_emission_prob(*
seqs,0) +
getTransition(init, st, 0);
74 if (viterbi_temp > -INFINITY){
75 (*nth_scoring_current)[st].push_back(
nthScore(-1,-1,viterbi_temp));
77 next_states |= (*(*hmm)[st]->getTo());
83 for(
size_t position = 1; position <
seq_size ; ++position ){
93 current_states.reset();
94 current_states |= next_states;
102 for (
size_t st_current = 0; st_current <
state_size; ++st_current){
105 if (!current_states[st_current]){
110 emission = (*hmm)[st_current]->get_emission_prob(*
seqs, position);
117 if (emission == -INFINITY){
122 from_trans = (*hmm)[st_current]->getFrom();
124 for (
size_t st_previous = 0; st_previous <
state_size ; ++st_previous) {
125 if (!(*from_trans)[st_previous]){
134 if (trans== -INFINITY){
138 for(
size_t vit_previous=0; vit_previous < (*nth_scoring_previous)[st_previous].size(); vit_previous++){
139 viterbi_temp = emission + trans + (*nth_scoring_previous)[st_previous][vit_previous].score;
140 (*nth_scoring_current)[st_current].push_back(
nthScore(st_previous,vit_previous,viterbi_temp));
143 next_states |= (*(*hmm)[st_current]->getTo());
149 (*nth_scoring_current)[st_current].resize(
nth_size);
152 for (
size_t i=0; i < (*nth_scoring_current)[st_current].size(); i++){
167 for(
size_t st_previous = 0; st_previous <
state_size ;++st_previous){
170 trans = (*hmm)[st_previous]->getEndTrans();
172 if (trans == -INFINITY){
176 for(
size_t vit_previous=0; vit_previous < (*nth_scoring_previous)[st_previous].size(); vit_previous++){
177 viterbi_temp = trans + (*nth_scoring_previous)[st_previous][vit_previous].score;
202 std::vector<nthScore>* temp_scores;
204 double emission(-INFINITY);
205 double viterbi_temp(-INFINITY);
206 double trans(-INFINITY);
207 bool exDef_position(
false);
215 if (viterbi_temp == -INFINITY){
219 temp_scores =
new (std::nothrow) std::vector<nthScore>;
220 temp_scores->push_back(
nthScore(-1,-1,viterbi_temp));
222 (*naive_nth_scores)[0][st]=temp_scores;
226 for (
size_t position = 1 ; position <
seq_size ; ++position){
232 for (
size_t st_current = 0; st_current <
state_size; ++st_current){
234 emission = (*hmm)[st_current]->get_emission_prob(*
seqs, position);
240 if (emission == -INFINITY){
244 temp_scores =
new (std::nothrow) std::vector<nthScore>;
245 for (
size_t st_previous = 0; st_previous <
state_size; ++st_previous){
247 if (trans== -INFINITY){
255 for(
size_t vit_previous=0; vit_previous < (*naive_nth_scores)[position-1][st_previous]->size(); vit_previous++){
256 viterbi_temp = emission + trans + (*(*naive_nth_scores)[position-1][st_previous])[vit_previous].score;
257 temp_scores->push_back(
nthScore(st_previous,vit_previous,viterbi_temp));
262 if (temp_scores->size() >
nth_size){
265 (*naive_nth_scores)[position][st_current]=temp_scores;
270 temp_scores =
new(std::nothrow) std::vector<nthScore>;
271 for (
size_t st_previous = 0; st_previous <
state_size; ++st_previous){
274 if ((*
hmm)[st_previous]->getEndTrans() != -INFINITY){
280 for (
size_t prev_scores=0; prev_scores < (*naive_nth_scores)[seq_size-1][st_previous]->size(); prev_scores++){
282 viterbi_temp = (*(*naive_nth_scores)[seq_size-1][st_previous])[prev_scores].score + (*
hmm)[st_previous]->getEndTrans();
283 temp_scores->push_back(
nthScore(st_previous, prev_scores, viterbi_temp));
291 if (temp_scores->size() >
nth_size){