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

Function test_rare_positives

dlib/test/auto_train_linear_classifier.cpp:112–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110// ----------------------------------------------------------------------------------------
111
112 void test_rare_positives()
113 {
114 // 20 positives among 400 sparse samples of noise words, the positives also holding
115 // a few words of their own. Strong regularization still gets the sign of the held
116 // out scores right on both classes, but ranks them worse, so it must not be chosen.
117 dlib::rand rnd;
118 std::vector<sparse_type> x;
119 std::vector<double> y;
120 for (int i = 0; i < 400; ++i)
121 {
122 const double label = i < 20 ? +1 : -1;
123 std::map<unsigned long,double> words;
124 for (int k = 0; k < 20; ++k)
125 words[10 + rnd.get_random_32bit_number()%1000] = 1;
126 if (label > 0)
127 {
128 for (int k = 0; k < 3; ++k)
129 words[rnd.get_random_32bit_number()%10] = 1;
130 }
131 x.emplace_back(words.begin(), words.end());
132 for (auto& word : x.back())
133 word.second /= std::sqrt(static_cast<double>(words.size()));
134 y.push_back(label);
135 }
136 const auto df = auto_train_linear_classifier(x, y, false);
137 const double c = find_c(df.decision_funct, x, y);
138 dlog << LINFO << "chosen C: " << c;
139 DLIB_TEST(c >= 1);
140 }
141
142// ----------------------------------------------------------------------------------------
143

Callers 1

perform_testMethod · 0.85

Calls 10

find_cFunction · 0.85
emplace_backMethod · 0.80
sqrtFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected