exploring possible bug in optimize_linear_svm

This commit is contained in:
Vadim Pisarevsky 2013-03-21 17:00:08 +04:00
parent d756de176f
commit 63a5587d0d
3 changed files with 20 additions and 16 deletions

View File

@ -1562,14 +1562,14 @@ void CvSVM::optimize_linear_svm()
int j, k, sv_count = df[i].sv_count;
for( j = 0; j < sv_count; j++ )
{
const float* src = class_count > 1 ? sv[df[i].sv_index[j]] : sv[j];
const float* src = class_count > 1 && df[i].sv_index ? sv[df[i].sv_index[j]] : sv[j];
double a = df[i].alpha[j];
for( k = 0; k < var_count; k++ )
dst[k] = (float)(dst[k] + src[k]*a);
}
df[i].sv_count = 1;
df[i].alpha[0] = 1.;
if( class_count > 1 )
if( class_count > 1 && df[i].sv_index )
df[i].sv_index[0] = i;
}

View File

@ -769,7 +769,11 @@ void CV_MLBaseTest::load( const char* filename )
else if( !modelName.compare(CV_KNEAREST) )
knearest->load( filename );
else if( !modelName.compare(CV_SVM) )
{
delete svm;
svm = new CvSVM;
svm->load( filename );
}
else if( !modelName.compare(CV_ANN) )
ann->load( filename );
else if( !modelName.compare(CV_DTREE) )

View File

@ -64,11 +64,11 @@ int CV_SLMLTest::run_test_case( int testCaseIdx )
if( code == cvtest::TS::OK )
{
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps1 );
fname1 = tempfile(".yml.gz");
fname1 = tempfile(".yml");
save( fname1.c_str() );
load( fname1.c_str() );
get_error( testCaseIdx, CV_TEST_ERROR, &test_resps2 );
fname2 = tempfile(".yml.gz");
fname2 = tempfile(".yml");
save( fname2.c_str() );
}
else
@ -84,30 +84,30 @@ int CV_SLMLTest::validate_test_results( int testCaseIdx )
// 1. compare files
ifstream f1( fname1.c_str() ), f2( fname2.c_str() );
string s1, s2;
int lineIdx = 0;
int lineIdx = 1;
CV_Assert( f1.is_open() && f2.is_open() );
for( ; !f1.eof() && !f2.eof(); lineIdx++ )
{
getline( f1, s1 );
getline( f2, s2 );
if( s1.compare(s2) )
if( s1.compare(s2) != 0 )
{
ts->printf( cvtest::TS::LOG, "first and second saved files differ in %n-line; first %n line: %s; second %n-line: %s",
lineIdx, lineIdx, s1.c_str(), lineIdx, s2.c_str() );
ts->printf( cvtest::TS::LOG,
"in test case %d first (%s) and second (%s) saved files differ in %d-th line:\n%s\n\tvs\n%s\n",
testCaseIdx, fname1.c_str(), fname2.c_str(),
lineIdx, s1.empty() ? "" : s1.c_str(), s2.empty() ? "" : s2.c_str() );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
break;
}
}
if( !f1.eof() || !f2.eof() )
{
ts->printf( cvtest::TS::LOG, "in test case %d first and second saved files differ in %n-line; first %n line: %s; second %n-line: %s",
testCaseIdx, lineIdx, lineIdx, s1.c_str(), lineIdx, s2.c_str() );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
}
f1.close();
f2.close();
// delete temporary files
remove( fname1.c_str() );
remove( fname2.c_str() );
if( code == cvtest::TS::OK )
{
remove( fname1.c_str() );
remove( fname2.c_str() );
}
// 2. compare responses
CV_Assert( test_resps1.size() == test_resps2.size() );