comparison linear_regression.py @ 403:273e5c03003e

Making linear_regression more robust
author Yoshua Bengio <bengioy@iro.umontreal.ca>
date Wed, 09 Jul 2008 17:55:46 -0400
parents efb797c5efc0
children 5175c564e37a
comparison
equal deleted inserted replaced
402:ffdd2c199f2a 403:273e5c03003e
84 XtY = numpy.zeros((n_inputs+1,n_outputs)) 84 XtY = numpy.zeros((n_inputs+1,n_outputs))
85 for i in xrange(n_inputs): 85 for i in xrange(n_inputs):
86 XtX[i+1,i+1]=self.L2_regularizer 86 XtX[i+1,i+1]=self.L2_regularizer
87 mbs=min(self.minibatch_size,len(trainset)) 87 mbs=min(self.minibatch_size,len(trainset))
88 for inputs,targets in trainset.minibatches(["input","target"],minibatch_size=mbs): 88 for inputs,targets in trainset.minibatches(["input","target"],minibatch_size=mbs):
89 XtX,XtY=self.equations.update(XtX,XtY,inputs,targets) 89 XtX,XtY=self.equations.update(XtX,XtY,numpy.array(inputs),numpy.array(targets))
90 theta=numpy.linalg.solve(XtX,XtY) 90 theta=numpy.linalg.solve(XtX,XtY)
91 return LinearPredictor(theta) 91 return LinearPredictor(theta)
92 92
93 class LinearPredictorEquations(AutoName): 93 class LinearPredictorEquations(AutoName):
94 inputs = T.matrix() # minibatchsize x n_inputs 94 inputs = T.matrix() # minibatchsize x n_inputs