21 using namespace shogun;
25 #define MAX_LOG_TABLE_SIZE 10*1024*1024
26 #define LOG_TABLE_PRECISION 1e-6
28 #define MAX_LOG_TABLE_SIZE 123*1024*1024
29 #define LOG_TABLE_PRECISION 1e-15
31 int32_t CMath::LOGACCURACY = 0;
32 #endif // USE_LOGCACHE
57 LOGRANGE=CMath::determine_logrange();
58 LOGACCURACY=CMath::determine_logaccuracy(
LOGRANGE);
81 int32_t CMath::determine_logrange()
92 SG_SINFO(
"determined range for x in table log(1+exp(-x)) is:%d (error:%G)\n",i,acc);
96 int32_t CMath::determine_logaccuracy(int32_t range)
98 range=MAX_LOG_TABLE_SIZE/range/((int)
sizeof(
float64_t));
99 SG_SINFO(
"determined accuracy for x in table log(1+exp(-x)) is:%d (error:%G)\n",range,1.0/(
double) range);
104 void CMath::init_log_table()
106 for (int32_t i=0; i< LOGACCURACY*
LOGRANGE; i++)
114 if (a[0]==-1) return ;
117 changed=0; int32_t i=0 ;
118 while ((a[(i+1)*cols]!=-1) && (a[(i+1)*cols+1]!=-1))
120 if (a[i*cols+sort_col]>a[(i+1)*cols+sort_col])
122 for (int32_t j=0; j<cols; j++)
137 for (int32_t i=0; i<N-1; i++)
142 swap(idx[i],idx[i+1]) ;
151 char* seq1,
char* seq2, int32_t l1, int32_t l2,
float64_t gapCost)
161 for( i1 = 0; i1 < l1; ++i1 ) {
162 gapCosts1[ i1 ] = gapCost * i1;
165 for( i2 = 0; i2 < l2; ++i2 ) {
166 gapCosts2[ i2 ] = gapCost * i2;
167 costs2_1[ i2+1 ] = costs2_1[ i2 ] + gapCosts2[ i2 ];
170 for( i1 = 0; i1 < l1; ++i1 ) {
171 swap( costs2_0, costs2_1 );
172 actCost = costs2_0[ 0 ] + gapCosts1[ i1 ];
173 costs2_1[ 0 ] = actCost;
174 for( i2 = 0; i2 < l2; ++i2 ) {
175 const float64_t actMatch = costs2_0[ i2 ] + ( seq1[i1] == seq2[i2] );
176 const float64_t actGap1 = costs2_0[ i2+1 ] + gapCosts1[ i1 ];
177 const float64_t actGap2 = actCost + gapCosts2[ i2 ];
179 actCost =
min( actMatch, actGap );
180 costs2_1[ i2+1 ] = actCost;