changeset 1507:2a6a6f16416c

fix import.
author Frederic Bastien <nouiz@nouiz.org>
date Mon, 12 Sep 2011 11:45:41 -0400
parents 2f69c9932d9a
children b28e8730c948
files pylearn/algorithms/mcRBM.py pylearn/algorithms/tests/test_mcRBM.py
diffstat 2 files changed, 23 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/algorithms/mcRBM.py	Mon Sep 12 10:56:38 2011 -0400
+++ b/pylearn/algorithms/mcRBM.py	Mon Sep 12 11:45:41 2011 -0400
@@ -199,22 +199,18 @@
 #    + 0.5 \sum_i v_i^2
 #    - \sum_i a_i v_i
 
-import sys, os, logging
 import numpy as np
 import numpy
 
 import theano
-from theano import function, shared, dot
+from theano import dot
 from theano import tensor as TT
 floatX = theano.config.floatX
 
-sharedX = lambda X, name : shared(numpy.asarray(X, dtype=floatX), name=name)
+sharedX = lambda X, name : theano.shared(numpy.asarray(X, dtype=floatX), name=name)
 
-import pylearn
 from pylearn.sampling.hmc import HMC_sampler
-from pylearn.io import image_tiling
 from pylearn.gd.sgd import sgd_updates
-import pylearn.dataset_ops.image_patches
 
 ###########################################
 #
--- a/pylearn/algorithms/tests/test_mcRBM.py	Mon Sep 12 10:56:38 2011 -0400
+++ b/pylearn/algorithms/tests/test_mcRBM.py	Mon Sep 12 11:45:41 2011 -0400
@@ -1,11 +1,15 @@
 import sys
-from pylearn.algorithms.mcRBM import *
-import pylearn.datasets.cifar10
-import pylearn.dataset_ops.tinyimages
+
+import numpy
+import theano
+from theano import tensor
 
+from pylearn.algorithms.mcRBM import mcRBM, mcRBMTrainer, mcRBM_withP, l2
+#import pylearn.datasets.cifar10
 import pylearn.dataset_ops.cifar10
-from theano import tensor
 from pylearn.shared.layers.logreg import LogisticRegression
+from pylearn.io import image_tiling
+import pylearn.dataset_ops.image_patches
 
 
 def _default_rbm_alloc(n_I, n_K=256, n_J=100):
@@ -69,8 +73,8 @@
                     min_dynamic_range=1e-2)
             image_tiling.save_tiled_raster_images(_img, fname)
 
-    batch_idx = TT.iscalar()
-    batch_range =batch_idx * batchsize + np.arange(batchsize)
+    batch_idx = tensor.iscalar()
+    batch_range =batch_idx * batchsize + numpy.arange(batchsize)
 
     if dataset == 'MAR':
         train_batch = pylearn.dataset_ops.image_patches.ranzato_hinton_2010_op(batch_range)
@@ -82,15 +86,15 @@
         train_batch = pylearn.dataset_ops.tinyimages.tinydataset_op(batch_range)
     else:
         train_batch = pylearn.dataset_ops.image_patches.image_patches(
-                s_idx = (batch_idx * batchsize + np.arange(batchsize)),
+                s_idx = (batch_idx * batchsize + numpy.arange(batchsize)),
                 dims = (n_patches,R,C),
                 center=True,
                 unitvar=True,
-                dtype=floatX,
+                dtype=theano.config.floatX,
                 rasterized=True)
 
     if not as_unittest:
-        imgs_fn = function([batch_idx], outputs=train_batch)
+        imgs_fn = theano.function([batch_idx], outputs=train_batch)
 
     trainer = trainer_alloc(
             rbm_alloc(n_I=n_vis),
@@ -104,11 +108,11 @@
 
     if persistent_chains:
         grads = trainer.contrastive_grads()
-        learn_fn = function([batch_idx], 
+        learn_fn = theano.function([batch_idx], 
                 outputs=[grads[0].norm(2), grads[0].norm(2), grads[1].norm(2)],
                 updates=trainer.cd_updates())
     else:
-        learn_fn = function([batch_idx], outputs=[], updates=trainer.cd_updates())
+        learn_fn = theano.function([batch_idx], outputs=[], updates=trainer.cd_updates())
 
     if persistent_chains:
         smplr = trainer.sampler
@@ -254,7 +258,7 @@
                 p_training_start=2*epoch_size//batchsize,
                 persistent_chains=False)
         rbm=trainer.rbm
-        learn_fn = function([train_batch], outputs=[], updates=trainer.cd_updates())
+        learn_fn = theano.function([train_batch], outputs=[], updates=trainer.cd_updates())
         smplr = trainer._last_cd1_sampler
 
         ii = 0
@@ -323,9 +327,9 @@
 
         # put these into shared vars because support for big matrix constants is bad,
         # (comparing them is slow)
-        pca_eigvecs = shared(pca_dct['eig_vecs'].astype('float32'))
-        pca_eigvals = shared(pca_dct['eig_vals'].astype('float32'))
-        pca_mean    = shared(pca_dct['mean'].astype('float32'))
+        pca_eigvecs = theano.shared(pca_dct['eig_vecs'].astype('float32'))
+        pca_eigvals = theano.shared(pca_dct['eig_vals'].astype('float32'))
+        pca_mean    = theano.shared(pca_dct['mean'].astype('float32'))
 
         def theano_pca_whiten(X):
             #copying preprepcessing.pca.pca_whiten
@@ -354,7 +358,7 @@
 
         hg = tensor.concatenate(h_list + g_list, axis=1)
 
-        feat_fn = function([feat_idx], hg)
+        feat_fn = theano.function([feat_idx], hg)
         features = numpy.empty((60000, 11025), dtype='float32')
         for i in xrange(60000//batchsize):
             if i % 100 == 0:
@@ -402,7 +406,7 @@
         traincost = feature_logreg.nll(y_i).sum()
         traincost = traincost + abs(feature_logreg.w).sum() * l1_regularization
         #traincost = traincost + (feature_logreg.w**2).sum() * l2_regularization
-        train_logreg_fn = function([x_i, y_i, lr], 
+        train_logreg_fn = theano.function([x_i, y_i, lr], 
                 [feature_logreg.nll(y_i).mean(),
                     feature_logreg.errors(y_i).mean()],
                 updates=pylearn.gd.sgd.sgd_updates(