22 using namespace shogun;
26 #define MAX_LOG_TABLE_SIZE 10*1024*1024
27 #define LOG_TABLE_PRECISION 1e-6
29 #define MAX_LOG_TABLE_SIZE 123*1024*1024
30 #define LOG_TABLE_PRECISION 1e-15
32 int32_t CMath::LOGACCURACY = 0;
33 #endif // USE_LOGCACHE
54 LOGRANGE=CMath::determine_logrange();
55 LOGACCURACY=CMath::determine_logaccuracy(
LOGRANGE);
70 SG_FREE(CMath::logtable);
76 int32_t CMath::determine_logrange()
87 SG_SINFO(
"determined range for x in table log(1+exp(-x)) is:%d (error:%G)\n",i,acc)
91 int32_t
CMath::determine_logaccuracy(int32_t range)
93 range=MAX_LOG_TABLE_SIZE/range/((int)
sizeof(
float64_t));
94 SG_SINFO(
"determined accuracy for x in table log(1+exp(-x)) is:%d (error:%G)\n",range,1.0/(
double) range)
99 void CMath::init_log_table()
101 for (int32_t i=0; i< LOGACCURACY*
LOGRANGE; i++)
109 if (a[0]==-1) return ;
112 changed=0; int32_t i=0 ;
113 while ((a[(i+1)*cols]!=-1) && (a[(i+1)*cols+1]!=-1))
115 if (a[i*cols+sort_col]>a[(i+1)*cols+sort_col])
117 for (int32_t j=0; j<cols; j++)
132 for (int32_t i=0; i<N-1; i++)
137 swap(idx[i],idx[i+1]) ;
146 char* seq1,
char* seq2, int32_t l1, int32_t l2,
float64_t gapCost)
156 for( i1 = 0; i1 < l1; ++i1 ) {
157 gapCosts1[ i1 ] = gapCost * i1;
160 for( i2 = 0; i2 < l2; ++i2 ) {
161 gapCosts2[ i2 ] = gapCost * i2;
162 costs2_1[ i2+1 ] = costs2_1[ i2 ] + gapCosts2[ i2 ];
165 for( i1 = 0; i1 < l1; ++i1 ) {
166 swap( costs2_0, costs2_1 );
167 actCost = costs2_0[ 0 ] + gapCosts1[ i1 ];
168 costs2_1[ 0 ] = actCost;
169 for( i2 = 0; i2 < l2; ++i2 ) {
170 const float64_t actMatch = costs2_0[ i2 ] + ( seq1[i1] == seq2[i2] );
171 const float64_t actGap1 = costs2_0[ i2+1 ] + gapCosts1[ i1 ];
172 const float64_t actGap2 = actCost + gapCosts2[ i2 ];
174 actCost =
min( actMatch, actGap );
175 costs2_1[ i2+1 ] = actCost;
204 return std::isnan(f);
209 return std::isinf(f);