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

Function test_binary_decision_function_impl

dlib/svm/svm.h:107–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105 typename in_scalar_vector_type
106 >
107 const matrix<double,1,2> test_binary_decision_function_impl (
108 const dec_funct_type& dec_funct,
109 const in_sample_vector_type& x_test,
110 const in_scalar_vector_type& y_test
111 )
112 {
113
114 // make sure requires clause is not broken
115 DLIB_ASSERT( is_binary_classification_problem(x_test,y_test) == true,
116 "\tmatrix test_binary_decision_function()"
117 << "\n\t invalid inputs were given to this function"
118 << "\n\t is_binary_classification_problem(x_test,y_test): "
119 << ((is_binary_classification_problem(x_test,y_test))? "true":"false"));
120
121
122 // count the number of positive and negative examples
123 long num_pos = 0;
124 long num_neg = 0;
125
126
127 long num_pos_correct = 0;
128 long num_neg_correct = 0;
129
130
131 // now test this trained object
132 for (long i = 0; i < x_test.nr(); ++i)
133 {
134 // if this is a positive example
135 if (y_test(i) == +1.0)
136 {
137 ++num_pos;
138 if (dec_funct(x_test(i)) >= 0)
139 ++num_pos_correct;
140 }
141 else if (y_test(i) == -1.0)
142 {
143 ++num_neg;
144 if (dec_funct(x_test(i)) < 0)
145 ++num_neg_correct;
146 }
147 else
148 {
149 throw dlib::error("invalid input labels to the test_binary_decision_function() function");
150 }
151 }
152
153
154 matrix<double, 1, 2> res;
155 res(0) = (double)num_pos_correct/(double)(num_pos);
156 res(1) = (double)num_neg_correct/(double)(num_neg);
157 return res;
158 }
159
160 template <
161 typename dec_funct_type,

Callers 1

Calls 3

errorClass · 0.85
nrMethod · 0.45

Tested by

no test coverage detected