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

Function test2

dlib/test/sequence_labeler.cpp:386–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384// ----------------------------------------------------------------------------------------
385
386 void test2()
387 {
388 /*
389 The point of this test is to make sure calling set_feature() multiple
390 times works the way it is supposed to.
391 */
392
393 print_spinner();
394 std::vector<funny_sequence> samples;
395 std::vector<std::vector<unsigned long> > labels;
396
397 matrix<double> transition_probabilities(num_label_states, num_label_states);
398 transition_probabilities = 0.05, 0.90, 0.05,
399 0.05, 0.05, 0.90,
400 0.90, 0.05, 0.05;
401
402 matrix<double> emission_probabilities(num_label_states,num_sample_states);
403 emission_probabilities = 0.5, 0.5, 0.0,
404 0.0, 0.5, 0.5,
405 0.5, 0.0, 0.5;
406
407
408 make_dataset(transition_probabilities,emission_probabilities,
409 samples, labels, 1000);
410
411 dlog << LINFO << "samples.size(): "<< samples.size();
412
413 structural_sequence_labeling_trainer<feature_extractor> trainer;
414 structural_sequence_labeling_trainer<feature_extractor_partial> trainer_part;
415 trainer.set_c(4);
416 trainer_part.set_c(4);
417 trainer.set_num_threads(4);
418 trainer_part.set_num_threads(4);
419 trainer.set_epsilon(1e-8);
420 trainer_part.set_epsilon(1e-8);
421
422
423
424 // Learn to do sequence labeling from the dataset
425 sequence_labeler<feature_extractor> labeler = trainer.train(samples, labels);
426 sequence_labeler<feature_extractor_partial> labeler_part = trainer_part.train(samples, labels);
427
428 dlog << LINFO << "weight disagreement: "<< max(abs(labeler.get_weights() - labeler_part.get_weights()));
429 dlog << LINFO << "max weight magnitude: "<< max(abs(labeler.get_weights()));
430
431 // Both feature extractors should be equivalent.
432 DLIB_TEST(max(abs(labeler.get_weights() - labeler_part.get_weights())) < 1e-6);
433
434 }
435
436// ----------------------------------------------------------------------------------------
437

Callers 1

perform_testMethod · 0.70

Calls 10

print_spinnerFunction · 0.85
absFunction · 0.85
make_datasetFunction · 0.70
maxFunction · 0.50
sizeMethod · 0.45
set_cMethod · 0.45
set_num_threadsMethod · 0.45
set_epsilonMethod · 0.45
trainMethod · 0.45
get_weightsMethod · 0.45

Tested by

no test coverage detected