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

Function test_regression

dlib/test/svm.cpp:252–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250
251
252 void test_regression (
253 )
254 {
255 dlog << LINFO << " being test_regression()";
256 // Here we declare that our samples will be 1 dimensional column vectors. The reason for
257 // using a matrix here is that in general you can use N dimensional vectors as inputs to the
258 // krls object. But here we only have 1 dimension to make the example simple.
259 typedef matrix<double,1,1> sample_type;
260
261 // Now we are making a typedef for the kind of kernel we want to use. I picked the
262 // radial basis kernel because it only has one parameter and generally gives good
263 // results without much fiddling.
264 typedef radial_basis_kernel<sample_type> kernel_type;
265
266 // Here we declare an instance of the krls object. The first argument to the constructor
267 // is the kernel we wish to use. The second is a parameter that determines the numerical
268 // accuracy with which the object will perform part of the regression algorithm. Generally
269 // smaller values give better results but cause the algorithm to run slower. You just have
270 // to play with it to decide what balance of speed and accuracy is right for your problem.
271 // Here we have set it to 0.001.
272 krls<kernel_type> test(kernel_type(0.1),0.001);
273 rvm_regression_trainer<kernel_type> rvm_test;
274 rvm_test.set_kernel(test.get_kernel());
275
276 krr_trainer<kernel_type> krr_test;
277 krr_test.set_kernel(test.get_kernel());
278
279 svr_trainer<kernel_type> svr_test;
280 svr_test.set_kernel(test.get_kernel());
281 svr_test.set_epsilon_insensitivity(0.0001);
282 svr_test.set_c(10);
283
284 rbf_network_trainer<kernel_type> rbf_test;
285 rbf_test.set_kernel(test.get_kernel());
286 rbf_test.set_num_centers(13);
287
288 print_spinner();
289 std::vector<sample_type> samples;
290 std::vector<sample_type> samples2;
291 std::vector<double> labels;
292 std::vector<double> labels2;
293 // now we train our object on a few samples of the sinc function.
294 sample_type m;
295 for (double x = -10; x <= 5; x += 0.6)
296 {
297 m(0) = x;
298 test.train(m, sinc(x));
299
300 samples.push_back(m);
301 samples2.push_back(m);
302 labels.push_back(sinc(x));
303 labels2.push_back(2);
304 }
305
306 print_spinner();
307 decision_function<kernel_type> test2 = rvm_test.train(samples, labels);
308 print_spinner();
309 decision_function<kernel_type> test3 = rbf_test.train(samples, labels);

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
absFunction · 0.85
test5Class · 0.85
randomize_samplesFunction · 0.85
set_num_centersMethod · 0.80
sincFunction · 0.70
testFunction · 0.70
test2Function · 0.70
set_kernelMethod · 0.45
get_kernelMethod · 0.45

Tested by

no test coverage detected