48 std::cerr <<
"Model isn't a simple/basic HMM. Use complex algorithms\n";
62 std::cerr <<
"Can't allocate Viterbi score and traceback table. OUT OF MEMORY" << std::endl;
67 std::bitset<STATE_MAX> next_states;
68 std::bitset<STATE_MAX> current_states;
70 double viterbi_temp(-INFINITY);
71 double emission(-INFINITY);
72 bool exDef_position(
false);
79 std::bitset<STATE_MAX>* from_trans(NULL);
83 if ((*initial_to)[st]){
85 viterbi_temp = (*hmm)[st]->get_emission_prob(*
seqs,0) +
getTransition(init, st, 0);
87 if (viterbi_temp > -INFINITY){
89 (*scoring_current)[st] = viterbi_temp;
91 next_states |= (*(*hmm)[st]->getTo());
97 for(
size_t position = 1; position <
seq_size ; ++position ){
107 current_states.reset();
108 current_states |= next_states;
116 for (
size_t st_current = 0; st_current <
state_size; ++st_current){
119 if (!current_states[st_current]){
124 emission = (*hmm)[st_current]->get_emission_prob(*
seqs, position);
132 if (emission == -INFINITY){
137 from_trans = (*hmm)[st_current]->getFrom();
139 for (
size_t st_previous = 0; st_previous <
state_size ; ++st_previous) {
140 if (!(*from_trans)[st_previous]){
147 viterbi_temp =
getTransition((*
hmm)[st_previous], st_current , position) + emission + (*scoring_previous)[st_previous];
150 (*scoring_current)[st_current] = viterbi_temp;
151 (*traceback_table)[position][st_current] = st_previous;
154 next_states |= (*(*hmm)[st_current]->getTo());
169 for(
size_t st_previous = 0; st_previous <
state_size ;++st_previous){
171 viterbi_temp = (*scoring_previous)[st_previous] + (*hmm)[st_previous]->getEndTrans();
205 double emission(-INFINITY);
206 double viterbi_temp(-INFINITY);
207 double trans(-INFINITY);
208 double previous(-INFINITY);
209 bool exDef_position(
false);
218 (*dbl_viterbi_score)[0][st]=viterbi_temp;
219 (*traceback_table)[0][st]=-1;
223 for (
size_t position = 1 ; position <
seq_size ; ++position){
229 for (
size_t st_current = 0; st_current <
state_size; ++st_current){
231 emission = (*hmm)[st_current]->get_emission_prob(*
seqs, position);
237 if (emission == -INFINITY){
241 for (
size_t st_previous = 0; st_previous <
state_size; ++st_previous){
242 previous = (*dbl_viterbi_score)[position-1][st_previous];
243 if (previous == -INFINITY){
249 if (trans !=-INFINITY){
250 viterbi_temp = emission + trans + previous;
253 (*dbl_viterbi_score)[position][st_current] = viterbi_temp;
254 (*traceback_table)[position][st_current] = st_previous;
264 for (
size_t st_previous = 0; st_previous <
state_size; ++st_previous){
265 if ((*
hmm)[st_previous]->getEndTrans() != -INFINITY){
267 viterbi_temp = (*dbl_viterbi_score)[seq_size-1][st_previous] + (*hmm)[st_previous]->getEndTrans();
482 std::cerr <<
"Can't allocate Viterbi score and traceback table. OUT OF MEMORY" << std::endl;
487 std::bitset<STATE_MAX> next_states;
488 std::bitset<STATE_MAX> current_states;
490 double viterbi_temp(-INFINITY);
491 double emission(-INFINITY);
492 bool exDef_position(
false);
493 double transition_prob(-INFINITY);
505 bool extend_duration(
false);
514 (*complex_transitions)[i] =
new std::vector<std::map<uint16_t,double>* > (
seq_size, NULL);
521 std::bitset<STATE_MAX>* from_trans(NULL);
525 if ((*initial_to)[i]){
528 viterbi_temp = (*hmm)[i]->get_emission_prob(*
seqs,0) +
getTransition(init, i, 0);
530 if (viterbi_temp > -INFINITY){
532 (*scoring_current)[i] = viterbi_temp;
534 next_states |= (*(*hmm)[i]->getTo());
540 for(
size_t position = 1; position <
seq_size ; ++position ){
550 current_states.reset();
551 current_states |= next_states;
563 for (
size_t st_current = 0; st_current <
state_size; ++st_current){
564 if (!current_states[st_current]){
568 emission = (*hmm)[st_current]->get_emission_prob(*
seqs, position);
577 from_trans = (*hmm)[st_current]->getFrom();
579 for (
size_t st_previous = 0; st_previous <
state_size ; ++st_previous) {
580 if (!(*from_trans)[st_previous]){
586 transition_prob =
getTransition((*
hmm)[st_previous], st_current , position);
588 if ((*duration)[st_previous]){
590 (*(*complex_transitions)[st_current])[position] =
new std::map<uint16_t,double>;
593 (*(*(*complex_transitions)[st_current])[position])[st_previous] = transition_prob;
596 viterbi_temp = transition_prob + emission + (*scoring_previous)[st_previous];
602 extend_duration = (st_current==st_previous) ?
true :
false;
604 (*scoring_current)[st_current] = viterbi_temp;
605 (*traceback_table)[position][st_current] = st_previous;
608 next_states |= (*(*hmm)[st_current]->getTo());
615 if (extend_duration && (*duration)[st_current]){
617 (*explicit_duration_current)[st_current]=2;
620 (*explicit_duration_current)[st_current]=(*explicit_duration_previous)[st_current]+1;
622 extend_duration=
false;
625 (*explicit_duration_current)[st_current]=0;
646 for(
size_t st_previous = 0; st_previous <
state_size ;++st_previous){
648 viterbi_temp = (*scoring_previous)[st_previous] + (*hmm)[st_previous]->getEndTrans();
677 std::cerr <<
"Can't allocate Viterbi score and traceback table. OUT OF MEMORY" << std::endl;
682 std::bitset<STATE_MAX> next_states;
683 std::bitset<STATE_MAX> current_states;
685 double viterbi_temp(-INFINITY);
686 double emission(-INFINITY);
687 bool exDef_position(
false);
698 bool extend_duration(
false);
704 std::bitset<STATE_MAX>* from_trans(NULL);
708 if ((*initial_to)[i]){
710 viterbi_temp = (*hmm)[i]->get_emission_prob(*
seqs,0) +
getTransition(init, i, 0);
712 if (viterbi_temp > -INFINITY){
714 (*scoring_current)[i] = viterbi_temp;
716 next_states |= (*(*hmm)[i]->getTo());
725 for(
size_t position = 1; position <
seq_size ; ++position ){
735 current_states.reset();
736 current_states |= next_states;
749 if (!current_states[i]){
755 emission = (*hmm)[i]->get_emission_prob(*
seqs, position);
764 from_trans = (*hmm)[i]->getFrom();
767 if (!(*from_trans)[j]){
772 viterbi_temp =
getTransition((*
hmm)[j], i , position) + emission + (*scoring_previous)[j];
782 extend_duration = (i==j) ?
true :
false;
784 (*scoring_current)[i] = viterbi_temp;
785 (*traceback_table)[position][i] = j;
788 next_states |= (*(*hmm)[i]->getTo());
795 if (extend_duration && (*duration)[i]){
797 (*explicit_duration_current)[i]=2;
800 (*explicit_duration_current)[i]=(*explicit_duration_previous)[i]+1;
802 extend_duration=
false;
805 (*explicit_duration_current)[i]=0;
828 viterbi_temp = (*scoring_previous)[i] + (*hmm)[i]->getEndTrans();