changeset 1474:a57f4839a9d8

merge
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 18 May 2011 10:52:42 -0400
parents 91a475ca9b6d (current diff) c41fdf8c35b8 (diff)
children e7401822d596
files pylearn/gd/sgd.py
diffstat 6 files changed, 78 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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.
 
--- 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!
--- /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
--- 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
--- 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
 
--- 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: