Skip to content

Commit e3f9cd2

Browse files
committed
Minimized lines > 79 characters, trailing whitespace, and whitespace before :
1 parent cef1016 commit e3f9cd2

File tree

8 files changed

+136
-107
lines changed

8 files changed

+136
-107
lines changed

code/SdA.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class SdA(object):
5858
"""
5959

6060
def __init__(
61-
self,
62-
numpy_rng,
63-
theano_rng=None,
61+
self,
62+
numpy_rng,
63+
theano_rng=None,
6464
n_ins=784,
65-
hidden_layers_sizes=[500, 500],
65+
hidden_layers_sizes=[500, 500],
6666
n_outs=10,
6767
corruption_levels=[0.1, 0.1]
6868
):
@@ -268,28 +268,40 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate):
268268
outputs=self.finetune_cost,
269269
updates=updates,
270270
givens={
271-
self.x: train_set_x[index * batch_size : (index + 1) * batch_size],
272-
self.y: train_set_y[index * batch_size : (index + 1) * batch_size]
271+
self.x: train_set_x[
272+
index * batch_size: (index + 1) * batch_size
273+
],
274+
self.y: train_set_y[
275+
index * batch_size: (index + 1) * batch_size
276+
]
273277
},
274278
name='train'
275279
)
276280

277281
test_score_i = theano.function(
278-
[index],
282+
[index],
279283
self.errors,
280284
givens={
281-
self.x: test_set_x[index * batch_size : (index + 1) * batch_size],
282-
self.y: test_set_y[index * batch_size : (index + 1) * batch_size]
285+
self.x: test_set_x[
286+
index * batch_size: (index + 1) * batch_size
287+
],
288+
self.y: test_set_y[
289+
index * batch_size: (index + 1) * batch_size
290+
]
283291
},
284292
name='test'
285293
)
286294

287295
valid_score_i = theano.function(
288-
[index],
296+
[index],
289297
self.errors,
290298
givens={
291-
self.x: valid_set_x[index * batch_size : (index + 1) * batch_size],
292-
self.y: valid_set_y[index * batch_size : (index + 1) * batch_size]
299+
self.x: valid_set_x[
300+
index * batch_size: (index + 1) * batch_size
301+
],
302+
self.y: valid_set_y[
303+
index * batch_size: (index + 1) * batch_size
304+
]
293305
},
294306
name='valid'
295307
)
@@ -346,7 +358,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
346358
print '... building the model'
347359
# construct the stacked denoising autoencoder class
348360
sda = SdA(
349-
numpy_rng=numpy_rng,
361+
numpy_rng=numpy_rng,
350362
n_ins=28 * 28,
351363
hidden_layers_sizes=[1000, 1000, 1000],
352364
n_outs=10

code/cA.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
squared Frobenius norm of the Jacobian of the hidden mapping h with
1313
respect to the visible units yields the contractive auto-encoder:
1414
15-
- \sum_{k=1}^d[ x_k \log z_k + (1-x_k) \log( 1-z_k)] + \| \frac{\partial h(x)}{\partial x} \|^2
15+
- \sum_{k=1}^d[ x_k \log z_k + (1-x_k) \log( 1-z_k)] + \| \frac{\partial h(x)}{\partial x} \|^2
1616
1717
References :
1818
- S. Rifai, P. Vincent, X. Muller, X. Glorot, Y. Bengio: Contractive

code/convolutional_mlp.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ 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,
93+
input=input,
9494
filters=self.W,
95-
filter_shape=filter_shape,
95+
filter_shape=filter_shape,
9696
image_shape=image_shape
9797
)
9898

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

@@ -170,7 +170,7 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
170170
# maxpooling reduces this further to (24/2,24/2) = (12,12)
171171
# 4D output tensor is thus of shape (batch_size,nkerns[0],12,12)
172172
layer0 = LeNetConvPoolLayer(
173-
rng,
173+
rng,
174174
input=layer0_input,
175175
image_shape=(batch_size, 1, 28, 28),
176176
filter_shape=(nkerns[0], 1, 5, 5),
@@ -182,10 +182,10 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
182182
# maxpooling reduces this further to (8/2,8/2) = (4,4)
183183
# 4D output tensor is thus of shape (nkerns[0],nkerns[1],4,4)
184184
layer1 = LeNetConvPoolLayer(
185-
rng,
185+
rng,
186186
input=layer0.output,
187187
image_shape=(batch_size, nkerns[0], 12, 12),
188-
filter_shape=(nkerns[1], nkerns[0], 5, 5),
188+
filter_shape=(nkerns[1], nkerns[0], 5, 5),
189189
poolsize=(2, 2)
190190
)
191191

@@ -196,10 +196,10 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
196196

197197
# construct a fully-connected sigmoidal layer
198198
layer2 = HiddenLayer(
199-
rng,
200-
input=layer2_input,
199+
rng,
200+
input=layer2_input,
201201
n_in=nkerns[1] * 4 * 4,
202-
n_out=500,
202+
n_out=500,
203203
activation=T.tanh
204204
)
205205

@@ -211,20 +211,20 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
211211

212212
# create a function to compute the mistakes that are made by the model
213213
test_model = theano.function(
214-
[index],
214+
[index],
215215
layer3.errors(y),
216216
givens={
217-
x: test_set_x[index * batch_size : (index + 1) * batch_size],
218-
y: test_set_y[index * batch_size : (index + 1) * batch_size]
217+
x: test_set_x[index * batch_size: (index + 1) * batch_size],
218+
y: test_set_y[index * batch_size: (index + 1) * batch_size]
219219
}
220220
)
221221

222222
validate_model = theano.function(
223-
[index],
223+
[index],
224224
layer3.errors(y),
225225
givens={
226-
x: valid_set_x[index * batch_size : (index + 1) * batch_size],
227-
y: valid_set_y[index * batch_size : (index + 1) * batch_size]
226+
x: valid_set_x[index * batch_size: (index + 1) * batch_size],
227+
y: valid_set_y[index * batch_size: (index + 1) * batch_size]
228228
}
229229
)
230230

@@ -245,12 +245,12 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
245245
]
246246

247247
train_model = theano.function(
248-
[index],
249-
cost,
248+
[index],
249+
cost,
250250
updates=updates,
251251
givens={
252-
x: train_set_x[index * batch_size : (index + 1) * batch_size],
253-
y: train_set_y[index * batch_size : (index + 1) * batch_size]
252+
x: train_set_x[index * batch_size: (index + 1) * batch_size],
253+
y: train_set_y[index * batch_size: (index + 1) * batch_size]
254254
}
255255
)
256256

@@ -312,10 +312,13 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
312312
best_iter = iter
313313

314314
# test it on the test set
315-
test_losses = [test_model(i) for i in xrange(n_test_batches)]
315+
test_losses = [
316+
test_model(i)
317+
for i in xrange(n_test_batches)
318+
]
316319
test_score = numpy.mean(test_losses)
317-
print((' epoch %i, minibatch %i/%i, test error of best '
318-
'model %f %%') %
320+
print((' epoch %i, minibatch %i/%i, test error of '
321+
'best model %f %%') %
319322
(epoch, minibatch_index + 1, n_train_batches,
320323
test_score * 100.))
321324

code/dA.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ class dA(object):
7676
"""
7777

