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

Function test_assignment_function

dlib/svm/cross_validate_assignment_trainer.h:20–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 typename assignment_function
19 >
20 double test_assignment_function (
21 const assignment_function& assigner,
22 const std::vector<typename assignment_function::sample_type>& samples,
23 const std::vector<typename assignment_function::label_type>& labels
24 )
25 {
26 // make sure requires clause is not broken
27#ifdef ENABLE_ASSERTS
28 if (assigner.forces_assignment())
29 {
30 DLIB_ASSERT(is_forced_assignment_problem(samples, labels),
31 "\t double test_assignment_function()"
32 << "\n\t invalid inputs were given to this function"
33 << "\n\t is_forced_assignment_problem(samples,labels): " << is_forced_assignment_problem(samples,labels)
34 << "\n\t is_assignment_problem(samples,labels): " << is_assignment_problem(samples,labels)
35 << "\n\t is_learning_problem(samples,labels): " << is_learning_problem(samples,labels)
36 );
37 }
38 else
39 {
40 DLIB_ASSERT(is_assignment_problem(samples, labels),
41 "\t double test_assignment_function()"
42 << "\n\t invalid inputs were given to this function"
43 << "\n\t is_assignment_problem(samples,labels): " << is_assignment_problem(samples,labels)
44 << "\n\t is_learning_problem(samples,labels): " << is_learning_problem(samples,labels)
45 );
46 }
47#endif
48 double total_right = 0;
49 double total = 0;
50 for (unsigned long i = 0; i < samples.size(); ++i)
51 {
52 const std::vector<long>& out = assigner(samples[i]);
53 for (unsigned long j = 0; j < out.size(); ++j)
54 {
55 if (out[j] == labels[i][j])
56 ++total_right;
57
58 ++total;
59 }
60 }
61
62 if (total != 0)
63 return total_right/total;
64 else
65 return 1;
66 }
67
68// ----------------------------------------------------------------------------------------
69

Callers 2

test1Function · 0.85
mainFunction · 0.85

Calls 5

is_assignment_problemFunction · 0.85
is_learning_problemFunction · 0.85
forces_assignmentMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected