| 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 |
no test coverage detected