mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added some tests to make sure the recent addition to svm_c_linear_trainer
works right.
This commit is contained in:
parent
b7d8129013
commit
ba33b82e83
@ -43,6 +43,12 @@ namespace
|
||||
typedef matrix<double,0,1> w_type;
|
||||
w_type w;
|
||||
|
||||
decision_function<linear_kernel<w_type> > df;
|
||||
svm_c_linear_trainer<linear_kernel<w_type> > trainer;
|
||||
trainer.set_c_class1(2);
|
||||
trainer.set_c_class1(3);
|
||||
trainer.set_learns_nonnegative_weights(true);
|
||||
trainer.set_epsilon(1e-12);
|
||||
|
||||
std::vector<w_type> x;
|
||||
w_type temp(2);
|
||||
@ -75,6 +81,13 @@ namespace
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
df = trainer.train(x,y);
|
||||
w = join_cols(df.basis_vectors(0), uniform_matrix<double>(1,1,-df.b));
|
||||
true_w = 0, 1, 0;
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
|
||||
print_spinner();
|
||||
|
||||
// test the version with a non-negativity constraint on w.
|
||||
@ -132,6 +145,52 @@ namespace
|
||||
true_w = 1, 0, 0;
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
df = trainer.train(x,y);
|
||||
w = join_cols(df.basis_vectors(0), uniform_matrix<double>(1,1,-df.b));
|
||||
true_w = 1, 0, 0;
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
|
||||
|
||||
x.clear();
|
||||
y.clear();
|
||||
temp = -2, 2;
|
||||
x.push_back(temp);
|
||||
temp = 0, -0;
|
||||
x.push_back(temp);
|
||||
|
||||
y.push_back(+1);
|
||||
y.push_back(-1);
|
||||
|
||||
trainer.set_c(10);
|
||||
df = trainer.train(x,y);
|
||||
w = join_cols(df.basis_vectors(0), uniform_matrix<double>(1,1,-df.b));
|
||||
true_w = 0, 1, -1;
|
||||
dlog << LINFO << "w: " << trans(w);
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
|
||||
x.clear();
|
||||
y.clear();
|
||||
temp = -2, 2;
|
||||
x.push_back(temp);
|
||||
temp = 0, -0;
|
||||
x.push_back(temp);
|
||||
|
||||
y.push_back(-1);
|
||||
y.push_back(+1);
|
||||
|
||||
trainer.set_c(10);
|
||||
df = trainer.train(x,y);
|
||||
w = join_cols(df.basis_vectors(0), uniform_matrix<double>(1,1,-df.b));
|
||||
true_w = 1, 0, 1;
|
||||
dlog << LINFO << "w: " << trans(w);
|
||||
dlog << LINFO << "error: "<< max(abs(w-true_w));
|
||||
DLIB_TEST(max(abs(w-true_w)) < 1e-10);
|
||||
|
||||
}
|
||||
|
||||
} a;
|
||||
|
Loading…
Reference in New Issue
Block a user