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

Function cross_validate_trainer_threaded_impl

dlib/svm/svm_threaded.h:86–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 typename in_scalar_vector_type
85 >
86 const matrix<double, 1, 2, typename trainer_type::mem_manager_type>
87 cross_validate_trainer_threaded_impl (
88 const trainer_type& trainer,
89 const in_sample_vector_type& x,
90 const in_scalar_vector_type& y,
91 const long folds,
92 const long num_threads
93 )
94 {
95 using namespace dlib::cvtti_helpers;
96 typedef typename trainer_type::mem_manager_type mem_manager_type;
97
98 // make sure requires clause is not broken
99 DLIB_ASSERT(is_binary_classification_problem(x,y) == true &&
100 1 < folds && folds <= std::min(sum(y>0),sum(y<0)) &&
101 num_threads > 0,
102 "\tmatrix cross_validate_trainer()"
103 << "\n\t invalid inputs were given to this function"
104 << "\n\t std::min(sum(y>0),sum(y<0)): " << std::min(sum(y>0),sum(y<0))
105 << "\n\t folds: " << folds
106 << "\n\t num_threads: " << num_threads
107 << "\n\t is_binary_classification_problem(x,y): " << ((is_binary_classification_problem(x,y))? "true":"false")
108 );
109
110
111 task mytask;
112 thread_pool tp(num_threads);
113
114
115 // count the number of positive and negative examples
116 long num_pos = 0;
117 long num_neg = 0;
118 for (long r = 0; r < y.nr(); ++r)
119 {
120 if (y(r) == +1.0)
121 ++num_pos;
122 else
123 ++num_neg;
124 }
125
126 // figure out how many positive and negative examples we will have in each fold
127 const long num_pos_test_samples = num_pos/folds;
128 const long num_pos_train_samples = num_pos - num_pos_test_samples;
129 const long num_neg_test_samples = num_neg/folds;
130 const long num_neg_train_samples = num_neg - num_neg_test_samples;
131
132
133 long pos_idx = 0;
134 long neg_idx = 0;
135
136
137
138 std::vector<future<job<trainer_type,in_sample_vector_type> > > jobs(folds);
139 std::vector<future<matrix<double, 1, 2, mem_manager_type> > > results(folds);
140
141
142 for (long i = 0; i < folds; ++i)
143 {

Callers 1

Calls 9

yFunction · 0.85
set_all_elementsFunction · 0.85
minFunction · 0.70
sumFunction · 0.50
nrMethod · 0.45
getMethod · 0.45
set_sizeMethod · 0.45
add_taskMethod · 0.45

Tested by

no test coverage detected