GeezerVison is showing github.com — got rid of all the xrange · ooitomato/DeepLearningTutorials@4c0858d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: code/DBN.py +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,7 +75,7 @@ def __init__(self, numpy_rng, theano_rng=None, n_ins=784, | 75 | 75 | # training the DBN by doing stochastic gradient descent on the | 76 | 76 | # MLP. | 77 | 77 |
| 78 | | - for i in xrange(self.n_layers): | | 78 | + for i in range(self.n_layers): | 79 | 79 | # construct the sigmoidal layer | 80 | 80 |
| 81 | 81 | # the size of the input is either the number of hidden | @@ -267,11 +267,11 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate): | 267 | 267 |
| 268 | 268 | # Create a function that scans the entire validation set | 269 | 269 | def valid_score(): | 270 | | - return [valid_score_i(i) for i in xrange(n_valid_batches)] | | 270 | + return [valid_score_i(i) for i in range(n_valid_batches)] | 271 | 271 |
| 272 | 272 | # Create a function that scans the entire test set | 273 | 273 | def test_score(): | 274 | | - return [test_score_i(i) for i in xrange(n_test_batches)] | | 274 | + return [test_score_i(i) for i in range(n_test_batches)] | 275 | 275 |
| 276 | 276 | return train_fn, valid_score, test_score | 277 | 277 |
| @@ -329,12 +329,12 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100, | 329 | 329 | print '... pre-training the model' | 330 | 330 | start_time = timeit.default_timer() | 331 | 331 | ## Pre-train layer-wise | 332 | | - for i in xrange(dbn.n_layers): | | 332 | + for i in range(dbn.n_layers): | 333 | 333 | # go through pretraining epochs | 334 | | - for epoch in xrange(pretraining_epochs): | | 334 | + for epoch in range(pretraining_epochs): | 335 | 335 | # go through the training set | 336 | 336 | c = [] | 337 | | - for batch_index in xrange(n_train_batches): | | 337 | + for batch_index in range(n_train_batches): | 338 | 338 | c.append(pretraining_fns[i](index=batch_index, | 339 | 339 | lr=pretrain_lr)) | 340 | 340 | print 'Pre-training layer %i, epoch %d, cost ' % (i, epoch), | @@ -379,7 +379,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100, | 379 | 379 |
| 380 | 380 | while (epoch < training_epochs) and (not done_looping): | 381 | 381 | epoch = epoch + 1 | 382 | | - for minibatch_index in xrange(n_train_batches): | | 382 | + for minibatch_index in range(n_train_batches): | 383 | 383 |
| 384 | 384 | minibatch_avg_cost = train_fn(minibatch_index) | 385 | 385 | iter = (epoch - 1) * n_train_batches + minibatch_index | |
Collapse file Copy file name to clipboardExpand all lines: code/cA.py +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | """ | 31 | 31 |
| 32 | 32 | from __future__ import print_function | 33 | | -from six.moves import xrange | 34 | 33 |
| 35 | 34 | import os | 36 | 35 | import sys | @@ -287,10 +286,10 @@ def test_cA(learning_rate=0.01, training_epochs=20, | 287 | 286 | ############ | 288 | 287 |
| 289 | 288 | # go through training epochs | 290 | | - for epoch in xrange(training_epochs): | | 289 | + for epoch in range(training_epochs): | 291 | 290 | # go through trainng set | 292 | 291 | c = [] | 293 | | - for batch_index in xrange(n_train_batches): | | 292 | + for batch_index in range(n_train_batches): | 294 | 293 | c.append(train_ca(batch_index)) | 295 | 294 |
| 296 | 295 | c_array = numpy.vstack(c) | |
Collapse file Copy file name to clipboardExpand all lines: code/hmc/test_hmc.py +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 |
| 2 | 2 | from __future__ import print_function | 3 | | -from six.moves import xrange | 4 | 3 |
| 5 | 4 | import numpy | 6 | 5 | import theano | @@ -39,10 +38,10 @@ def gaussian_energy(x): | 39 | 38 | initial_stepsize=1e-3, stepsize_max=0.5) | 40 | 39 |
| 41 | 40 | # Start with a burn-in process | 42 | | - garbage = [sampler.draw() for r in xrange(burnin)] # burn-in Draw | | 41 | + garbage = [sampler.draw() for r in range(burnin)] # burn-in Draw | 43 | 42 | # `n_samples`: result is a 3D tensor of dim [n_samples, batchsize, | 44 | 43 | # dim] | 45 | | - _samples = numpy.asarray([sampler.draw() for r in xrange(n_samples)]) | | 44 | + _samples = numpy.asarray([sampler.draw() for r in range(n_samples)]) | 46 | 45 | # Flatten to [n_samples * batchsize, dim] | 47 | 46 | samples = _samples.T.reshape(dim, -1).T | 48 | 47 |
| |
Collapse file Copy file name to clipboardExpand all lines: code/logistic_cg.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -239,15 +239,15 @@ def cg_optimization_mnist(n_epochs=50, mnist_pkl_gz='mnist.pkl.gz'): | 239 | 239 | def train_fn(theta_value): | 240 | 240 | classifier.theta.set_value(theta_value, borrow=True) | 241 | 241 | train_losses = [batch_cost(i * batch_size) | 242 | | - for i in xrange(n_train_batches)] | | 242 | + for i in range(n_train_batches)] | 243 | 243 | return numpy.mean(train_losses) | 244 | 244 |
| 245 | 245 | # creates a function that computes the average gradient of cost with | 246 | 246 | # respect to theta | 247 | 247 | def train_fn_grad(theta_value): | 248 | 248 | classifier.theta.set_value(theta_value, borrow=True) | 249 | 249 | grad = batch_grad(0) | 250 | | - for i in xrange(1, n_train_batches): | | 250 | + for i in range(1, n_train_batches): | 251 | 251 | grad += batch_grad(i * batch_size) | 252 | 252 | return grad / n_train_batches | 253 | 253 |
| @@ -258,7 +258,7 @@ def callback(theta_value): | 258 | 258 | classifier.theta.set_value(theta_value, borrow=True) | 259 | 259 | #compute the validation loss | 260 | 260 | validation_losses = [validate_model(i * batch_size) | 261 | | - for i in xrange(n_valid_batches)] | | 261 | + for i in range(n_valid_batches)] | 262 | 262 | this_validation_loss = numpy.mean(validation_losses) | 263 | 263 | print('validation error %f %%' % (this_validation_loss * 100.,)) | 264 | 264 |
| @@ -268,7 +268,7 @@ def callback(theta_value): | 268 | 268 | # testing dataset | 269 | 269 | validation_scores[0] = this_validation_loss | 270 | 270 | test_losses = [test_model(i * batch_size) | 271 | | - for i in xrange(n_test_batches)] | | 271 | + for i in range(n_test_batches)] | 272 | 272 | validation_scores[1] = numpy.mean(test_losses) | 273 | 273 |
| 274 | 274 | ############### | |
Collapse file Copy file name to clipboardExpand all lines: code/lstm.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | ''' | 4 | 4 |
| 5 | 5 | from __future__ import print_function | 6 | | -from six.moves import xrange | 7 | 6 | import six.moves.cPickle as pickle | 8 | 7 |
| 9 | 8 | from collections import OrderedDict | @@ -549,7 +548,7 @@ def train_lstm( | 549 | 548 | estop = False # early stop | 550 | 549 | start_time = time.time() | 551 | 550 | try: | 552 | | - for eidx in xrange(max_epochs): | | 551 | + for eidx in range(max_epochs): | 553 | 552 | n_samples = 0 | 554 | 553 |
| 555 | 554 | # Get new shuffled index for the training set. | |
Collapse file Copy file name to clipboardExpand all lines: code/rbm.py +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | """ | 7 | 7 |
| 8 | 8 | from __future__ import print_function | 9 | | -from six.moves import xrange | 10 | 9 |
| 11 | 10 | import timeit | 12 | 11 |
| @@ -435,11 +434,11 @@ def test_rbm(learning_rate=0.1, training_epochs=15, | 435 | 434 | start_time = timeit.default_timer() | 436 | 435 |
| 437 | 436 | # go through training epochs | 438 | | - for epoch in xrange(training_epochs): | | 437 | + for epoch in range(training_epochs): | 439 | 438 |
| 440 | 439 | # go through the training set | 441 | 440 | mean_cost = [] | 442 | | - for batch_index in xrange(n_train_batches): | | 441 | + for batch_index in range(n_train_batches): | 443 | 442 | mean_cost += [train_rbm(batch_index)] | 444 | 443 |
| 445 | 444 | print('Training epoch %d, cost is ' % epoch, numpy.mean(mean_cost)) | @@ -522,7 +521,7 @@ def test_rbm(learning_rate=0.1, training_epochs=15, | 522 | 521 | (29 * n_samples + 1, 29 * n_chains - 1), | 523 | 522 | dtype='uint8' | 524 | 523 | ) | 525 | | - for idx in xrange(n_samples): | | 524 | + for idx in range(n_samples): | 526 | 525 | # generate `plot_every` intermediate samples that we discard, | 527 | 526 | # because successive samples in the chain are too correlated | 528 | 527 | vis_mf, vis_sample = sample_fn() | |
Collapse file Copy file name to clipboardExpand all lines: code/rnnrbm.py +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | # More information at http://deeplearning.net/tutorial/rnnrbm.html | 5 | 5 |
| 6 | 6 | from __future__ import print_function | 7 | | -from six.moves import xrange | 8 | 7 |
| 9 | 8 | import glob | 10 | 9 | import os | @@ -249,12 +248,12 @@ def train(self, files, batch_size=100, num_epochs=200): | 249 | 248 | for f in files] | 250 | 249 |
| 251 | 250 | try: | 252 | | - for epoch in xrange(num_epochs): | | 251 | + for epoch in range(num_epochs): | 253 | 252 | numpy.random.shuffle(dataset) | 254 | 253 | costs = [] | 255 | 254 |
| 256 | 255 | for s, sequence in enumerate(dataset): | 257 | | - for i in xrange(0, len(sequence), batch_size): | | 256 | + for i in range(0, len(sequence), batch_size): | 258 | 257 | cost = self.train_function(sequence[i:i + batch_size]) | 259 | 258 | costs.append(cost) | 260 | 259 |
| |
Collapse file Copy file name to clipboardExpand all lines: code/rnnslu.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 |
| 2 | 2 | from __future__ import print_function | 3 | | -from six.moves import xrange | 4 | 3 | import six.moves.cPickle as pickle | 5 | 4 |
| 6 | 5 | from collections import OrderedDict | @@ -322,7 +321,7 @@ def main(param=None): | 322 | 321 | # train with early stopping on validation set | 323 | 322 | best_f1 = -numpy.inf | 324 | 323 | param['clr'] = param['lr'] | 325 | | - for e in xrange(param['nepochs']): | | 324 | + for e in range(param['nepochs']): | 326 | 325 |
| 327 | 326 | # shuffle | 328 | 327 | shuffle([train_lex, train_ne, train_y], param['seed']) | |
Collapse file Copy file name to clipboardExpand all lines: code/utils.py +3-5Lines changed: 3 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | image from a set of samples or weights. | 7 | 7 | """ | 8 | 8 |
| 9 | | - | 10 | | -from six.moves import xrange | 11 | 9 | import numpy | 12 | 10 |
| 13 | 11 |
| @@ -86,7 +84,7 @@ def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0), | 86 | 84 | else: | 87 | 85 | channel_defaults = [0., 0., 0., 1.] | 88 | 86 |
| 89 | | - for i in xrange(4): | | 87 | + for i in range(4): | 90 | 88 | if X[i] is None: | 91 | 89 | # if channel is None, fill it with zeros of the correct | 92 | 90 | # dtype | @@ -116,8 +114,8 @@ def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0), | 116 | 114 | dt = 'uint8' | 117 | 115 | out_array = numpy.zeros(out_shape, dtype=dt) | 118 | 116 |
| 119 | | - for tile_row in xrange(tile_shape[0]): | 120 | | - for tile_col in xrange(tile_shape[1]): | | 117 | + for tile_row in range(tile_shape[0]): | | 118 | + for tile_col in range(tile_shape[1]): | 121 | 119 | if tile_row * tile_shape[1] + tile_col < X.shape[0]: | 122 | 120 | this_x = X[tile_row * tile_shape[1] + tile_col] | 123 | 121 | if scale_rows_to_unit_interval: | |
Collapse file Copy file name to clipboardExpand all lines: doc/gettingstarted.txt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -578,7 +578,7 @@ of a strategy based on a geometrically increasing amount of patience. | 578 | 578 | while (epoch < n_epochs) and (not done_looping): | 579 | 579 | # Report "1" for first epoch, "n_epochs" for last epoch | 580 | 580 | epoch = epoch + 1 | 581 | | - for minibatch_index in xrange(n_train_batches): | | 581 | + for minibatch_index in range(n_train_batches): | 582 | 582 |
| 583 | 583 | d_loss_wrt_params = ... # compute gradient | 584 | 584 | params -= learning_rate * d_loss_wrt_params # gradient descent | |
|