MCPcopy Create free account
hub / github.com/davisking/dlib / dotest1

Function dotest1

dlib/test/ranking.cpp:149–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147// ----------------------------------------------------------------------------------------
148
149 void dotest1()
150 {
151 print_spinner();
152 dlog << LINFO << "in dotest1()";
153
154 typedef matrix<double,4,1> sample_type;
155
156 typedef linear_kernel<sample_type> kernel_type;
157
158 svm_rank_trainer<kernel_type> trainer;
159
160
161 std::vector<ranking_pair<sample_type> > samples;
162
163 ranking_pair<sample_type> p;
164 sample_type samp;
165
166 samp = 0, 0, 0, 1; p.relevant.push_back(samp);
167 samp = 1, 0, 0, 0; p.nonrelevant.push_back(samp);
168 samples.push_back(p);
169
170 samp = 0, 0, 1, 0; p.relevant.push_back(samp);
171 samp = 1, 0, 0, 0; p.nonrelevant.push_back(samp);
172 samp = 0, 1, 0, 0; p.nonrelevant.push_back(samp);
173 samp = 0, 1, 0, 0; p.nonrelevant.push_back(samp);
174 samples.push_back(p);
175
176
177 trainer.set_c(10);
178
179 decision_function<kernel_type> df = trainer.train(samples);
180
181 dlog << LINFO << "accuracy: "<< test_ranking_function(df, samples);
182 matrix<double,1,2> res;
183 res = 1,1;
184 DLIB_TEST(equal(test_ranking_function(df, samples), res));
185
186 DLIB_TEST(equal(test_ranking_function(trainer.train(samples[1]), samples), res));
187
188 trainer.set_epsilon(1e-13);
189 df = trainer.train(samples);
190
191 dlog << LINFO << df.basis_vectors(0);
192 sample_type truew;
193 truew = -0.5, -0.5, 0.5, 0.5;
194 DLIB_TEST(length(truew - df.basis_vectors(0)) < 1e-10);
195
196 dlog << LINFO << "accuracy: "<< test_ranking_function(df, samples);
197 DLIB_TEST(equal(test_ranking_function(df, samples), res));
198
199 dlog << LINFO << "cv-accuracy: "<< cross_validate_ranking_trainer(trainer, samples,2);
200 DLIB_TEST(std::abs(cross_validate_ranking_trainer(trainer, samples,2)(0) - 0.7777777778) < 0.0001);
201
202 trainer.set_learns_nonnegative_weights(true);
203 df = trainer.train(samples);
204 truew = 0, 0, 1.0, 1.0;
205 dlog << LINFO << df.basis_vectors(0);
206 DLIB_TEST(length(truew - df.basis_vectors(0)) < 1e-10);

Callers 1

perform_testMethod · 0.70

Calls 12

print_spinnerFunction · 0.85
test_ranking_functionFunction · 0.85
absFunction · 0.85
equalFunction · 0.50
lengthFunction · 0.50
push_backMethod · 0.45
set_cMethod · 0.45
trainMethod · 0.45
set_epsilonMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected