1- __author__ = 'Michael Isik'
2-
1+ # -*- coding: utf-8 -*-
32
43from pybrain .tools .validation import CrossValidator
54from numpy import linspace , append , ones , zeros , array , where , apply_along_axis
65import copy
76
7+ __author__ = 'Michael Isik'
8+
9+
810class GridSearch2D :
911 """ Abstract class providing a method for searching optimal metaparmeters
1012 of a training algorithm.
@@ -304,16 +306,17 @@ def _getTrainerForParams(self, params):
304306 return trainer
305307
306308
307-
308-
309309class GridSearchDOECostGamma (GridSearchDOE ):
310310 """ Same as GridSearchCostGamma, except, that it uses the Design of Experiment (DOE)
311311 algorithm.
312312 """
313313 def __init__ (self , trainer , dataset , min_params = [- 5 , - 15 ], max_params = [15 , 3 ], n_iterations = 5 , ** kwargs ):
314314 """ See GridSearchCostGamma and GridSearchDOE """
315315 GridSearchDOE .__init__ (self , min_params , max_params , n_iterations )
316- assert len (min_params ) == 2
316+
317+ if len (min_params ) != 2 :
318+ raise Exception ("len(min_params) != 2" )
319+
317320 self ._trainer = trainer
318321 self ._dataset = dataset
319322
@@ -331,7 +334,6 @@ def setArgs(self, **kwargs):
331334 else :
332335 GridSearchDOE .setArgs (self , ** {key :value })
333336
334-
335337 def _validate (self , params ):
336338 """ See GridSearchCostGamma """
337339 glob_idx = tuple (params )
@@ -345,14 +347,8 @@ def _validate(self, params):
345347 local_perf = perf [glob_idx ]
346348 return local_perf
347349
348-
349350 def _getTrainerForParams (self , params ):
350351 """ See GridSearchCostGamma """
351352 trainer = copy .deepcopy (self ._trainer )
352353 trainer .setArgs (cost = 2 ** params [0 ], gamma = 2 ** params [1 ], ver = 0 )
353354 return trainer
354-
355-
356-
357-
358-
0 commit comments