changeset 699:6a56fcec4677

Add another kind of early stopper for NIPS 09
author Pascal Lamblin <lamblinp@iro.umontreal.ca>
date Fri, 15 May 2009 17:52:24 -0400
parents 12237ae37452
children 33e13d8ca7d3
files pylearn/sandbox/nips09stopper.py
diffstat 1 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+