7878
def __init__(
79-
self,
80-
numpy_rng,
81-
theano_rng=None,
79+
self,
80+
numpy_rng,
81+
theano_rng=None,
8282
input=None,
83-
n_visible=784,
83+
n_visible=784,
8484
n_hidden=500,
85-
W=None,
86-
bhid=None,
85+
W=None,
86+
bhid=None,
8787
bvis=None
8888
):
8989
"""
@@ -287,10 +287,10 @@ 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,
290+
numpy_rng=rng,
291+
theano_rng=theano_rng,
292292
input=x,
293-
n_visible=28 * 28,
293+
n_visible=28 * 28,
294294
n_hidden=500
295295
)
296296

@@ -300,11 +300,11 @@ def test_dA(learning_rate=0.1, training_epochs=15,
300300
)
301301

302302
train_da = theano.function(
303-
[index],
304-
cost,
303+
[index],
304+
cost,
305305
updates=updates,
306306
givens={
307-
x: train_set_x[index * batch_size : (index + 1) * batch_size]
307+
x: train_set_x[index * batch_size: (index + 1) * batch_size]
308308
}
309309
)
310310

@@ -344,10 +344,10 @@ 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,
347+
numpy_rng=rng,
348+
theano_rng=theano_rng,
349349
input=x,
350-
n_visible=28 * 28,
350+
n_visible=28 * 28,
351351
n_hidden=500
352352
)
353353

code/logistic_sgd.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, input, n_in, n_out):
7979
(n_in, n_out),
8080
dtype=theano.config.floatX
8181
),
82-
name='W',
82+
name='W',
8383
borrow=True
8484
)
8585
# initialize the baises b as a vector of n_out 0s
@@ -88,19 +88,22 @@ def __init__(self, input, n_in, n_out):
8888
(n_out,),
8989
dtype=theano.config.floatX
9090
),
91-
name='b',
91+
name='b',
9292
borrow=True
9393
)
9494

95-
# symbolic expression for computing the matrix of class-membership probabilities
95+
# symbolic expression for computing the matrix of class-membership
96+
# probabilities
9697
# Where:
97-
# W is a matrix where column-k represent the separation hyper plain for class-k
98+
# W is a matrix where column-k represent the separation hyper plain for
99+
# class-k
98100
# x is a matrix where row-j represents input training sample-j
99-
# b is a vector where element-k represent the free parameter of hyper plain-k
101+
# b is a vector where element-k represent the free parameter of hyper
102+
# plain-k
100103
self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)
101104

102-
# symbolic description of how to compute prediction as class whose probability
103-
# is maximal
105+
# symbolic description of how to compute prediction as class whose
106+
# probability is maximal
104107
self.y_pred = T.argmax(self.p_y_given_x, axis=1)
105108

106109
# parameters of the model
@@ -173,13 +176,20 @@ def load_data(dataset):
173176
data_dir, data_file = os.path.split(dataset)
174177
if data_dir == "" and not os.path.isfile(dataset):
175178
# Check if dataset is in the data directory.
176-
new_path = os.path.join(os.path.split(__file__)[0], "..", "data", dataset)
179+
new_path = os.path.join(
180+
os.path.split(__file__)[0],
181+
"..",
182+
"data",
183+
dataset
184+
)
177185
if os.path.isfile(new_path) or data_file == 'mnist.pkl.gz':
178186
dataset = new_path
179187

180188
if (not os.path.isfile(dataset)) and data_file == 'mnist.pkl.gz':
181189
import urllib
182-
origin = 'http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz'
190+
origin = (
191+
'http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz'
192+
)
183193
print 'Downloading data from %s' % origin
184194
urllib.urlretrieve(origin, dataset)
185195

@@ -289,17 +299,17 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
289299
inputs=[index],
290300
outputs=classifier.errors(y),
291301
givens={
292-
x: test_set_x[index * batch_size : (index + 1) * batch_size],
293-
y: test_set_y[index * batch_size : (index + 1) * batch_size]
302+
x: test_set_x[index * batch_size: (index + 1) * batch_size],
303+
y: test_set_y[index * batch_size: (index + 1) * batch_size]
294304
}
295305
)
296306

297307
validate_model = theano.function(
298308
inputs=[index],
299309
outputs=classifier.errors(y),
300310
givens={
301-
x: valid_set_x[index * batch_size : (index + 1) * batch_size],
302-
y: valid_set_y[index * batch_size : (index + 1) * batch_size]
311+
x: valid_set_x[index * batch_size: (index + 1) * batch_size],
312+
y: valid_set_y[index * batch_size: (index + 1) * batch_size]
303313
}
304314
)
305315

@@ -320,8 +330,8 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
320330
outputs=cost,
321331
updates=updates,
322332
givens={
323-
x: train_set_x[index * batch_size : (index + 1) * batch_size],
324-
y: train_set_y[index * batch_size : (index + 1) * batch_size]
333+
x: train_set_x[index * batch_size: (index + 1) * batch_size],
334+
y: train_set_y[index * batch_size: (index + 1) * batch_size]
325335
}
326336
)
327337

0 commit comments

Comments
 (0)