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

Method test_random_subset_selector

dlib/test/statistics.cpp:41–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 {}
40
41 void test_random_subset_selector ()
42 {
43 random_subset_selector<double> rand_set;
44
45 for (int j = 0; j < 30; ++j)
46 {
47 print_spinner();
48
49 running_stats<double> rs, rs2;
50
51 rand_set.set_max_size(1000);
52
53 for (double i = 0; i < 100000; ++i)
54 {
55 rs.add(i);
56 rand_set.add(i);
57 }
58
59
60 for (unsigned long i = 0; i < rand_set.size(); ++i)
61 rs2.add(rand_set[i]);
62
63
64 dlog << LDEBUG << "true mean: " << rs.mean();
65 dlog << LDEBUG << "true sampled: " << rs2.mean();
66 double ratio = rs.mean()/rs2.mean();
67 DLIB_TEST_MSG(0.96 < ratio && ratio < 1.04, " ratio: " << ratio);
68 }
69
70
71 {
72 random_subset_selector<int> r1, r2;
73 r1.set_max_size(300);
74 for (int i = 0; i < 4000; ++i)
75 r1.add(i);
76
77 ostringstream sout;
78 serialize(r1, sout);
79 istringstream sin(sout.str());
80 deserialize(r2, sin);
81
82 DLIB_TEST(r1.size() == r2.size());
83 DLIB_TEST(r1.max_size() == r2.max_size());
84 DLIB_TEST(r1.next_add_accepts() == r2.next_add_accepts());
85 DLIB_TEST(std::equal(r1.begin(), r1.end(), r2.begin()));
86
87 for (int i = 0; i < 4000; ++i)
88 {
89 r1.add(i);
90 r2.add(i);
91 }
92
93 DLIB_TEST(r1.size() == r2.size());
94 DLIB_TEST(r1.max_size() == r2.max_size());
95 DLIB_TEST(r1.next_add_accepts() == r2.next_add_accepts());
96 DLIB_TEST(std::equal(r1.begin(), r1.end(), r2.begin()));
97 }
98 }

Callers

nothing calls this directly

Calls 13

print_spinnerFunction · 0.85
set_max_sizeMethod · 0.80
next_add_acceptsMethod · 0.80
serializeFunction · 0.70
deserializeFunction · 0.70
equalFunction · 0.50
addMethod · 0.45
sizeMethod · 0.45
meanMethod · 0.45
strMethod · 0.45
max_sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected