Skip to content

Commit 3f46135

Browse files
committed
Ran code through pep8 and fixed all occurrences of E251 unexpected spaces around keyword / parameter equals. Fixed indentation of comments in rnnrbm.py.
1 parent 1d8b9fd commit 3f46135

File tree

7 files changed

+182
-182
lines changed

7 files changed

+182
-182
lines changed

code/SdA.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class SdA(object):
5959

6060
def __init__(self,
6161
numpy_rng,
62-
theano_rng = None,
63-
n_ins = 784,
64-
hidden_layers_sizes = [500, 500],
65-
n_outs = 10,
66-
corruption_levels = [0.1, 0.1]
62+
theano_rng=None,
63+
n_ins=784,
64+
hidden_layers_sizes=[500, 500],
65+
n_outs=10,
66+
corruption_levels=[0.1, 0.1]
6767
):
6868
""" This class is made to support a variable number of layers.
6969
@@ -246,9 +246,9 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate):
246246
(test_set_x, test_set_y) = datasets[2]
247247

248248
# compute number of minibatches for training, validation and testing
249-
n_valid_batches = valid_set_x.get_value(borrow = True).shape[0]
249+
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0]
250250
n_valid_batches /= batch_size
251-
n_test_batches = test_set_x.get_value(borrow = True).shape[0]
251+
n_test_batches = test_set_x.get_value(borrow=True).shape[0]
252252
n_test_batches /= batch_size
253253

254254
index = T.lscalar('index') # index to a [mini]batch
@@ -263,30 +263,30 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate):
263263
]
264264

265265
train_fn = theano.function(
266-
inputs = [index],
267-
outputs = self.finetune_cost,
268-
updates = updates,
269-
givens = {
266+
inputs=[index],
267+
outputs=self.finetune_cost,
268+
updates=updates,
269+
givens={
270270
self.x: train_set_x[index * batch_size : (index + 1) * batch_size],
271271
self.y: train_set_y[index * batch_size : (index + 1) * batch_size]
272272
},
273-
name = 'train'
273+
name='train'
274274
)
275275

276276
test_score_i = theano.function(
277277
[index],
278278
self.errors,
279-
givens = {
279+
givens={
280280
self.x: test_set_x[index * batch_size : (index + 1) * batch_size],
281281
self.y: test_set_y[index * batch_size : (index + 1) * batch_size]
282282
},
283-
name = 'test'
283+
name='test'
284284
)
285285

286286
valid_score_i = theano.function(
287287
[index],
288288
self.errors,
289-
givens = {
289+
givens={
290290
self.x: valid_set_x[index * batch_size : (index + 1) * batch_size],
291291
self.y: valid_set_y[index * batch_size : (index + 1) * batch_size]
292292
},
@@ -345,10 +345,10 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
345345
print '... building the model'
346346
# construct the stacked denoising autoencoder class
347347
sda = SdA(
348-
numpy_rng = numpy_rng,
349-
n_ins = 28 * 28,
350-
hidden_layers_sizes = [1000, 1000, 1000],
351-
n_outs = 10
348+
numpy_rng=numpy_rng,
349+
n_ins=28 * 28,
350+
hidden_layers_sizes=[1000, 1000, 1000],
351+
n_outs=10
352352
)
353353

354354
#########################

code/convolutional_mlp.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def __init__(self, rng, input, filter_shape, image_shape, poolsize=(2, 2)):
7878
W_bound = numpy.sqrt(6. / (fan_in + fan_out))
7979
self.W = theano.shared(
8080
numpy.asarray(
81-
rng.uniform(low = -W_bound, high = W_bound, size = filter_shape),
82-
dtype = theano.config.floatX
81+
rng.uniform(low=-W_bound, high=W_bound, size=filter_shape),
82+
dtype=theano.config.floatX
8383
),
84-
borrow = True
84+
borrow=True
8585
)
8686

8787
# the bias is a 1D tensor -- one bias per output feature map
@@ -90,17 +90,17 @@ def __init__(self, rng, input, filter_shape, image_shape, poolsize=(2, 2)):
9090

9191
# convolve input feature maps with filters
9292
conv_out = conv.conv2d(
93-
input = input,
94-
filters = self.W,
95-
filter_shape = filter_shape,
96-
image_shape = image_shape
93+
input=input,
94+
filters=self.W,
95+
filter_shape=filter_shape,
96+
image_shape=image_shape
9797
)
9898

9999
# downsample each feature map individually, using maxpooling
100100
pooled_out = downsample.max_pool_2d(
101-
input = conv_out,
102-
ds = poolsize,
103-
ignore_border = True
101+
input=conv_out,
102+
ds=poolsize,
103+
ignore_border=True
104104
)
105105

106106
# add the bias term. Since the bias is a vector (1D array), we first
@@ -141,9 +141,9 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
141141
test_set_x, test_set_y = datasets[2]
142142

143143
# compute number of minibatches for training, validation and testing
144-
n_train_batches = train_set_x.get_value(borrow = True).shape[0]
145-
n_valid_batches = valid_set_x.get_value(borrow = True).shape[0]
146-
n_test_batches = test_set_x.get_value(borrow = True).shape[0]
144+
n_train_batches = train_set_x.get_value(borrow=True).shape[0]
145+
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0]
146+
n_test_batches = test_set_x.get_value(borrow=True).shape[0]
147147
n_train_batches /= batch_size
148148
n_valid_batches /= batch_size
149149
n_test_batches /= batch_size
@@ -171,10 +171,10 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
171171
# 4D output tensor is thus of shape (batch_size,nkerns[0],12,12)
172172
layer0 = LeNetConvPoolLayer(
173173
rng,
174-
input = layer0_input,
175-
image_shape = (batch_size, 1, 28, 28),
176-
filter_shape = (nkerns[0], 1, 5, 5),
177-
poolsize = (2, 2)
174+
input=layer0_input,
175+
image_shape=(batch_size, 1, 28, 28),
176+
filter_shape=(nkerns[0], 1, 5, 5),
177+
poolsize=(2, 2)
178178
)
179179

180180
# Construct the second convolutional pooling layer
@@ -183,10 +183,10 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
183183
# 4D output tensor is thus of shape (nkerns[0],nkerns[1],4,4)
184184
layer1 = LeNetConvPoolLayer(
185185
rng,
186-
input = layer0.output,
187-
image_shape = (batch_size, nkerns[0], 12, 12),
188-
filter_shape = (nkerns[1], nkerns[0], 5, 5),
189-
poolsize = (2, 2)
186+
input=layer0.output,
187+
image_shape=(batch_size, nkerns[0], 12, 12),
188+
filter_shape=(nkerns[1], nkerns[0], 5, 5),
189+
poolsize=(2, 2)
190190
)
191191

192192
# the HiddenLayer being fully-connected, it operates on 2D matrices of
@@ -197,14 +197,14 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
197197
# construct a fully-connected sigmoidal layer
198198
layer2 = HiddenLayer(
199199
rng,
200-
input = layer2_input,
201-
n_in = nkerns[1] * 4 * 4,
202-
n_out = 500,
203-
activation = T.tanh
200+
input=layer2_input,
201+
n_in=nkerns[1] * 4 * 4,
202+
n_out=500,
203+
activation=T.tanh
204204
)
205205

206206
# classify the values of the fully-connected sigmoidal layer
207-
layer3 = LogisticRegression(input = layer2.output, n_in = 500, n_out = 10)
207+
layer3 = LogisticRegression(input=layer2.output, n_in=500, n_out=10)
208208

209209
# the cost we minimize during training is the NLL of the model
210210
cost = layer3.negative_log_likelihood(y)
@@ -213,7 +213,7 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
213213
test_model = theano.function(
214214
[index],
215215
layer3.errors(y),
216-
givens = {
216+
givens={
217217
x: test_set_x[index * batch_size : (index + 1) * batch_size],
218218
y: test_set_y[index * batch_size : (index + 1) * batch_size]
219219
}
@@ -222,7 +222,7 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
222222
validate_model = theano.function(
223223
[index],
224224
layer3.errors(y),
225-
givens = {
225+
givens={
226226
x: valid_set_x[index * batch_size : (index + 1) * batch_size],
227227
y: valid_set_y[index * batch_size : (index + 1) * batch_size]
228228
}
@@ -247,8 +247,8 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
247247
train_model = theano.function(
248248
[index],
249249
cost,
250-
updates = updates,
251-
givens = {
250+
updates=updates,
251+
givens={
252252
x: train_set_x[index * batch_size : (index + 1) * batch_size],
253253
y: train_set_y[index * batch_size : (index + 1) * batch_size]
254254
}

code/dA.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class dA(object):
7878
def __init__(
7979
self,
8080
numpy_rng,
81-
theano_rng = None,
82-
input = None,
83-
n_visible = 784,
84-
n_hidden = 500,
85-
W = None,
86-
bhid = None,
87-
bvis = None
81+
theano_rng=None,
82+
input=None,
83+
n_visible=784,
84+
n_hidden=500,
85+
W=None,
86+
bhid=None,
87+
bvis=None
8888
):
8989
"""
9090
Initialize the dA class by specifying the number of visible units (the
@@ -287,11 +287,11 @@ def test_dA(learning_rate=0.1, training_epochs=15,
287287
theano_rng = RandomStreams(rng.randint(2 ** 30))
288288

289289
da = dA(
290-
numpy_rng = rng,
291-
theano_rng = theano_rng,
292-
input = x,
293-
n_visible = 28 * 28,
294-
n_hidden = 500
290+
numpy_rng=rng,
291+
theano_rng=theano_rng,
292+
input=x,
293+
n_visible=28 * 28,
294+
n_hidden=500
295295
)
296296

297297
cost, updates = da.get_cost_updates(
@@ -302,8 +302,8 @@ def test_dA(learning_rate=0.1, training_epochs=15,
302302
train_da = theano.function(
303303
[index],
304304
cost,
305-
updates = updates,
306-
givens = {
305+
updates=updates,
306+
givens={
307307
x: train_set_x[index * batch_size : (index + 1) * batch_size]
308308
}
309309
)
@@ -344,15 +344,15 @@ def test_dA(learning_rate=0.1, training_epochs=15,
344344
theano_rng = RandomStreams(rng.randint(2 ** 30))
345345

346346
da = dA(
347-
numpy_rng = rng,
348-
theano_rng = theano_rng,
349-
input = x,
350-
n_visible = 28 * 28,
351-
n_hidden = 500
347+
numpy_rng=rng,
348+
theano_rng=theano_rng,
349+
input=x,
350+
n_visible=28 * 28,
351+
n_hidden=500
352352
)
353353

354354
cost, updates = da.get_cost_updates(
355-
corruption_level = 0.3,
355+
corruption_level=0.3,
356356
learning_rate=learning_rate
357357
)
358358

code/logistic_sgd.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ def __init__(self, input, n_in, n_out):
7575

7676
# initialize with 0 the weights W as a matrix of shape (n_in, n_out)
7777
self.W = theano.shared(
78-
value = numpy.zeros(
78+
value=numpy.zeros(
7979
(n_in, n_out),
80-
dtype = theano.config.floatX
80+
dtype=theano.config.floatX
8181
),
82-
name = 'W',
83-
borrow = True
82+
name='W',
83+
borrow=True
8484
)
8585
# initialize the baises b as a vector of n_out 0s
8686
self.b = theano.shared(
87-
value = numpy.zeros(
87+
value=numpy.zeros(
8888
(n_out,),
89-
dtype = theano.config.floatX
89+
dtype=theano.config.floatX
9090
),
91-
name = 'b',
92-
borrow = True
91+
name='b',
92+
borrow=True
9393
)
9494

9595
# symbolic expression for computing the matrix of class-membership probabilities
@@ -101,7 +101,7 @@ def __init__(self, input, n_in, n_out):
101101

102102
# symbolic description of how to compute prediction as class whose probability
103103
# is maximal
104-
self.y_pred = T.argmax(self.p_y_given_x, axis = 1)
104+
self.y_pred = T.argmax(self.p_y_given_x, axis=1)
105105

106106
# parameters of the model
107107
self.params = [self.W, self.b]
@@ -277,7 +277,7 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
277277

278278
# construct the logistic regression class
279279
# Each MNIST image has size 28*28
280-
classifier = LogisticRegression(input = x, n_in = 28 * 28, n_out = 10)
280+
classifier = LogisticRegression(input=x, n_in=28 * 28, n_out=10)
281281

282282
# the cost we minimize during training is the negative log likelihood of
283283
# the model in symbolic format
@@ -286,26 +286,26 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
286286
# compiling a Theano function that computes the mistakes that are made by
287287
# the model on a minibatch
288288
test_model = theano.function(
289-
inputs = [index],
290-
outputs = classifier.errors(y),
291-
givens = {
289+
inputs=[index],
290+
outputs=classifier.errors(y),
291+
givens={
292292
x: test_set_x[index * batch_size : (index + 1) * batch_size],
293293
y: test_set_y[index * batch_size : (index + 1) * batch_size]
294294
}
295295
)
296296

297297
validate_model = theano.function(
298-
inputs = [index],
299-
outputs = classifier.errors(y),
300-
givens = {
298+
inputs=[index],
299+
outputs=classifier.errors(y),
300+
givens={
301301
x: valid_set_x[index * batch_size : (index + 1) * batch_size],
302302
y: valid_set_y[index * batch_size : (index + 1) * batch_size]
303303
}
304304
)
305305

306306
# compute the gradient of cost with respect to theta = (W,b)
307-
g_W = T.grad(cost = cost, wrt = classifier.W)
308-
g_b = T.grad(cost = cost, wrt = classifier.b)
307+
g_W = T.grad(cost=cost, wrt=classifier.W)
308+
g_b = T.grad(cost=cost, wrt=classifier.b)
309309

310310
# specify how to update the parameters of the model as a list of
311311
# (variable, update expression) pairs.
@@ -316,10 +316,10 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
316316
# the same time updates the parameter of the model based on the rules
317317
# defined in `updates`
318318
train_model = theano.function(
319-
inputs = [index],
320-
outputs = cost,
321-
updates = updates,
322-
givens = {
319+
inputs=[index],
320+
outputs=cost,
321+
updates=updates,
322+
givens={
323323
x: train_set_x[index * batch_size : (index + 1) * batch_size],
324324
y: train_set_y[index * batch_size : (index + 1) * batch_size]
325325
}

0 commit comments

Comments
 (0)