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

Function test_regression

dlib/test/svm.cpp:155–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154
155 void test_regression (
156 )
157 {
158 dlog << LINFO << " being test_regression()";
159 // Here we declare that our samples will be 1 dimensional column vectors. The reason for
160 // using a matrix here is that in general you can use N dimensional vectors as inputs to the
161 // krls object. But here we only have 1 dimension to make the example simple.
162 typedef matrix<double,1,1> sample_type;
163
164 // Now we are making a typedef for the kind of kernel we want to use. I picked the
165 // radial basis kernel because it only has one parameter and generally gives good
166 // results without much fiddling.
167 typedef radial_basis_kernel<sample_type> kernel_type;
168
169 // Here we declare an instance of the krls object. The first argument to the constructor
170 // is the kernel we wish to use. The second is a parameter that determines the numerical
171 // accuracy with which the object will perform part of the regression algorithm. Generally
172 // smaller values give better results but cause the algorithm to run slower. You just have
173 // to play with it to decide what balance of speed and accuracy is right for your problem.
174 // Here we have set it to 0.001.
175 krls<kernel_type> test(kernel_type(0.1),0.001);
176 rvm_regression_trainer<kernel_type> rvm_test;
177 rvm_test.set_kernel(test.get_kernel());
178
179 krr_trainer<kernel_type> krr_test;
180 krr_test.set_kernel(test.get_kernel());
181
182 svr_trainer<kernel_type> svr_test;
183 svr_test.set_kernel(test.get_kernel());
184 svr_test.set_epsilon_insensitivity(0.0001);
185 svr_test.set_c(10);
186
187 rbf_network_trainer<kernel_type> rbf_test;
188 rbf_test.set_kernel(test.get_kernel());
189 rbf_test.set_num_centers(13);
190
191 print_spinner();
192 std::vector<sample_type> samples;
193 std::vector<sample_type> samples2;
194 std::vector<double> labels;
195 std::vector<double> labels2;
196 // now we train our object on a few samples of the sinc function.
197 sample_type m;
198 for (double x = -10; x <= 5; x += 0.6)
199 {
200 m(0) = x;
201 test.train(m, sinc(x));
202
203 samples.push_back(m);
204 samples2.push_back(m);
205 labels.push_back(sinc(x));
206 labels2.push_back(2);
207 }
208
209 print_spinner();
210 decision_function<kernel_type> test2 = rvm_test.train(samples, labels);
211 print_spinner();
212 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