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

Function do_test

dlib/test/sequence_labeler.cpp:283–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281
282 template <typename fe_type>
283 void do_test()
284 {
285 called_rejct_labeling = false;
286
287 matrix<double> transition_probabilities(num_label_states, num_label_states);
288 transition_probabilities = 0.05, 0.90, 0.05,
289 0.05, 0.05, 0.90,
290 0.90, 0.05, 0.05;
291
292 matrix<double> emission_probabilities(num_label_states,num_sample_states);
293 emission_probabilities = 0.5, 0.5, 0.0,
294 0.0, 0.5, 0.5,
295 0.5, 0.0, 0.5;
296
297 print_spinner();
298
299
300 std::vector<funny_sequence> samples;
301 std::vector<std::vector<unsigned long> > labels;
302 make_dataset(transition_probabilities,emission_probabilities,
303 samples, labels, 1000);
304
305 dlog << LINFO << "samples.size(): "<< samples.size();
306
307 // print out some of the randomly sampled sequences
308 for (int i = 0; i < 10; ++i)
309 {
310 dlog << LINFO << "hidden states: " << trans(mat(labels[i]));
311 dlog << LINFO << "observed states: " << trans(mat(samples[i].item));
312 dlog << LINFO << "******************************";
313 }
314
315 print_spinner();
316 structural_sequence_labeling_trainer<fe_type> trainer;
317 trainer.set_c(4);
318 DLIB_TEST(trainer.get_c() == 4);
319 trainer.set_num_threads(4);
320 DLIB_TEST(trainer.get_num_threads() == 4);
321
322
323
324 // Learn to do sequence labeling from the dataset
325 sequence_labeler<fe_type> labeler = trainer.train(samples, labels);
326
327 std::vector<unsigned long> predicted_labels = labeler(samples[0]);
328 dlog << LINFO << "true hidden states: "<< trans(mat(labels[0]));
329 dlog << LINFO << "predicted hidden states: "<< trans(mat(predicted_labels));
330
331 DLIB_TEST(mat(labels[0]) == mat(predicted_labels));
332
333
334 print_spinner();
335
336
337 // We can also do cross-validation
338 matrix<double> confusion_matrix;
339 confusion_matrix = cross_validate_sequence_labeler(trainer, samples, labels, 4);
340 dlog << LINFO << "cross-validation: ";

Callers

nothing calls this directly

Calls 15

print_spinnerFunction · 0.85
absFunction · 0.85
logFunction · 0.85
join_colsFunction · 0.85
reshape_to_column_vectorFunction · 0.85
test_sequence_labelerFunction · 0.85
make_datasetFunction · 0.70
serializeFunction · 0.70
deserializeFunction · 0.70
transFunction · 0.50
matFunction · 0.50

Tested by

no test coverage detected