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

Function test_normal

dlib/test/svm_c_linear_dcd.cpp:175–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173// ----------------------------------------------------------------------------------------
174
175 void test_normal()
176 {
177 typedef matrix<double,10,1> sample_type;
178
179
180 typedef linear_kernel<sample_type> kernel_type;
181
182
183
184 svm_c_linear_trainer<kernel_type> linear_trainer_cpa;
185 svm_c_linear_dcd_trainer<kernel_type> linear_trainer;
186
187 svm_c_linear_dcd_trainer<kernel_type>::optimizer_state state;
188
189 const double C = 1;
190 linear_trainer.set_epsilon(1e-10);
191 linear_trainer_cpa.set_epsilon(1e-10);
192 linear_trainer_cpa.set_relative_epsilon(1e-10);
193
194 std::vector<sample_type> samples;
195 std::vector<double> labels;
196
197 // make an instance of a sample vector so we can use it below
198 sample_type sample;
199
200 decision_function<kernel_type> df, df2, df3;
201
202 dlib::rand rnd;
203 // Now lets go into a loop and randomly generate 10000 samples.
204 double label = +1;
205 for (int i = 0; i < 100; ++i)
206 {
207 // flip this flag
208 label *= -1;
209
210 sample = 0;
211
212 // now make a random sparse sample with at most 10 non-zero elements
213 for (int j = 0; j < 5; ++j)
214 {
215 int idx = rnd.get_random_32bit_number()%10;
216 double value = rnd.get_random_double();
217
218 sample(idx) = label*value;
219 }
220
221 // Also save the samples we are generating so we can let the svm_c_linear_trainer
222 // learn from them below.
223 samples.push_back(sample);
224 labels.push_back(label);
225
226 if (samples.size() > 1)
227 {
228 linear_trainer_cpa.set_c_class1(C);
229 linear_trainer_cpa.set_c_class2(1.5*C);
230 linear_trainer.set_c_class1(C/samples.size());
231 linear_trainer.set_c_class2(1.5*C/samples.size());
232

Callers 1

perform_testMethod · 0.85

Calls 11

absFunction · 0.85
set_relative_epsilonMethod · 0.80
get_random_doubleMethod · 0.80
maxFunction · 0.50
set_epsilonMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
set_c_class1Method · 0.45
set_c_class2Method · 0.45
trainMethod · 0.45

Tested by

no test coverage detected