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

Function test_gaussian_random_hash

dlib/test/rand.cpp:253–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251 }
252
253 void test_gaussian_random_hash()
254 {
255 print_spinner();
256 dlog << LINFO << "test_gaussian_random_hash()";
257 double cnt1 = 0; // num <= -1.2
258 double cnt2 = 0; // num <= -0.5
259 double cnt3 = 0; // num <= 0
260 double cnt4 = 0; // num <= 0.5
261 double cnt5 = 0; // num <= 1.2
262
263 const unsigned long total = 1000000;
264 for (unsigned long i = 0; i < total; ++i)
265 {
266 const double r = gaussian_random_hash(i,0,0);
267 if (r <= -1.2) cnt1 += 1;
268 if (r <= -0.5) cnt2 += 1;
269 if (r <= 0) cnt3 += 1;
270 if (r <= 0.5) cnt4 += 1;
271 if (r <= 1.2) cnt5 += 1;
272 }
273 for (unsigned long i = 0; i < total; ++i)
274 {
275 const double r = gaussian_random_hash(0,i,0);
276 if (r <= -1.2) cnt1 += 1;
277 if (r <= -0.5) cnt2 += 1;
278 if (r <= 0) cnt3 += 1;
279 if (r <= 0.5) cnt4 += 1;
280 if (r <= 1.2) cnt5 += 1;
281 }
282 for (unsigned long i = 0; i < total; ++i)
283 {
284 const double r = gaussian_random_hash(0,0,i);
285 if (r <= -1.2) cnt1 += 1;
286 if (r <= -0.5) cnt2 += 1;
287 if (r <= 0) cnt3 += 1;
288 if (r <= 0.5) cnt4 += 1;
289 if (r <= 1.2) cnt5 += 1;
290 }
291
292 cnt1 /= total*3;
293 cnt2 /= total*3;
294 cnt3 /= total*3;
295 cnt4 /= total*3;
296 cnt5 /= total*3;
297
298 dlog << LINFO << "cnt1: "<< cnt1;
299 dlog << LINFO << "cnt2: "<< cnt2;
300 dlog << LINFO << "cnt3: "<< cnt3;
301 dlog << LINFO << "cnt4: "<< cnt4;
302 dlog << LINFO << "cnt5: "<< cnt5;
303
304 DLIB_TEST(std::abs(cnt1 - 0.11507) < 0.001);
305 DLIB_TEST(std::abs(cnt2 - 0.30854) < 0.001);
306 DLIB_TEST(std::abs(cnt3 - 0.5) < 0.001);
307 DLIB_TEST(std::abs(cnt4 - 0.69146) < 0.001);
308 DLIB_TEST(std::abs(cnt5 - 0.88493) < 0.001);
309 }
310

Callers 1

perform_testMethod · 0.85

Calls 3

print_spinnerFunction · 0.85
gaussian_random_hashFunction · 0.85
absFunction · 0.85

Tested by

no test coverage detected