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

Method perform_test

dlib/test/random_forest.cpp:39–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38
39 void perform_test (
40 )
41 {
42 istringstream sin(get_decoded_string());
43
44 print_spinner();
45
46 typedef matrix<double,0,1> sample_type;
47 std::vector<double> labels;
48 std::vector<sample_type> samples;
49
50 deserialize(samples, sin);
51 deserialize(labels, sin);
52
53 DLIB_TEST(samples.size() == 506);
54
55 random_forest_regression_trainer<dense_feature_extractor> trainer;
56 trainer.set_num_trees(1000);
57 trainer.set_seed("random forest");
58
59 std::vector<double> oobs;
60 auto df = trainer.train(samples, labels, oobs);
61
62 DLIB_TEST(df.get_num_trees() == 1000);
63
64 auto result = test_regression_function(df, samples, labels);
65 // train: 1.95064 0.990374 0.92738 1.04536
66 dlog << LINFO << "train: " << result;
67 DLIB_TEST_MSG(result(0) < 2.0, result(0));
68
69 // By construction, output values should be in the span of the training labels.
70 const double min_label = min(mat(labels));
71 const double max_label = max(mat(labels));
72 for (auto&& x : samples) {
73 double y = df(x);
74 DLIB_TEST(min_label <= y && y <= max_label);
75 }
76
77 running_stats<double> rs;
78 for (size_t i = 0; i < oobs.size(); ++i)
79 rs.add(std::pow(oobs[i]-labels[i],2.0));
80 dlog << LINFO << "OOB MSE: "<< rs.mean();
81 DLIB_TEST_MSG(rs.mean() < 10.0, rs.mean());
82
83 print_spinner();
84
85 stringstream ss;
86 serialize(df, ss);
87 decltype(df) df2;
88 deserialize(df2, ss);
89 DLIB_TEST(df2.get_num_trees() == 1000);
90 result = test_regression_function(df2, samples, labels);
91 // train: 1.95064 0.990374 0.92738 1.04536
92 dlog << LINFO << "serialized train results: " << result;
93 DLIB_TEST_MSG(result(0) < 2.0, result(0));
94 }
95 } a;
96

Callers

nothing calls this directly

Calls 15

print_spinnerFunction · 0.85
test_regression_functionFunction · 0.85
set_num_treesMethod · 0.80
get_decoded_stringFunction · 0.70
deserializeFunction · 0.70
serializeFunction · 0.70
minFunction · 0.50
matFunction · 0.50
maxFunction · 0.50
sizeMethod · 0.45
set_seedMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected