# HG changeset patch # User James Bergstra # Date 1305730362 14400 # Node ID a57f4839a9d859beb5f08b24e2f66af610dcc79e # Parent 91a475ca9b6d586373d940e5f27af9074820cd08# Parent c41fdf8c35b80218f170ffb00b20a2704321ca3a merge diff -r 91a475ca9b6d -r a57f4839a9d8 LICENSE --- a/LICENSE Wed May 18 10:52:22 2011 -0400 +++ b/LICENSE Wed May 18 10:52:42 2011 -0400 @@ -1,4 +1,4 @@ -Copyright (c) 2008, Theano Development Team +Copyright (c) 2008-2011, Pylearn Development Team All rights reserved. Redistribution and use in source and binary forms, with or without @@ -8,7 +8,7 @@ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Theano nor the names of its contributors may be + * Neither the name of Pylearn nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff -r 91a475ca9b6d -r a57f4839a9d8 pylearn/algorithms/aa.py --- a/pylearn/algorithms/aa.py Wed May 18 10:52:22 2011 -0400 +++ b/pylearn/algorithms/aa.py Wed May 18 10:52:42 2011 -0400 @@ -2,6 +2,8 @@ import theano from theano import tensor as T from theano.tensor import nnet as NN +floatX = theano.config.floatX + import numpy as N class AutoEncoder(theano.Module): @@ -73,11 +75,15 @@ if input_size is not None: sz = (input_size, hidden_size) range = 1/N.sqrt(input_size) - obj.w1 = R.uniform(size = sz, low = -range, high = range) + if floatX=='float32': + range = N.float32(range) + obj.w1 = N.asarray(R.uniform(size = sz, low = -range, high = range), + dtype=floatX) if not self.tie_weights: - obj.w2 = R.uniform(size = list(reversed(sz)), low = -range, high = range) - obj.b1 = N.zeros(hidden_size) - obj.b2 = N.zeros(input_size) + obj.w2 = N.asarray(R.uniform(size = list(reversed(sz)), low = -range, high = range), + dtype=floatX) + obj.b1 = N.zeros(hidden_size, dtype=floatX) + obj.b2 = N.zeros(input_size, dtype=floatX) def build_regularization(self): return T.zero() # no regularization! diff -r 91a475ca9b6d -r a57f4839a9d8 pylearn/datasets/nade.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylearn/datasets/nade.py Wed May 18 10:52:42 2011 -0400 @@ -0,0 +1,59 @@ +import os +import numpy + +from pylearn.io.pmat import PMat +from pylearn.datasets.config import data_root # config +from pylearn.datasets.dataset import Dataset + +def load_dataset(name=None): + """ + Various datasets which were used in the following paper. + The Neural Autoregressive Distribution Estimator + Hugo Larochelle and Iain Murray, AISTATS 2011 + + :param name: string specifying which dataset to load + :return: Dataset object + dataset.train.x: matrix of training data of shape (num_examples, ndim) + dataset.train.y: vector of training labels of length num_examples. Labels are + integer valued and represent the class it belongs too. + dataset.valid.x: idem for validation data + dataset.valid.y: idem for validation data + dataset.test.x: idem for test data + dataset.test.y: idem for test data + + WARNING: class labels are integer-valued instead of 1-of-n encoding ! + """ + assert name in ['adult','binarized_mnist', 'mnist', 'connect4','dna', + 'mushrooms','nips','ocr_letters','rcv1','web'] + rval = Dataset() + + path = os.path.join(data_root(), 'larocheh', name) + + # load training set + x=numpy.load(os.path.join(path,'train_data.npy')) + y_fname = os.path.join(path, 'train_labels.npy') + if os.path.exists(y_fname): + y = numpy.load(os.path.join(path,'train_labels.npy')) + else: + y = None + rval.train = Dataset.Obj(x=x, y=y) + + # load validation set + x=numpy.load(os.path.join(path,'valid_data.npy')) + y_fname = os.path.join(path, 'valid_labels.npy') + if os.path.exists(y_fname): + y = numpy.load(os.path.join(path,'valid_labels.npy')) + else: + y = None + rval.valid = Dataset.Obj(x=x, y=y) + + # load training set + x=numpy.load(os.path.join(path,'test_data.npy')) + y_fname = os.path.join(path, 'test_labels.npy') + if os.path.exists(y_fname): + y = numpy.load(os.path.join(path,'test_labels.npy')) + else: + y = None + rval.test = Dataset.Obj(x=x, y=y) + + return rval diff -r 91a475ca9b6d -r a57f4839a9d8 pylearn/datasets/utlc.py --- a/pylearn/datasets/utlc.py Wed May 18 10:52:22 2011 -0400 +++ b/pylearn/datasets/utlc.py Wed May 18 10:52:42 2011 -0400 @@ -174,7 +174,7 @@ else: raise Exception("This dataset don't have its normalization defined") if transfer: - transfer = load_sparse(os.path.join(config.data_root(),"UTLC","sparse",name+"_transfer.npy")) + transfer = load_filetensor(os.path.join(config.data_root(),"UTLC","filetensor",name+"_transfer.ft")) return train, valid, test, transfer else: return train, valid, test diff -r 91a475ca9b6d -r a57f4839a9d8 pylearn/formulas/costs.py --- a/pylearn/formulas/costs.py Wed May 18 10:52:22 2011 -0400 +++ b/pylearn/formulas/costs.py Wed May 18 10:52:42 2011 -0400 @@ -168,7 +168,7 @@ # in which file? from theano import gof -from theano.tensor.tsor_apply import Apply +from theano.tensor import Apply from theano import tensor import numpy as np diff -r 91a475ca9b6d -r a57f4839a9d8 pylearn/gd/sgd.py --- a/pylearn/gd/sgd.py Wed May 18 10:52:22 2011 -0400 +++ b/pylearn/gd/sgd.py Wed May 18 10:52:42 2011 -0400 @@ -16,7 +16,7 @@ """ try: iter(stepsizes) - except: + except Exception: stepsizes = [stepsizes for p in params] if len(params) != len(grads): raise ValueError('params and grads have different lens') @@ -27,11 +27,11 @@ # if stepsizes is just a scalar, expand it to match params try: iter(stepsizes) - except: + except Exception: stepsizes = [stepsizes for p in params] try: iter(momentum) - except: + except Exception: momentum = [momentum for p in params] if len(params) != len(grads): raise ValueError('params and grads have different lens') @@ -79,7 +79,8 @@ raise TypeError('stepsize must be a scalar', stepsize) self.params = params - self.gparams = theano.tensor.grad(cost, self.params) if gradients is None else gradients + self.gparams = [theano.tensor.grad(cost, self.params)] if gradients is None else gradients + assert len(self.params) == len(self.gparams) self._updates = (dict((p, p - self.stepsize * g) for p, g in zip(self.params, self.gparams))) if updates is not None: