# HG changeset patch # User Yoshua Bengio # Date 1216491161 14400 # Node ID 32c5f87bc54e5b86f46e0326d7b1a50cdf68801b # Parent e01f17be270a710544b79edb9676614bf51953a2 Added __len__ to HStackedDataSet and replaced default len() by sys.maxint instead of None diff -r e01f17be270a -r 32c5f87bc54e dataset.py --- a/dataset.py Sat Jul 19 10:11:22 2008 -0400 +++ b/dataset.py Sat Jul 19 14:12:41 2008 -0400 @@ -220,7 +220,8 @@ Sub-classes which implement finite-length datasets should redefine this method. Some methods only make sense for finite-length datasets. """ - return None + from sys import maxint + return maxint class MinibatchToSingleExampleIterator(object): @@ -943,6 +944,9 @@ del self.fieldname2dataset[fieldname] self.fieldname2dataset[rename_field(fieldname,self.datasets[i],i)]=i + def __len__(self): + return len(self.datasets[0]) + def hasFields(self,*fieldnames): for fieldname in fieldnames: if not fieldname in self.fieldname2dataset: diff -r e01f17be270a -r 32c5f87bc54e kernel_regression.py --- a/kernel_regression.py Sat Jul 19 10:11:22 2008 -0400 +++ b/kernel_regression.py Sat Jul 19 14:12:41 2008 -0400 @@ -48,7 +48,7 @@ Usage: - kernel_regressor=KernelRegression(L2_regularizer=0.1,kernel=GaussianKernel(gamma=0.5)) + kernel_regressor=KernelRegression(L2_regularizer=0.1,gamma=0.5) (kernel=GaussianKernel(gamma=0.5)) kernel_predictor=kernel_regressor(training_set) all_results_dataset=kernel_predictor(test_set) # creates a dataset with "output" and "squared_error" field outputs = kernel_predictor.compute_outputs(inputs) # inputs and outputs are numpy arrays @@ -96,7 +96,11 @@ train_inputs = numpy.array(data['input']) Y[0]=1 Y[1:,:] = numpy.array(data['target']) - M,train_inputs_square=self.equations.compute_system_matrix(train_inputs,M) + train_inputs_square,sumG=self.equations.compute_system_matrix(train_inputs,M) + M[0,1:] = sumG + M[1:,0] = 1 + M[0,0] = M.shape[0] + print M theta=numpy.linalg.solve(M,Y) return KernelPredictor(theta,self.gamma, train_inputs, train_inputs_square) @@ -111,7 +115,7 @@ b = theta[0] alpha = theta[1:,:] inputs_square = T.sum(inputs*inputs,axis=1) - Kx = exp(-(train_inputs_square-2*dot(inputs,train_inputs.T)+inputs_square)*inv_gamma2) + Kx = T.exp(-(train_inputs_square-2*T.dot(inputs,train_inputs.T)+inputs_square)*inv_gamma2) outputs = T.dot(Kx,alpha) + b # minibatchsize x n_outputs squared_errors = T.sum(T.sqr(targets-outputs),axis=1) @@ -132,15 +136,11 @@ self.compile() class KernelRegressionEquations(KernelPredictorEquations): - # P = KernelPredictorEquations M = T.matrix() # (n_examples+1) x (n_examples+1) inputs = T.matrix() # n_examples x n_inputs G = M[1:,1:] - new_G = gemm(G,1.,inputs,inputs.T,1.) - M2 = T.add_inplace(M,new_G) - M2[0,0] = M.shape[0] - M2[1:,0] = 1 - M2[0,1:] = T.sum(G,axis=0) + new_G = T.gemm(G,1.,inputs,inputs.T,1.) + sumG = T.sum(new_G,axis=0) inputs_square = T.sum(inputs*inputs,axis=1) __compiled = False @@ -152,7 +152,7 @@ def fn(input_vars,output_vars): return staticmethod(theano.function(input_vars,output_vars, linker=linker)) - cls.compute_system_matrix = fn([cls.inputs,cls.M],[cls.M2,cls.inputs_square]) + cls.compute_system_matrix = fn([cls.inputs,cls.M],[cls.inputs_square,cls.sumG]) cls.__compiled = True diff -r e01f17be270a -r 32c5f87bc54e lookup_list.py --- a/lookup_list.py Sat Jul 19 10:11:22 2008 -0400 +++ b/lookup_list.py Sat Jul 19 14:12:41 2008 -0400 @@ -29,6 +29,7 @@ U{http://epydoc.sourceforge.net/manual-epytext.html#doctest-blocks} """ def __init__(self,names=[],values=[]): + print names,values assert len(values)==len(names) self.__dict__['_values']=values self.__dict__['_name2index']={}