| 327 | typename T |
| 328 | > |
| 329 | size_t count_steps_without_decrease_robust ( |
| 330 | const T& container, |
| 331 | double probability_of_decrease = 0.51, |
| 332 | double quantile_discard = 0.10 |
| 333 | ) |
| 334 | { |
| 335 | // make sure requires clause is not broken |
| 336 | DLIB_ASSERT(0 <= quantile_discard && quantile_discard <= 1); |
| 337 | DLIB_ASSERT(0.5 < probability_of_decrease && probability_of_decrease < 1, |
| 338 | "\t size_t count_steps_without_decrease_robust()" |
| 339 | << "\n\t probability_of_decrease: "<< probability_of_decrease |
| 340 | ); |
| 341 | |
| 342 | if (container.size() == 0) |
| 343 | return 0; |
| 344 | |
| 345 | const auto quantile_thresh = find_upper_quantile(container, quantile_discard); |
| 346 | |
| 347 | running_gradient g; |
| 348 | size_t count = 0; |
| 349 | size_t j = 0; |
| 350 | for (auto i = container.rbegin(); i != container.rend(); ++i) |
| 351 | { |
| 352 | ++j; |
| 353 | // ignore values that are too large |
| 354 | if (*i <= quantile_thresh) |
| 355 | g.add(*i); |
| 356 | |
| 357 | if (g.current_n() > 2) |
| 358 | { |
| 359 | // Note that this only looks backwards because we are looping over the |
| 360 | // container backwards. So here we are really checking if the gradient isn't |
| 361 | // decreasing. |
| 362 | double prob_decreasing = g.probability_gradient_greater_than(0); |
| 363 | // If we aren't confident things are decreasing. |
| 364 | if (prob_decreasing < probability_of_decrease) |
| 365 | count = j; |
| 366 | } |
| 367 | } |
| 368 | return count; |
| 369 | } |
| 370 | |
| 371 | // ---------------------------------------------------------------------------------------- |
| 372 |
no test coverage detected