27 using namespace shogun;
41 false,
false,
false,
false,
false,
false,
false,
false} ;
46 :
CSGObject(), m_transition_matrix_a_id(1,1), m_transition_matrix_a(1,1),
47 m_transition_matrix_a_deriv(1,1), m_initial_state_distribution_p(1),
48 m_initial_state_distribution_p_deriv(1), m_end_state_distribution_q(1),
49 m_end_state_distribution_q_deriv(1),
54 m_word_degree(word_degree_default, m_num_degrees, true, true),
55 m_cum_num_words(cum_num_words_default, m_num_degrees+1, true, true),
56 m_cum_num_words_array(m_cum_num_words.get_array()),
57 m_num_words(num_words_default, m_num_degrees, true, true),
58 m_num_words_array(m_num_words.get_array()),
59 m_mod_words(mod_words_default, m_num_svms, 2, true, true),
60 m_mod_words_array(m_mod_words.get_array()),
61 m_sign_words(sign_words_default, m_num_svms, true, true),
62 m_sign_words_array(m_sign_words.get_array()),
63 m_string_words(string_words_default, m_num_svms, true, true),
64 m_string_words_array(m_string_words.get_array()),
66 m_num_unique_words(m_num_degrees),
67 m_svm_arrays_clean(true),
69 m_max_a_id(0), m_observation_matrix(1,1,1),
75 m_genestr(1), m_wordstr(NULL), m_dict_weights(1,1), m_segment_loss(1,1,2),
88 m_plif_matrices(NULL),
92 m_num_intron_plifs(0),
94 m_raw_intensities(NULL),
96 m_num_probes_cum(NULL),
97 m_num_lin_feat_plifs_cum(NULL),
100 m_long_transitions(true),
101 m_long_transition_threshold(1000)
103 trans_list_forward = NULL ;
104 trans_list_forward_cnt = NULL ;
105 trans_list_forward_val = NULL ;
106 trans_list_forward_id = NULL ;
109 mem_initialized = true ;
121 #ifdef ARRAY_STATISTICS
146 if (trans_list_forward_cnt)
147 SG_FREE(trans_list_forward_cnt);
148 if (trans_list_forward)
150 for (int32_t i=0; i<trans_list_len; i++)
152 if (trans_list_forward[i])
153 SG_FREE(trans_list_forward[i]);
157 if (trans_list_forward_val)
159 for (int32_t i=0; i<trans_list_len; i++)
161 if (trans_list_forward_val[i])
162 SG_FREE(trans_list_forward_val[i]);
164 SG_FREE(trans_list_forward_val);
166 if (trans_list_forward_id)
168 for (int32_t i=0; i<trans_list_len; i++)
170 if (trans_list_forward_id[i])
171 SG_FREE(trans_list_forward_id[i]);
173 SG_FREE(trans_list_forward_id);
205 for (int32_t i=0; i<length-2; i++)
242 int32_t* probe_pos,
float64_t* intensities,
const int32_t num_probes)
251 if (m_num_raw_data==1){
252 memcpy(tmp_probe_pos, probe_pos, num_probes*
sizeof(int32_t));
253 memcpy(tmp_raw_intensities, intensities, num_probes*
sizeof(
float64_t));
258 memcpy(tmp_probe_pos+
m_num_probes_cum[m_num_raw_data-1], probe_pos, num_probes*
sizeof(int32_t));
276 for (
int s=0; s<p_num_svms; s++)
292 memset(tmp, 0, (dim1+num_new_feat)*dim2*
sizeof(
float64_t)) ;
295 tmp[j*(dim1+num_new_feat)+k] = arr[j*dim1+k];
315 CPlif** PEN,
const int32_t* tiling_plif_ids,
const int32_t num_tiling_plifs)
322 int32_t* tiling_rows =
SG_MALLOC(int32_t, num_tiling_plifs);
323 for (int32_t i=0; i<num_tiling_plifs; i++)
326 CPlif * plif = PEN[tiling_plif_ids[i]];
338 for (int32_t pos_idx=0;pos_idx<
m_seq_len;pos_idx++)
342 for (int32_t i=0; i<num_tiling_plifs; i++)
345 CPlif * plif = PEN[tiling_plif_ids[i]];
355 for (int32_t i=0; i<num_tiling_plifs; i++)
376 for (int32_t i=0; i<genestr_len; i++)
401 int32_t from_pos =
m_pos[p];
402 int32_t to_pos =
m_pos[p+1];
410 my_svm_values_unnormalized[s]=0.0;
412 for (int32_t i=from_pos; i<to_pos; i++)
430 if (prev<-1e20 || prev>1e20)
432 SG_ERROR(
"initialization missing (%i, %i, %f)\n", s, p, prev) ;
437 SG_FREE(my_svm_values_unnormalized);
447 SG_ERROR(
"length of start prob vector p (%i) is not equal to the number of states (%i), N: %i\n",p.
vlen,
m_N);
455 SG_ERROR(
"length of end prob vector q (%i) is not equal to the number of states (%i), N: %i\n",q.
vlen,
m_N);
473 for (int32_t i=0; i<
m_N; i++)
475 for (int32_t j=0; j<
m_N; j++)
487 if (!((num_cols==3) || (num_cols==4)))
488 SG_ERROR(
"!((num_cols==3) || (num_cols==4)), num_cols: %i\n",num_cols);
491 SG_FREE(trans_list_forward_cnt);
492 SG_FREE(trans_list_forward_val);
493 SG_FREE(trans_list_forward_id);
495 trans_list_forward = NULL ;
496 trans_list_forward_cnt = NULL ;
497 trans_list_forward_val = NULL ;
503 mem_initialized = true ;
505 trans_list_forward_cnt=NULL ;
506 trans_list_len =
m_N ;
513 for (int32_t j=0; j<
m_N; j++)
515 int32_t old_start_idx=start_idx;
517 while (start_idx<num_trans && a_trans.
matrix[start_idx+num_trans]==j)
521 if (start_idx>1 && start_idx<num_trans)
525 if (start_idx>1 && start_idx<num_trans)
528 int32_t len=start_idx-old_start_idx;
531 trans_list_forward_cnt[j] = 0 ;
537 trans_list_forward_id[j] =
SG_MALLOC(int32_t, len);
541 trans_list_forward[j] = NULL;
542 trans_list_forward_val[j] = NULL;
543 trans_list_forward_id[j] = NULL;
547 for (int32_t i=0; i<num_trans; i++)
549 int32_t from_state = (int32_t)a_trans.
matrix[i] ;
550 int32_t to_state = (int32_t)a_trans.
matrix[i+num_trans] ;
554 id = (int32_t)a_trans.
matrix[i+num_trans*3] ;
557 ASSERT(to_state>=0 && to_state<m_N);
558 ASSERT(from_state>=0 && from_state<m_N);
560 trans_list_forward[to_state][trans_list_forward_cnt[to_state]]=from_state ;
561 trans_list_forward_val[to_state][trans_list_forward_cnt[to_state]]=val ;
562 trans_list_forward_id[to_state][trans_list_forward_cnt[to_state]]=id ;
563 trans_list_forward_cnt[to_state]++ ;
570 for (int32_t i=0; i<
m_N; i++)
571 for (int32_t j=0; j<
m_N; j++)
636 SG_WARNING(
"SVM array: word_degree.get_dim1()!=m_num_degrees") ;
638 SG_WARNING(
"SVM array: m_cum_num_words.get_dim1()!=m_num_degrees+1") ;
640 SG_WARNING(
"SVM array: m_num_words.get_dim1()==m_num_degrees") ;
644 SG_WARNING(
"SVM array: m_num_unique_words.get_dim1()!=m_num_degrees") ;
646 SG_WARNING(
"SVM array: m_mod_words.get_dim1()!=num_svms") ;
648 SG_WARNING(
"SVM array: m_mod_words.get_dim2()!=2") ;
650 SG_WARNING(
"SVM array: m_sign_words.get_dim1()!=num_svms") ;
652 SG_WARNING(
"SVM array: m_string_words.get_dim1()!=num_svms") ;
662 SG_ERROR(
"Expected 3-dimensional Matrix\n");
664 int32_t N=seq.
dims[0];
665 int32_t cand_pos=seq.
dims[1];
666 int32_t max_num_features=seq.
dims[2];
691 if (seg_path.
matrix!=NULL)
697 segment_ids[i] = (int32_t)seg_path.
matrix[2*i] ;
698 segment_mask[i] = seg_path.
matrix[2*i+1] ;
736 if ((!seq_sparse1 && seq_sparse2) || (seq_sparse1 && !seq_sparse2))
737 SG_ERROR(
"Sparse features must either both be NULL or both NON-NULL\n");
785 SG_ERROR(
"m_dict_weights array does not match num_svms=%i!=%i\n",
806 SG_ERROR(
"segment_loss should be 2 x quadratic matrix: %i!=%i\n", 2*m, n) ;
818 int32_t* segment_ids,
float64_t* segment_mask, int32_t m)
824 for (int32_t i=1;i<m;i++)
867 ASSERT(scores && seq_len);
871 int32_t sz =
sizeof(
float64_t)*(*seq_len);
881 ASSERT(losses && seq_len);
885 int32_t sz =
sizeof(
float64_t)*(*seq_len);
896 int32_t orf_from, int32_t orf_to, int32_t start, int32_t &last_pos,
899 #ifdef DYNPROG_TIMING_DETAIL
908 int32_t orf_target = orf_to-orf_from ;
909 if (orf_target<0) orf_target+=3 ;
919 #ifdef DYNPROG_TIMING_DETAIL
921 orf_time += MyTime.time_diff_sec() ;
926 for (; pos>=start; pos-=3)
929 #ifdef DYNPROG_TIMING_DETAIL
931 orf_time += MyTime.time_diff_sec() ;
939 #ifdef DYNPROG_TIMING_DETAIL
941 orf_time += MyTime.time_diff_sec() ;
947 int16_t nbest,
bool with_loss,
bool with_multiple_sequences)
962 for (int32_t i=0; i<nbest; i++)
980 #ifdef DYNPROG_TIMING
981 segment_init_time = 0.0 ;
982 segment_pos_time = 0.0 ;
983 segment_extend_time = 0.0 ;
984 segment_clean_time = 0.0 ;
986 svm_init_time = 0.0 ;
988 svm_clean_time = 0.0 ;
989 inner_loop_time = 0.0 ;
990 content_svm_values_time = 0.0 ;
991 content_plifs_time = 0.0 ;
992 inner_loop_max_time = 0.0 ;
993 long_transition_time = 0.0 ;
1000 SG_ERROR(
"SVM arrays not clean") ;
1004 #ifdef DYNPROG_DEBUG
1013 int32_t max_look_back = 1000 ;
1014 bool use_svm = false ;
1031 #ifdef DYNPROG_DEBUG
1035 SG_PRINT(
"m_num_lin_feat_plifs_cum: ");
1051 if (seq_array!=NULL)
1063 SG_PRINT(
"using sparse seq_array\n") ;
1067 ASSERT(max_num_signals==2) ;
1070 for (int32_t i=0; i<
m_N; i++)
1074 for (int32_t i=0; i<
m_N; i++)
1076 for (int32_t k=0; k<max_num_signals; k++)
1078 if ((PEN_state_signals.
element(i,k)==NULL) && (k==0))
1081 if (seq_input!=NULL)
1092 if (PEN_state_signals.
element(i,k)!=NULL)
1094 if (seq_input!=NULL)
1135 long_transition_content_start_position.
set_array_name(
"long_transition_content_start_position");
1136 #ifdef DYNPROG_DEBUG
1138 long_transition_content_end_position.
set_array_name(
"long_transition_content_end_position");
1141 long_transition_content_start.
set_array_name(
"long_transition_content_start");
1144 long_transition_content_scores.
set_array_name(
"long_transition_content_scores");
1145 #ifdef DYNPROG_DEBUG
1148 long_transition_content_scores_pen.
set_array_name(
"long_transition_content_scores_pen");
1151 long_transition_content_scores_prev.
set_array_name(
"long_transition_content_scores_prev");
1154 long_transition_content_scores_elem.
set_array_name(
"long_transition_content_scores_elem");
1157 long_transition_content_scores_loss.
set_array_name(
"long_transition_content_scores_loss");
1161 SG_ERROR(
"Long transitions are not supported for nbest!=1") ;
1162 long_transitions = false ;
1165 #ifdef DYNPROG_DEBUG
1166 long_transition_content_scores_pen.
set_const(0) ;
1167 long_transition_content_scores_elem.
set_const(0) ;
1168 long_transition_content_scores_prev.
set_const(0) ;
1171 long_transition_content_scores_loss.
set_const(0) ;
1172 long_transition_content_start.
set_const(0) ;
1173 long_transition_content_start_position.
set_const(0) ;
1174 #ifdef DYNPROG_DEBUG
1175 long_transition_content_end_position.
set_const(0) ;
1191 for (int32_t i=0; i<
m_N; i++)
1192 for (int32_t j=0; j<
m_N; j++)
1198 for (int32_t j=0; j<
m_N; j++)
1201 const T_STATES num_elem = trans_list_forward_cnt[j] ;
1202 const T_STATES *elem_list = trans_list_forward[j] ;
1204 for (int32_t i=0; i<num_elem; i++)
1211 if (long_transitions)
1241 if (long_transitions)
1247 int32_t num_long_transitions = 0 ;
1248 for (int32_t i=0; i<
m_N; i++)
1249 for (int32_t j=0; j<
m_N; j++)
1252 num_long_transitions++ ;
1255 if (long_transitions)
1267 SG_DEBUG(
"Using %i long transitions\n", num_long_transitions) ;
1272 SG_DEBUG(
"use_svm=%i\n", use_svm) ;
1274 SG_DEBUG(
"maxlook: %d m_N: %d nbest: %d \n", max_look_back,
m_N, nbest);
1275 const int32_t look_back_buflen = (max_look_back*
m_N+1)*nbest ;
1276 SG_DEBUG(
"look_back_buflen=%i\n", look_back_buflen) ;
1323 memset(fixedtempvv, 0, look_back_buflen*
sizeof(
float64_t)) ;
1324 int32_t * fixedtempii=
SG_MALLOC(int32_t, look_back_buflen);
1325 memset(fixedtempii, 0, look_back_buflen*
sizeof(int32_t)) ;
1371 #ifdef USE_TMP_ARRAYCLASS
1372 fixedtempvv.set_array_name(
"fixedtempvv") ;
1373 fixedtempii.set_array_name(
"fixedtempvv") ;
1384 #ifdef DYNPROG_DEBUG
1397 PEN.display_size() ;
1398 PEN_state_signals.display_size() ;
1411 #ifdef USE_TMP_ARRAYCLASS
1412 fixedtempvv.display_size() ;
1413 fixedtempii.display_size() ;
1424 #endif //DYNPROG_DEBUG
1449 for (int16_t k=1; k<nbest; k++)
1451 int32_t dim1, dim2, dim3 ;
1495 for (int16_t k=0; k<nbest; k++)
1497 delta.
element(delta_array, t, j, k, m_seq_len, m_N) = seq.
element(j,t) ;
1506 const T_STATES num_elem = trans_list_forward_cnt[j] ;
1507 const T_STATES *elem_list = trans_list_forward[j] ;
1508 const float64_t *elem_val = trans_list_forward_val[j] ;
1509 const int32_t *elem_id = trans_list_forward_id[j] ;
1511 int32_t fixed_list_len = 0 ;
1513 int32_t fixedtempii_ = 0 ;
1514 bool fixedtemplong = false ;
1516 for (int32_t i=0; i<num_elem; i++)
1533 int32_t look_back_ = look_back.
element(j, ii) ;
1537 if((orf_from!=-1)!=(orf_to!=-1))
1538 SG_DEBUG(
"j=%i ii=%i orf_from=%i orf_to=%i p=%1.2f\n", j, ii, orf_from, orf_to, elem_val[i]) ;
1539 ASSERT((orf_from!=-1)==(orf_to!=-1)) ;
1541 int32_t orf_target = -1 ;
1544 orf_target=orf_to-orf_from ;
1547 ASSERT(orf_target>=0 && orf_target<3) ;
1550 int32_t orf_last_pos =
m_pos[t] ;
1551 #ifdef DYNPROG_TIMING
1554 int32_t num_ok_pos = 0 ;
1556 for (int32_t ts=t-1; ts>=0 &&
m_pos[t]-
m_pos[ts]<=look_back_; ts--)
1570 else if (m_pos[ts]!=-1 && (m_pos[t]-m_pos[ts])%3==orf_target)
1571 ok=(!use_orf) ||
extend_orf(orf_from, orf_to, m_pos[ts], orf_last_pos, m_pos[t]) ;
1589 int32_t frame = orf_from;
1595 #ifdef DYNPROG_TIMING_DETAIL
1598 pen_val = penalty->
lookup_penalty(m_pos[t]-m_pos[ts], svm_value) ;
1600 #ifdef DYNPROG_TIMING_DETAIL
1602 content_plifs_time += MyTime.time_diff_sec() ;
1606 #ifdef DYNPROG_TIMING_DETAIL
1615 val += segment_loss ;
1617 float64_t mval = -(val + delta.
element(delta_array, ts, ii, 0, m_seq_len, m_N)) ;
1619 if (mval<fixedtempvv_)
1621 fixedtempvv_ = mval ;
1622 fixedtempii_ = ii + ts*
m_N;
1623 fixed_list_len = 1 ;
1624 fixedtemplong = false ;
1629 for (int16_t diff=0; diff<nbest; diff++)
1634 val += segment_loss ;
1636 float64_t mval = -(val + delta.
element(delta_array, ts, ii, diff, m_seq_len, m_N)) ;
1642 if ((fixed_list_len < nbest) || ((0==fixed_list_len) || (mval < fixedtempvv[fixed_list_len-1])))
1644 if ( (fixed_list_len<nbest) && ((0==fixed_list_len) || (mval>fixedtempvv[fixed_list_len-1])) )
1646 fixedtempvv[fixed_list_len] = mval ;
1647 fixedtempii[fixed_list_len] = ii + diff*m_N + ts*m_N*nbest;
1652 int32_t addhere = fixed_list_len;
1653 while ((addhere > 0) && (mval < fixedtempvv[addhere-1]))
1657 for (int32_t jj=fixed_list_len-1; jj>addhere; jj--)
1659 fixedtempvv[jj] = fixedtempvv[jj-1];
1660 fixedtempii[jj] = fixedtempii[jj-1];
1663 fixedtempvv[addhere] = mval;
1664 fixedtempii[addhere] = ii + diff*m_N + ts*m_N*nbest;
1666 if (fixed_list_len < nbest)
1672 #ifdef DYNPROG_TIMING_DETAIL
1674 inner_loop_max_time += MyTime.time_diff_sec() ;
1678 #ifdef DYNPROG_TIMING
1680 inner_loop_time += MyTime3.time_diff_sec() ;
1683 for (int32_t i=0; i<num_elem; i++)
1700 int32_t look_back_ = look_back.
element(j, ii) ;
1705 if((orf_from!=-1)!=(orf_to!=-1))
1706 SG_DEBUG(
"j=%i ii=%i orf_from=%i orf_to=%i p=%1.2f\n", j, ii, orf_from, orf_to, elem_val[i]) ;
1707 ASSERT((orf_from!=-1)==(orf_to!=-1)) ;
1709 int32_t orf_target = -1 ;
1712 orf_target=orf_to-orf_from ;
1715 ASSERT(orf_target>=0 && orf_target<3) ;
1721 #ifdef DYNPROG_TIMING
1732 #ifdef DYNPROG_TIMING
1741 int32_t start = long_transition_content_start.
get_element(ii, j) ;
1742 int32_t end_5p_part = start ;
1746 while (end_5p_part<=t &&
m_pos[end_5p_part+1]-
m_pos[start_5p_part]<=m_long_transition_threshold)
1749 ASSERT(
m_pos[end_5p_part+1]-
m_pos[start_5p_part] > m_long_transition_threshold || end_5p_part==t) ;
1750 ASSERT(
m_pos[end_5p_part]-
m_pos[start_5p_part] <= m_long_transition_threshold) ;
1767 float64_t mval_trans = -( elem_val[i] + pen_val*0.5 + delta.
element(delta_array, start_5p_part, ii, 0, m_seq_len, m_N) ) ;
1776 mval_trans -= segment_loss_part1 ;
1787 long_transition_content_start_position.
set_element(0, ii, j) ;
1789 long_transition_content_scores_loss.
set_element(0.0, ii, j) ;
1790 #ifdef DYNPROG_DEBUG
1791 long_transition_content_scores_pen.
set_element(0.0, ii, j) ;
1792 long_transition_content_scores_elem.
set_element(0.0, ii, j) ;
1793 long_transition_content_scores_prev.
set_element(0.0, ii, j) ;
1794 long_transition_content_end_position.
set_element(0, ii, j) ;
1802 long_transition_content_scores.
set_element(score, ii, j) ;
1803 long_transition_content_scores_loss.
set_element(new_loss, ii, j) ;
1804 #ifdef DYNPROG_DEBUG
1805 long_transition_content_end_position.
set_element(end_5p_part, ii, j) ;
1809 if (-long_transition_content_scores.
get_element(ii, j) > mval_trans )
1812 long_transition_content_scores.
set_element(-mval_trans, ii, j) ;
1813 long_transition_content_start_position.
set_element(start_5p_part, ii, j) ;
1815 long_transition_content_scores_loss.
set_element(segment_loss_part1, ii, j) ;
1816 #ifdef DYNPROG_DEBUG
1817 long_transition_content_scores_pen.
set_element(pen_val*0.5, ii, j) ;
1818 long_transition_content_scores_elem.
set_element(elem_val[i], ii, j) ;
1819 long_transition_content_scores_prev.
set_element(delta.
element(delta_array, start_5p_part, ii, 0, m_seq_len, m_N), ii, j) ;
1823 long_transition_content_end_position.
set_element(end_5p_part, ii, j) ;
1830 long_transition_content_start.
set_element(start_5p_part, ii, j) ;
1840 while (ts>0 &&
m_pos[t]-
m_pos[ts-1] <= m_long_transition_threshold)
1849 float pen_val_3p = 0.0 ;
1852 int32_t frame = orf_from ;
1860 #ifdef DYNPROG_DEBUG
1870 #ifdef DYNPROG_DEBUG
1877 mval -= (segment_loss_total-long_transition_content_scores_loss.
get_element(ii, j)) ;
1880 #ifdef DYNPROG_DEBUG
1883 SG_PRINT(
"Part2: %i,%i,%i: val=%1.6f pen_val_3p*0.5=%1.6f (t=%i, ts=%i, ts-1=%i, ts+1=%i); scores=%1.6f (pen=%1.6f,prev=%1.6f,elem=%1.6f,loss=%1.1f), positions=%i,%i,%i, loss=%1.1f/%1.1f (%i,%i)\n",
1885 long_transition_content_scores.
get_element(ii, j),
1886 long_transition_content_scores_pen.
get_element(ii, j),
1887 long_transition_content_scores_prev.
get_element(ii, j),
1888 long_transition_content_scores_elem.
get_element(ii, j),
1889 long_transition_content_scores_loss.
get_element(ii, j),
1892 m_pos[long_transition_content_start.
get_element(ii,j)], segment_loss_part2, segment_loss_total, long_transition_content_start_position.
get_element(ii,j), t) ;
1893 SG_PRINT(
"fixedtempvv_: %1.6f, from_state:%i from_pos:%i\n ",-fixedtempvv_, (fixedtempii_%m_N), m_pos[(fixedtempii_-(fixedtempii_%(m_N*nbest)))/(m_N*nbest)] );
1896 if (fabs(segment_loss_part2+long_transition_content_scores_loss.
get_element(ii, j) - segment_loss_total)>1e-3)
1898 SG_ERROR(
"LOSS: total=%1.1f (%i-%i) part1=%1.1f/%1.1f (%i-%i) part2=%1.1f (%i-%i) sum=%1.1f diff=%1.1f\n",
1900 long_transition_content_scores_loss.
get_element(ii, j), segment_loss_part1,
m_pos[long_transition_content_start_position.
get_element(ii,j)], m_pos[long_transition_content_end_position.
get_element(ii,j)],
1901 segment_loss_part2, m_pos[long_transition_content_end_position.
get_element(ii,j)], m_pos[t],
1902 segment_loss_part2+long_transition_content_scores_loss.
get_element(ii, j),
1903 segment_loss_part2+long_transition_content_scores_loss.
get_element(ii, j) - segment_loss_total) ;
1913 if (mval < fixedtempvv_)
1916 int32_t fromtjk = fixedtempii_ ;
1922 ASSERT((fromtjk-(fromtjk%(m_N*nbest)))/(m_N*nbest)==0 ||
m_pos[(fromtjk-(fromtjk%(m_N*nbest)))/(m_N*nbest)]>=
m_pos[long_transition_content_start_position.
get_element(ii, j)] || fixedtemplong) ;
1924 fixedtempvv_ = mval ;
1925 fixedtempii_ = ii + m_N*long_transition_content_start_position.
get_element(ii, j) ;
1926 fixed_list_len = 1 ;
1927 fixedtemplong = true ;
1932 #ifdef DYNPROG_TIMING
1934 long_transition_time += MyTime3.time_diff_sec() ;
1938 int32_t numEnt = fixed_list_len;
1943 for (int16_t k=0; k<nbest; k++)
1949 minusscore = fixedtempvv_ ;
1950 fromtjk = fixedtempii_ ;
1954 minusscore = fixedtempvv[k];
1955 fromtjk = fixedtempii[k];
1958 delta.
element(delta_array, t, j, k, m_seq_len, m_N) = -minusscore + seq.
element(j,t);
1961 ktable.
element(t,j,k) = (fromtjk%(m_N*nbest)-psi.
element(t,j,k))/m_N ;
1962 ptable.
element(t,j,k) = (fromtjk-(fromtjk%(m_N*nbest)))/(m_N*nbest) ;
1977 int32_t list_len = 0 ;
1978 for (int16_t diff=0; diff<nbest; diff++)
1982 oldtempvv[list_len] = -(delta.
element(delta_array, (m_seq_len-1), i, diff, m_seq_len, m_N)+
get_q(i)) ;
1983 oldtempii[list_len] = i + diff*
m_N ;
1990 for (int16_t k=0; k<nbest; k++)
1992 delta_end.
element(k) = -oldtempvv[k] ;
2002 for (int16_t k=0; k<nbest; k++)
2004 prob_nbest[k]= delta_end.
element(k) ;
2007 state_seq[i] = path_ends.
element(k) ;
2011 pos_seq[i] = m_seq_len-1 ;
2013 while (pos_seq[i]>0)
2017 state_seq[i+1] = psi.
element(pos_seq[i], state_seq[i], q);
2018 pos_seq[i+1] = ptable.
element(pos_seq[i], state_seq[i], q) ;
2020 q = ktable.
element(pos_seq[i], state_seq[i], q) ;
2024 int32_t num_states = i+1 ;
2025 for (i=0; i<num_states;i++)
2027 my_state_seq[i+k*
m_seq_len] = state_seq[num_states-i-1] ;
2028 my_pos_seq[i+k*
m_seq_len] = pos_seq[num_states-i-1] ;
2030 if (num_states<m_seq_len)
2032 my_state_seq[num_states+k*
m_seq_len]=-1 ;
2042 #ifdef DYNPROG_TIMING
2046 SG_PRINT(
"Timing: orf=%1.2f s \n Segment_init=%1.2f s Segment_pos=%1.2f s Segment_extend=%1.2f s Segment_clean=%1.2f s\nsvm_init=%1.2f s svm_pos=%1.2f svm_clean=%1.2f\n content_svm_values_time=%1.2f content_plifs_time=%1.2f\ninner_loop_max_time=%1.2f inner_loop=%1.2f long_transition_time=%1.2f\n total=%1.2f\n", orf_time, segment_init_time, segment_pos_time, segment_extend_time, segment_clean_time, svm_init_time, svm_pos_time, svm_clean_time, content_svm_values_time, content_plifs_time, inner_loop_max_time, inner_loop_time, long_transition_time, MyTime2.time_diff_sec()) ;
2055 int32_t *my_state_seq, int32_t *my_pos_seq,
2056 int32_t my_seq_len,
const float64_t *seq_array, int32_t max_num_signals)
2072 SG_ERROR(
"SVM arrays not clean") ;
2080 bool use_svm = false ;
2092 for (int32_t i=0; i<
m_N; i++)
2093 for (int32_t j=0; j<
m_N; j++)
2103 for (int32_t i=0; i<
m_N; i++)
2104 for (int32_t j=0; j<max_num_signals; j++)
2117 for (int32_t i=0; i<
m_N; i++)
2121 for (int32_t j=0; j<
m_N; j++)
2127 for (int32_t i=0; i<my_seq_len; i++)
2146 svm_value_part1[s]=0 ;
2147 svm_value_part2[s]=0 ;
2155 ASSERT(my_state_seq[0]>=0) ;
2159 ASSERT(my_state_seq[my_seq_len-1]>=0) ;
2164 total_score += my_scores[0] + my_scores[my_seq_len-1] ;
2167 SG_DEBUG(
"m_seq_len=%i\n", my_seq_len) ;
2168 for (int32_t i=0; i<my_seq_len-1; i++)
2170 if (my_state_seq[i+1]==-1)
2172 int32_t from_state = my_state_seq[i] ;
2173 int32_t to_state = my_state_seq[i+1] ;
2174 int32_t from_pos = my_pos_seq[i] ;
2175 int32_t to_pos = my_pos_seq[i+1] ;
2180 #ifdef DYNPROG_DEBUG
2188 SG_PRINT(
"loss1:%f loss2:%f loss3:%f, diff:%f\n", loss1, loss2, loss3, loss1+loss2-loss3);
2191 SG_PRINT(
"%i. segment loss %f (id=%i): from=%i(%i), to=%i(%i)\n", i, my_losses[i], elem_id, from_pos, from_state, to_pos, to_state) ;
2195 SG_DEBUG(
"%i. segment loss %f (id=%i): from=%i(%i), to=%i(%i)\n", i, my_losses[i], elem_id, from_pos, from_state, to_pos, to_state) ;
2201 #ifdef DYNPROG_DEBUG
2202 SG_DEBUG(
"%i. scores[i]=%f\n", i, my_scores[i]) ;
2209 bool is_long_transition = false ;
2213 is_long_transition = true ;
2215 is_long_transition =
false ;
2218 int32_t from_pos_thresh = from_pos ;
2219 int32_t to_pos_thresh = to_pos ;
2223 if (is_long_transition)
2228 ASSERT(from_pos_thresh<to_pos) ;
2235 #ifdef DYNPROG_DEBUG
2236 SG_PRINT(
"part1: pos1: %i pos2: %i pos3: %i \nsvm_value_part1: ",
m_pos[from_pos],
m_pos[from_pos_thresh],
m_pos[from_pos_thresh+1]) ;
2238 SG_PRINT(
"%1.4f ", svm_value_part1[s]);
2244 ASSERT(to_pos_thresh>0) ;
2250 #ifdef DYNPROG_DEBUG
2251 SG_PRINT(
"part2: pos1: %i pos2: %i pos3: %i \nsvm_value_part2: ",
m_pos[to_pos],
m_pos[to_pos_thresh],
m_pos[to_pos_thresh+1]) ;
2253 SG_PRINT(
"%1.4f ", svm_value_part2[s]);
2265 int32_t num_current_svms=0;
2266 int32_t svm_ids[] = {-8, -7, -6, -5, -4, -3, -2, -1};
2267 SG_PRINT(
"penalties(%i, %i), frame:%i ", from_state, to_state, frame);
2268 ((
CPlifBase*) PEN.
element(to_state, from_state))->get_used_svms(&num_current_svms, svm_ids);
2273 #ifdef DYNPROG_DEBUG
2274 SG_PRINT(
"part2: pos1: %i pos2: %i \nsvm_values: ",
m_pos[from_pos],
m_pos[to_pos]) ;
2282 if (PEN.
element(to_state, from_state)!=NULL)
2285 if (is_long_transition)
2289 nscore= 0.5*pen_value_part1 + 0.5*pen_value_part2 ;
2295 SG_PRINT(
"is_long_transition=%i (from_pos=%i (%i), to_pos=%i (%i)=> %1.5f\n",
2296 is_long_transition,
m_pos[from_pos], from_state,
m_pos[to_pos], to_state, nscore) ;
2298 my_scores[i] += nscore ;
2307 #ifdef DYNPROG_DEBUG
2310 if (is_long_transition)
2312 #ifdef DYNPROG_DEBUG
2315 for (
int kk=0; kk<i; kk++)
2316 sum_score += my_scores[i] ;
2318 SG_PRINT(
"is_long_transition=%i (from_pos=%i (%i), to_pos=%i (%i)=> %1.5f, %1.5f --- 1: %1.6f (%i-%i) 2: %1.6f (%i-%i) \n",
2319 is_long_transition,
m_pos[from_pos], from_state,
m_pos[to_pos], to_state,
2321 PEN.
element(to_state, from_state)->lookup_penalty(
m_pos[from_pos_thresh]-
m_pos[from_pos], svm_value_part1)*0.5,
m_pos[from_pos],
m_pos[from_pos_thresh],
2322 PEN.
element(to_state, from_state)->lookup_penalty(m_pos[to_pos]-m_pos[to_pos_thresh], svm_value_part2)*0.5, m_pos[to_pos_thresh], m_pos[to_pos]) ;
2326 if (is_long_transition)
2328 ((
CPlifBase*) PEN.
element(to_state, from_state))->penalty_add_derivative(
m_pos[from_pos_thresh]-
m_pos[from_pos], svm_value_part1, 0.5) ;
2329 ((
CPlifBase*) PEN.
element(to_state, from_state))->penalty_add_derivative(
m_pos[to_pos]-
m_pos[to_pos_thresh], svm_value_part2, 0.5) ;
2340 if (is_long_transition)
2348 for (int32_t k=0;k<num_intensities;k++)
2350 for (int32_t j=m_num_lin_feat_plifs_cum[d-1];j<m_num_lin_feat_plifs_cum[d];j++)
2351 svm_value[j]=intensities[k];
2357 for (int32_t k=0;k<num_intensities;k++)
2359 for (int32_t j=m_num_lin_feat_plifs_cum[d-1];j<m_num_lin_feat_plifs_cum[d];j++)
2360 svm_value[j]=intensities[k];
2378 for (int32_t k=0;k<num_intensities;k++)
2380 for (int32_t j=m_num_lin_feat_plifs_cum[d-1];j<m_num_lin_feat_plifs_cum[d];j++)
2381 svm_value[j]=intensities[k];
2391 #ifdef DYNPROG_DEBUG
2392 SG_DEBUG(
"%i. scores[i]=%f\n", i, my_scores[i]) ;
2396 for (int32_t k=0; k<max_num_signals; k++)
2398 if ((PEN_state_signals.
element(to_state,k)==NULL)&&(k==0))
2400 #ifdef DYNPROG_DEBUG
2401 SG_DEBUG(
"%i. emmission penalty: to_state=%i to_pos=%i score=%1.2f (no signal plif)\n", i, to_state, to_pos, seq_input.
element(to_state, to_pos, k)) ;
2403 my_scores[i] += seq_input.
element(to_state, to_pos, k) ;
2408 if (PEN_state_signals.
element(to_state, k)!=NULL)
2411 my_scores[i] += nscore ;
2412 #ifdef DYNPROG_DEBUG
2415 SG_PRINT(
"is_long_transition=%i (from_pos=%i (%i), from_state=%i, to_pos=%i (%i) to_state=%i=> %1.5f, dim3:%i, seq_input.element(to_state, to_pos, k): %1.4f\n",
2416 is_long_transition,
m_pos[from_pos], from_pos, from_state,
m_pos[to_pos], to_pos, to_state, nscore, k, seq_input.
element(to_state, to_pos, k)) ;
2417 for (
int x=0; x<23; x++)
2419 for (
int i=-10; i<10; i++)
2434 #ifdef DYNPROG_DEBUG
2435 SG_DEBUG(
"%i. emmission penalty: to_state=%i to_pos=%i value=%1.2f score=%1.2f k=%i\n", i, to_state, to_pos, seq_input.
element(to_state, to_pos, k), nscore, k) ;
2437 ((
CPlifBase*) PEN_state_signals.
element(to_state,k))->penalty_add_derivative(seq_input.
element(to_state, to_pos, k), svm_value, 1) ;
2445 total_score += my_scores[i] ;
2446 total_loss += my_losses[i] ;
2461 int32_t num_intensities = 0;
2465 int32_t num = m_num_probes_cum[type-1];
2466 while (*p_tiling_pos<to_pos)
2468 if (*p_tiling_pos>=from_pos)
2470 intensities[num_intensities] = *p_tiling_data;
2474 if (num>=m_num_probes_cum[type])
2476 last_pos = *p_tiling_pos;
2479 ASSERT(last_pos<*p_tiling_pos);
2481 return num_intensities;
2486 #ifdef DYNPROG_TIMING_DETAIL
2496 svm_values[i] = (to_val-from_val)/(to_pos-from_pos);
2502 svm_values[i] = to_val-from_val ;
2508 int32_t intron_list_start = m_num_lin_feat_plifs_cum[
m_num_raw_data];
2511 for (int32_t i=intron_list_start; i<intron_list_end;i++)
2513 svm_values[i] = (
float64_t) (support[cnt]);
2524 svm_values[frame_plifs[1]] = 1e10;
2525 svm_values[frame_plifs[2]] = 1e10;
2526 int32_t global_frame = from_pos%3;
2527 int32_t row = ((global_frame+frame)%3)+4;
2530 svm_values[frame+frame_plifs[0]] = (to_val-from_val)/(to_pos-from_pos);
2532 #ifdef DYNPROG_TIMING_DETAIL
2534 content_svm_values_time += MyTime.time_diff_sec() ;