comparison mlp_factory_approach.py @ 232:c047238e5b3f

Fixed by James
author delallea@opale.iro.umontreal.ca
date Tue, 27 May 2008 15:49:09 -0400
parents 3595ba2610f7
children 3156a9976183
comparison
equal deleted inserted replaced
231:38beb81f4e8b 232:c047238e5b3f
44 """Update this model from more training data.""" 44 """Update this model from more training data."""
45 params = self.params 45 params = self.params
46 #TODO: why should we have to unpack target like this? 46 #TODO: why should we have to unpack target like this?
47 # tbm : creates problem... 47 # tbm : creates problem...
48 for input, target in input_target: 48 for input, target in input_target:
49 rval= self.update_fn(input, target[:,0], *params) 49 rval= self.update_fn(input, target, *params)
50 #print rval[0] 50 #print rval[0]
51 51
52 def __call__(self, testset, fieldnames=['output_class'],input='input',target='target'): 52 def __call__(self, testset, fieldnames=['output_class'],input='input',target='target'):
53 """Apply this model (as a function) to new data""" 53 """Apply this model (as a function) to new data"""
54 #TODO: cache fn between calls 54 #TODO: cache fn between calls
134 valset = trainset[nmin:] #validation set for early stopping 134 valset = trainset[nmin:] #validation set for early stopping
135 best = rval 135 best = rval
136 for stp in self.early_stopper(): 136 for stp in self.early_stopper():
137 rval.update( 137 rval.update(
138 minset.minibatches([input, target], minibatch_size=min(32, 138 minset.minibatches([input, target], minibatch_size=min(32,
139 len(trainset)))) 139 len(minset))))
140 #print 'mlp.__call__(), we did an update' 140 #print 'mlp.__call__(), we did an update'
141 if stp.set_score: 141 if stp.set_score:
142 stp.score = rval(valset, ['loss_01']) 142 stp.score = rval(valset, ['loss_01'])
143 if (stp.score < stp.best_score): 143 if (stp.score < stp.best_score):
144 best = copy.copy(rval) 144 best = copy.copy(rval)
169 169
170 learn_algo = MultiLayerPerceptron(2, 10, 2, .1 170 learn_algo = MultiLayerPerceptron(2, 10, 2, .1
171 , linker='c&py' 171 , linker='c&py'
172 , early_stopper = lambda:stopper.NStages(100,1)) 172 , early_stopper = lambda:stopper.NStages(100,1))
173 173
174 model1 = learn_algo(training_set1,input='input',target='target') 174 model1 = learn_algo(training_set1)
175 175
176 model2 = learn_algo(training_set2) 176 model2 = learn_algo(training_set2)
177 177
178 n_match = 0 178 n_match = 0
179 for o1, o2 in zip(model1(test_data), model2(test_data)): 179 for o1, o2 in zip(model1(test_data), model2(test_data)):