| 290 | typename T |
| 291 | > |
| 292 | size_t count_steps_without_decrease ( |
| 293 | const T& container, |
| 294 | double probability_of_decrease = 0.51 |
| 295 | ) |
| 296 | { |
| 297 | // make sure requires clause is not broken |
| 298 | DLIB_ASSERT(0.5 < probability_of_decrease && probability_of_decrease < 1, |
| 299 | "\t size_t count_steps_without_decrease()" |
| 300 | << "\n\t probability_of_decrease: "<< probability_of_decrease |
| 301 | ); |
| 302 | |
| 303 | running_gradient g; |
| 304 | size_t count = 0; |
| 305 | size_t j = 0; |
| 306 | for (auto i = container.rbegin(); i != container.rend(); ++i) |
| 307 | { |
| 308 | ++j; |
| 309 | g.add(*i); |
| 310 | if (g.current_n() > 2) |
| 311 | { |
| 312 | // Note that this only looks backwards because we are looping over the |
| 313 | // container backwards. So here we are really checking if the gradient isn't |
| 314 | // decreasing. |
| 315 | double prob_decreasing = g.probability_gradient_greater_than(0); |
| 316 | // If we aren't confident things are decreasing. |
| 317 | if (prob_decreasing < probability_of_decrease) |
| 318 | count = j; |
| 319 | } |
| 320 | } |
| 321 | return count; |
| 322 | } |
| 323 | |
| 324 | // ---------------------------------------------------------------------------------------- |
| 325 |
no test coverage detected