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

Function test_normal_force_last_weight

dlib/test/svm_c_linear_dcd.cpp:247–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245// ----------------------------------------------------------------------------------------
246
247 void test_normal_force_last_weight(bool have_bias, bool force_weight)
248 {
249 typedef matrix<double,10,1> sample_type;
250 dlog << LINFO << "have_bias: "<< have_bias << " force_weight: "<< force_weight;
251
252
253 typedef linear_kernel<sample_type> kernel_type;
254
255
256 svm_c_linear_trainer<kernel_type> linear_trainer_cpa;
257
258 svm_c_linear_dcd_trainer<kernel_type> linear_trainer;
259
260 svm_c_linear_dcd_trainer<kernel_type>::optimizer_state state;
261
262 const double C = 1;
263 linear_trainer.set_epsilon(1e-10);
264 linear_trainer_cpa.set_epsilon(1e-11);
265 linear_trainer_cpa.set_relative_epsilon(1e-11);
266
267 linear_trainer_cpa.force_last_weight_to_1(force_weight);
268
269 linear_trainer.force_last_weight_to_1(force_weight);
270 linear_trainer.include_bias(have_bias);
271
272 std::vector<sample_type> samples;
273 std::vector<double> labels;
274
275 // make an instance of a sample vector so we can use it below
276 sample_type sample;
277
278 decision_function<kernel_type> df, df2;
279
280 running_stats<double> rs;
281
282 dlib::rand rnd;
283 // Now lets go into a loop and randomly generate 10000 samples.
284 double label = +1;
285 for (int i = 0; i < 40; ++i)
286 {
287 // flip this flag
288 label *= -1;
289
290 sample = 0;
291
292 // now make a random sparse sample with at most 10 non-zero elements
293 for (int j = 0; j < 5; ++j)
294 {
295 int idx = rnd.get_random_32bit_number()%9;
296 double value = rnd.get_random_double();
297
298 sample(idx) = label*value + label;
299 }
300
301 sample(9) = 4;
302
303 // Also save the samples we are generating so we can let the svm_c_linear_trainer
304 // learn from them below.

Callers 1

perform_testMethod · 0.85

Calls 14

absFunction · 0.85
set_relative_epsilonMethod · 0.80
include_biasMethod · 0.80
get_random_doubleMethod · 0.80
maxFunction · 0.50
set_epsilonMethod · 0.45
push_backMethod · 0.45
set_cMethod · 0.45
sizeMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected