# HG changeset patch # User Pascal Lamblin # Date 1242424344 14400 # Node ID 6a56fcec46770eb54303f78776f3acc80e95a14b # Parent 12237ae37452fb8394dd920aa3bc0285a89cb35a Add another kind of early stopper for NIPS 09 diff -r 12237ae37452 -r 6a56fcec4677 pylearn/sandbox/nips09stopper.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylearn/sandbox/nips09stopper.py Fri May 15 17:52:24 2009 -0400 @@ -0,0 +1,54 @@ +"""Early stopper""" + +class NIPS09Stopper(object): + """Contrary to pylearn.algorithms.stopper, this early stopper should be + used by calling 'find_min'. + + This stoppers stops if... + n_iter_max iterations have happened since the beginning, + OR (training error is below train_error_min + AND (n_iter_max * patience iterations have happened since last minimum + OR validation error gets higher than its minimum * valid_aumentation_max)) + """ + + def __init__(self, n_iter_max, + train_error_min = float('inf'), + patience = 0.1, + valid_augmentation_max = 1.1, + set_score_interval = 1): + self.stop = False + self.iter = 0 + + self.n_iter_max = n_iter_max + self.train_error_min = train_error_min + self.patience = patience + self.valid_augmentation_max = valid_augmentation_max + self.set_score_interval = set_score_interval + + self.best_valid = float('inf') + self.best_valid_iter = -1 + + + def find_min(self, step, check, save): + best = None + while not self.stop: + self.iter++ + step() + if (self.iter % self.set_score_interval == 0): + self.train_score, self.valid_score = check() + if (self.valid_score < self.best_valid) and save: + self.best_valid = self.valid_score + self.best_valid_iter = self.iter + best = (save(), self.iter, self.valid_score) + + if self.iter >= self.n_iter_max: + self.stop = True + elif self.train_score < self.train_error_min: + if (self.iter - self.best_valid_iter) >\ + self.n_iter_max * self.patience: + self.stop = True + elif self.valid_score > self.best_valid * self.valid_augmentation_max: + self.stop = True + + return best +