| 18 | """ |
| 19 | |
| 20 | def stop_fn(trials, best_loss=None, iteration_no_progress=0): |
| 21 | new_loss = trials.trials[len(trials.trials) - 1]["result"]["loss"] |
| 22 | if best_loss is None: |
| 23 | return False, [new_loss, iteration_no_progress + 1] |
| 24 | best_loss_threshold = best_loss - abs(best_loss * (percent_increase / 100.0)) |
| 25 | if new_loss < best_loss_threshold: |
| 26 | best_loss = new_loss |
| 27 | iteration_no_progress = 0 |
| 28 | else: |
| 29 | iteration_no_progress += 1 |
| 30 | logger.debug( |
| 31 | "No progress made: %d iteration on %d. best_loss=%.2f, best_loss_threshold=%.2f, new_loss=%.2f" |
| 32 | % ( |
| 33 | iteration_no_progress, |
| 34 | iteration_stop_count, |
| 35 | best_loss, |
| 36 | best_loss_threshold, |
| 37 | new_loss, |
| 38 | ) |
| 39 | ) |
| 40 | |
| 41 | return ( |
| 42 | iteration_no_progress >= iteration_stop_count, |
| 43 | [best_loss, iteration_no_progress], |
| 44 | ) |
| 45 | |
| 46 | return stop_fn |