changeset 743:504ce30bbd2a

added hard_time_limit to stopper
author bergstra@ip05.m
date Mon, 01 Jun 2009 00:22:35 -0400
parents 5aa4cf193197
children 4d22396678e6
files pylearn/algorithms/stopper.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/algorithms/stopper.py	Sun May 31 05:07:55 2009 -0400
+++ b/pylearn/algorithms/stopper.py	Mon Jun 01 00:22:35 2009 -0400
@@ -1,3 +1,4 @@
+import time
 """Early stopping iterators
 
 The idea here is to supply early-stopping heuristics that can be used in the
@@ -65,12 +66,14 @@
         return ICML08Stopper(30*ntrain/batchsize,
                 ntrain/batchsize, 0.96, 2.0, 100000000)
 
-    def __init__(self, i_wait, v_int, min_improvement, patience, hard_limit):
+    def __init__(self, i_wait, v_int, min_improvement, patience, hard_limit, hard_time_limit=None):
         self.initial_wait = i_wait
         self.set_score_interval = v_int
         self.min_improvement = min_improvement
         self.patience = patience
         self.hard_limit = hard_limit
+        self.hard_limit_seconds = hard_time_limit
+        self.start_time = time.time()
 
         self.best_score = float('inf')
         self.best_iter = -1
@@ -97,7 +100,8 @@
 
         starting = self.iter < self.initial_wait
         waiting = self.iter < (self.patience * self.best_iter)
-        if starting or waiting:
+        times_up = (time.time() - self.start_time) > self.hard_limit_second if self.hard_limit_second != None else False
+        if (starting or waiting) and not times_up:
             # continue to iterate
             self.iter += 1
             if self.iter == self.hard_limit: