annotate deep/autoencoder/DA_training.py @ 333:69109e41983e

Adapt parameters (especially the number of epochs) to P07
author Arnaud Bergeron <abergeron@gmail.com>
date Wed, 14 Apr 2010 16:06:04 -0400
parents e12702b88a2d
children
rev   line source
190
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
1 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
2 This tutorial introduces stacked denoising auto-encoders (SdA) using Theano.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
3
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
4 Denoising autoencoders are the building blocks for SDAE.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
5 They are based on auto-encoders as the ones used in Bengio et al. 2007.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
6 An autoencoder takes an input x and first maps it to a hidden representation
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
7 y = f_{\theta}(x) = s(Wx+b), parameterized by \theta={W,b}. The resulting
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
8 latent representation y is then mapped back to a "reconstructed" vector
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
9 z \in [0,1]^d in input space z = g_{\theta'}(y) = s(W'y + b'). The weight
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
10 matrix W' can optionally be constrained such that W' = W^T, in which case
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
11 the autoencoder is said to have tied weights. The network is trained such
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
12 that to minimize the reconstruction error (the error between x and z).
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
13
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
14 For the denosing autoencoder, during training, first x is corrupted into
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
15 \tilde{x}, where \tilde{x} is a partially destroyed version of x by means
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
16 of a stochastic mapping. Afterwards y is computed as before (using
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
17 \tilde{x}), y = s(W\tilde{x} + b) and z as s(W'y + b'). The reconstruction
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
18 error is now measured between z and the uncorrupted input x, which is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
19 computed as the cross-entropy :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
20 - \sum_{k=1}^d[ x_k \log z_k + (1-x_k) \log( 1-z_k)]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
21
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
22 For X iteration of the main program loop it takes *** minutes on an
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
23 Intel Core i7 and *** minutes on GPU (NVIDIA GTX 285 graphics processor).
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
24
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
25
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
26 References :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
27 - P. Vincent, H. Larochelle, Y. Bengio, P.A. Manzagol: Extracting and
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
28 Composing Robust Features with Denoising Autoencoders, ICML'08, 1096-1103,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
29 2008
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
30 - Y. Bengio, P. Lamblin, D. Popovici, H. Larochelle: Greedy Layer-Wise
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
31 Training of Deep Networks, Advances in Neural Information Processing
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
32 Systems 19, 2007
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
33
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
34 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
35
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
36 import numpy
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
37 import theano
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
38 import time
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
39 import theano.tensor as T
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
40 from theano.tensor.shared_randomstreams import RandomStreams
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
41
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
42 import gzip
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
43 import cPickle
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
44
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
45 from pylearn.io import filetensor as ft
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
46
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
47 class dA():
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
48 """Denoising Auto-Encoder class (dA)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
49
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
50 A denoising autoencoders tries to reconstruct the input from a corrupted
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
51 version of it by projecting it first in a latent space and reprojecting
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
52 it afterwards back in the input space. Please refer to Vincent et al.,2008
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
53 for more details. If x is the input then equation (1) computes a partially
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
54 destroyed version of x by means of a stochastic mapping q_D. Equation (2)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
55 computes the projection of the input into the latent space. Equation (3)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
56 computes the reconstruction of the input, while equation (4) computes the
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
57 reconstruction error.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
58
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
59 .. math::
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
60
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
61 \tilde{x} ~ q_D(\tilde{x}|x) (1)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
62
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
63 y = s(W \tilde{x} + b) (2)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
64
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
65 z = s(W' y + b') (3)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
66
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
67 L(x,z) = -sum_{k=1}^d [x_k \log z_k + (1-x_k) \log( 1-z_k)] (4)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
68
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
69 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
70
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
71 def __init__(self, n_visible= 784, n_hidden= 500, complexity = 0.1, input= None):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
72 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
73 Initialize the DAE class by specifying the number of visible units (the
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
74 dimension d of the input ), the number of hidden units ( the dimension
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
75 d' of the latent or hidden space ) and by giving a symbolic variable
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
76 for the input. Such a symbolic variable is useful when the input is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
77 the result of some computations. For example when dealing with SDAEs,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
78 the dA on layer 2 gets as input the output of the DAE on layer 1.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
79 This output can be written as a function of the input to the entire
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
80 model, and as such can be computed by theano whenever needed.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
81
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
82 :param n_visible: number of visible units
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
83
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
84 :param n_hidden: number of hidden units
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
85
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
86 :param input: a symbolic description of the input or None
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
87
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
88 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
89 self.n_visible = n_visible
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
90 self.n_hidden = n_hidden
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
91
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
92 # create a Theano random generator that gives symbolic random values
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
93 theano_rng = RandomStreams()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
94 # create a numpy random generator
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
95 numpy_rng = numpy.random.RandomState()
206
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
96
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
97 # print the parameter of the DA
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
98 if True :
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
99 print 'input size = %d' %n_visible
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
100 print 'hidden size = %d' %n_hidden
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
101 print 'complexity = %2.2f' %complexity
190
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
102
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
103 # initial values for weights and biases
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
104 # note : W' was written as `W_prime` and b' as `b_prime`
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
105
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
106 # W is initialized with `initial_W` which is uniformely sampled
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
107 # from -6./sqrt(n_visible+n_hidden) and 6./sqrt(n_hidden+n_visible)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
108 # the output of uniform if converted using asarray to dtype
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
109 # theano.config.floatX so that the code is runable on GPU
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
110 initial_W = numpy.asarray( numpy.random.uniform( \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
111 low = -numpy.sqrt(6./(n_visible+n_hidden)), \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
112 high = numpy.sqrt(6./(n_visible+n_hidden)), \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
113 size = (n_visible, n_hidden)), dtype = theano.config.floatX)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
114 initial_b = numpy.zeros(n_hidden)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
115
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
116 # W' is initialized with `initial_W_prime` which is uniformely sampled
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
117 # from -6./sqrt(n_visible+n_hidden) and 6./sqrt(n_hidden+n_visible)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
118 # the output of uniform if converted using asarray to dtype
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
119 # theano.config.floatX so that the code is runable on GPU
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
120 initial_b_prime= numpy.zeros(n_visible)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
121
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
122
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
123 # theano shared variables for weights and biases
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
124 self.W = theano.shared(value = initial_W, name = "W")
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
125 self.b = theano.shared(value = initial_b, name = "b")
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
126 # tied weights, therefore W_prime is W transpose
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
127 self.W_prime = self.W.T
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
128 self.b_prime = theano.shared(value = initial_b_prime, name = "b'")
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
129
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
130 # if no input is given, generate a variable representing the input
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
131 if input == None :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
132 # we use a matrix because we expect a minibatch of several examples,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
133 # each example being a row
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
134 x = T.dmatrix(name = 'input')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
135 else:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
136 x = input
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
137 # Equation (1)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
138 # note : first argument of theano.rng.binomial is the shape(size) of
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
139 # random numbers that it should produce
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
140 # second argument is the number of trials
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
141 # third argument is the probability of success of any trial
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
142 #
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
143 # this will produce an array of 0s and 1s where 1 has a
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
144 # probability of 0.9 and 0 of 0.1
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
145
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
146 tilde_x = theano_rng.binomial( x.shape, 1, 1-complexity) * x
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
147 # Equation (2)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
148 # note : y is stored as an attribute of the class so that it can be
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
149 # used later when stacking dAs.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
150 self.y = T.nnet.sigmoid(T.dot(tilde_x, self.W ) + self.b)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
151 # Equation (3)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
152 z = T.nnet.sigmoid(T.dot(self.y, self.W_prime) + self.b_prime)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
153 # Equation (4)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
154 self.L = - T.sum( x*T.log(z) + (1-x)*T.log(1-z), axis=1 )
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
155 # note : L is now a vector, where each element is the cross-entropy cost
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
156 # of the reconstruction of the corresponding example of the
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
157 # minibatch. We need to compute the average of all these to get
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
158 # the cost of the minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
159 self.cost = T.mean(self.L)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
160 # note : y is computed from the corrupted `tilde_x`. Later on,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
161 # we will need the hidden layer obtained from the uncorrupted
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
162 # input when for example we will pass this as input to the layer
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
163 # above
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
164 self.hidden_values = T.nnet.sigmoid( T.dot(x, self.W) + self.b)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
165
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
166
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
167
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
168 def sgd_optimization_nist( learning_rate=0.01, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
169 n_iter = 300, n_code_layer = 400, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
170 complexity = 0.1):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
171 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
172 Demonstrate stochastic gradient descent optimization for a denoising autoencoder
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
173
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
174 This is demonstrated on MNIST.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
175
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
176 :param learning_rate: learning rate used (factor for the stochastic
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
177 gradient
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
178
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
179 :param pretraining_epochs: number of epoch to do pretraining
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
180
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
181 :param pretrain_lr: learning rate to be used during pre-training
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
182
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
183 :param n_iter: maximal number of iterations ot run the optimizer
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
184
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
185 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
186 #open file to save the validation and test curve
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
187 filename = 'lr_' + str(learning_rate) + 'ni_' + str(n_iter) + 'nc_' + str(n_code_layer) + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
188 'c_' + str(complexity) + '.txt'
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
189
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
190 result_file = open(filename, 'w')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
191
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
192
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
193
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
194 data_path = '/data/lisa/data/nist/by_class/'
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
195 f = open(data_path+'all/all_train_data.ft')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
196 g = open(data_path+'all/all_train_labels.ft')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
197 h = open(data_path+'all/all_test_data.ft')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
198 i = open(data_path+'all/all_test_labels.ft')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
199
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
200 train_set_x = ft.read(f)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
201 train_set_y = ft.read(g)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
202 test_set_x = ft.read(h)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
203 test_set_y = ft.read(i)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
204
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
205 f.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
206 g.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
207 i.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
208 h.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
209
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
210 # make minibatches of size 20
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
211 batch_size = 20 # sized of the minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
212
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
213 #create a validation set the same size as the test size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
214 #use the end of the training array for this purpose
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
215 #discard the last remaining so we get a %batch_size number
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
216 test_size=len(test_set_y)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
217 test_size = int(test_size/batch_size)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
218 test_size*=batch_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
219 train_size = len(train_set_x)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
220 train_size = int(train_size/batch_size)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
221 train_size*=batch_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
222 validation_size =test_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
223 offset = train_size-test_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
224 if True:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
225 print 'train size = %d' %train_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
226 print 'test size = %d' %test_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
227 print 'valid size = %d' %validation_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
228 print 'offset = %d' %offset
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
229
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
230
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
231 #train_set = (train_set_x,train_set_y)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
232 train_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
233 for i in xrange(0, train_size-test_size, batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
234 train_batches = train_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
235 [(train_set_x[i:i+batch_size], train_set_y[i:i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
236
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
237 test_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
238 for i in xrange(0, test_size, batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
239 test_batches = test_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
240 [(test_set_x[i:i+batch_size], test_set_y[i:i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
241
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
242 valid_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
243 for i in xrange(0, test_size, batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
244 valid_batches = valid_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
245 [(train_set_x[offset+i:offset+i+batch_size], \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
246 train_set_y[offset+i:offset+i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
247
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
248
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
249 ishape = (32,32) # this is the size of NIST images
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
250
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
251 # allocate symbolic variables for the data
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
252 x = T.fmatrix() # the data is presented as rasterized images
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
253 y = T.lvector() # the labels are presented as 1D vector of
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
254 # [long int] labels
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
255
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
256 # construct the denoising autoencoder class
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
257 n_ins = 32*32
206
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
258 encoder = dA(n_ins, n_code_layer, complexity, input = x.reshape((batch_size,n_ins)))
190
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
259
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
260 # Train autoencoder
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
261
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
262 # compute gradients of the layer parameters
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
263 gW = T.grad(encoder.cost, encoder.W)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
264 gb = T.grad(encoder.cost, encoder.b)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
265 gb_prime = T.grad(encoder.cost, encoder.b_prime)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
266 # compute the updated value of the parameters after one step
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
267 updated_W = encoder.W - gW * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
268 updated_b = encoder.b - gb * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
269 updated_b_prime = encoder.b_prime - gb_prime * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
270
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
271 # defining the function that evaluate the symbolic description of
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
272 # one update step
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
273 train_model = theano.function([x], encoder.cost, updates=\
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
274 { encoder.W : updated_W, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
275 encoder.b : updated_b, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
276 encoder.b_prime : updated_b_prime } )
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
277
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
278
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
279
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
280
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
281 # compiling a theano function that computes the mistakes that are made
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
282 # by the model on a minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
283 test_model = theano.function([x], encoder.cost)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
284
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
285 normalize = numpy.asarray(255, dtype=theano.config.floatX)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
286
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
287
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
288 n_minibatches = len(train_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
289
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
290 # early-stopping parameters
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
291 patience = 10000000 / batch_size # look as this many examples regardless
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
292 patience_increase = 2 # wait this much longer when a new best is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
293 # found
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
294 improvement_threshold = 0.995 # a relative improvement of this much is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
295 # considered significant
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
296 validation_frequency = n_minibatches # go through this many
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
297 # minibatche before checking the network
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
298 # on the validation set; in this case we
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
299 # check every epoch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
300
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
301
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
302 best_params = None
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
303 best_validation_loss = float('inf')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
304 best_iter = 0
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
305 test_score = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
306 start_time = time.clock()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
307 # have a maximum of `n_iter` iterations through the entire dataset
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
308 for iter in xrange(n_iter* n_minibatches):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
309
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
310 # get epoch and minibatch index
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
311 epoch = iter / n_minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
312 minibatch_index = iter % n_minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
313
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
314 # get the minibatches corresponding to `iter` modulo
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
315 # `len(train_batches)`
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
316 x,y = train_batches[ minibatch_index ]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
317 '''
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
318 if iter == 0:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
319 b = numpy.asarray(255, dtype=theano.config.floatX)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
320 x = x / b
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
321 print x
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
322 print y
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
323 print x.__class__
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
324 print x.shape
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
325 print x.dtype.name
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
326 print y.dtype.name
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
327 print x.min(), x.max()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
328 '''
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
329
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
330 cost_ij = train_model(x/normalize)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
331
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
332 if (iter+1) % validation_frequency == 0:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
333 # compute zero-one loss on validation set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
334 this_validation_loss = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
335 for x,y in valid_batches:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
336 # sum up the errors for each minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
337 this_validation_loss += test_model(x/normalize)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
338 # get the average by dividing with the number of minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
339 this_validation_loss /= len(valid_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
340
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
341 print('epoch %i, minibatch %i/%i, validation error %f ' % \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
342 (epoch, minibatch_index+1, n_minibatches, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
343 this_validation_loss))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
344
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
345 # save value in file
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
346 result_file.write(str(epoch) + ' ' + str(this_validation_loss)+ '\n')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
347
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
348
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
349 # if we got the best validation score until now
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
350 if this_validation_loss < best_validation_loss:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
351
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
352 #improve patience if loss improvement is good enough
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
353 if this_validation_loss < best_validation_loss * \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
354 improvement_threshold :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
355 patience = max(patience, iter * patience_increase)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
356
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
357 best_validation_loss = this_validation_loss
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
358 best_iter = iter
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
359 # test it on the test set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
360
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
361 test_score = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
362 for x,y in test_batches:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
363 test_score += test_model(x/normalize)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
364 test_score /= len(test_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
365 print((' epoch %i, minibatch %i/%i, test error of best '
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
366 'model %f ') %
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
367 (epoch, minibatch_index+1, n_minibatches,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
368 test_score))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
369
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
370 if patience <= iter :
206
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
371 print('iter (%i) is superior than patience(%i). break', (iter, patience))
190
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
372 break
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
373
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
374
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
375
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
376 end_time = time.clock()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
377 print(('Optimization complete with best validation score of %f ,'
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
378 'with test performance %f ') %
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
379 (best_validation_loss, test_score))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
380 print ('The code ran for %f minutes' % ((end_time-start_time)/60.))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
381
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
382
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
383 result_file.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
384
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
385 return (best_validation_loss, test_score, (end_time-start_time)/60, best_iter)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
386
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
387 def sgd_optimization_mnist( learning_rate=0.01, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
388 n_iter = 1, n_code_layer = 400, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
389 complexity = 0.1):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
390 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
391 Demonstrate stochastic gradient descent optimization for a denoising autoencoder
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
392
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
393 This is demonstrated on MNIST.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
394
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
395 :param learning_rate: learning rate used (factor for the stochastic
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
396 gradient
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
397
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
398 :param pretraining_epochs: number of epoch to do pretraining
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
399
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
400 :param pretrain_lr: learning rate to be used during pre-training
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
401
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
402 :param n_iter: maximal number of iterations ot run the optimizer
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
403
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
404 """
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
405 #open file to save the validation and test curve
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
406 filename = 'lr_' + str(learning_rate) + 'ni_' + str(n_iter) + 'nc_' + str(n_code_layer) + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
407 'c_' + str(complexity) + '.txt'
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
408
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
409 result_file = open(filename, 'w')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
410
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
411 # Load the dataset
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
412 f = gzip.open('/u/lisa/HTML/deep/data/mnist/mnist.pkl.gz','rb')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
413 train_set, valid_set, test_set = cPickle.load(f)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
414 f.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
415
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
416 # make minibatches of size 20
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
417 batch_size = 20 # sized of the minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
418
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
419 # Dealing with the training set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
420 # get the list of training images (x) and their labels (y)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
421 (train_set_x, train_set_y) = train_set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
422 # initialize the list of training minibatches with empty list
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
423 train_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
424 for i in xrange(0, len(train_set_x), batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
425 # add to the list of minibatches the minibatch starting at
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
426 # position i, ending at position i+batch_size
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
427 # a minibatch is a pair ; the first element of the pair is a list
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
428 # of datapoints, the second element is the list of corresponding
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
429 # labels
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
430 train_batches = train_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
431 [(train_set_x[i:i+batch_size], train_set_y[i:i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
432
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
433 # Dealing with the validation set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
434 (valid_set_x, valid_set_y) = valid_set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
435 # initialize the list of validation minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
436 valid_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
437 for i in xrange(0, len(valid_set_x), batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
438 valid_batches = valid_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
439 [(valid_set_x[i:i+batch_size], valid_set_y[i:i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
440
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
441 # Dealing with the testing set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
442 (test_set_x, test_set_y) = test_set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
443 # initialize the list of testing minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
444 test_batches = []
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
445 for i in xrange(0, len(test_set_x), batch_size):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
446 test_batches = test_batches + \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
447 [(test_set_x[i:i+batch_size], test_set_y[i:i+batch_size])]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
448
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
449
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
450 ishape = (28,28) # this is the size of MNIST images
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
451
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
452 # allocate symbolic variables for the data
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
453 x = T.fmatrix() # the data is presented as rasterized images
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
454 y = T.lvector() # the labels are presented as 1D vector of
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
455 # [long int] labels
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
456
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
457 # construct the denoising autoencoder class
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
458 n_ins = 28*28
206
e12702b88a2d removed one bug: the complexity value was not sent to the dA class
youssouf
parents: 190
diff changeset
459 encoder = dA(n_ins, n_code_layer, complexity, input = x.reshape((batch_size,n_ins)))
190
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
460
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
461 # Train autoencoder
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
462
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
463 # compute gradients of the layer parameters
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
464 gW = T.grad(encoder.cost, encoder.W)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
465 gb = T.grad(encoder.cost, encoder.b)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
466 gb_prime = T.grad(encoder.cost, encoder.b_prime)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
467 # compute the updated value of the parameters after one step
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
468 updated_W = encoder.W - gW * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
469 updated_b = encoder.b - gb * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
470 updated_b_prime = encoder.b_prime - gb_prime * learning_rate
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
471
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
472 # defining the function that evaluate the symbolic description of
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
473 # one update step
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
474 train_model = theano.function([x], encoder.cost, updates=\
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
475 { encoder.W : updated_W, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
476 encoder.b : updated_b, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
477 encoder.b_prime : updated_b_prime } )
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
478
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
479
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
480
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
481
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
482 # compiling a theano function that computes the mistakes that are made
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
483 # by the model on a minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
484 test_model = theano.function([x], encoder.cost)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
485
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
486
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
487
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
488
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
489 n_minibatches = len(train_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
490
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
491 # early-stopping parameters
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
492 patience = 10000# look as this many examples regardless
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
493 patience_increase = 2 # wait this much longer when a new best is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
494 # found
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
495 improvement_threshold = 0.995 # a relative improvement of this much is
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
496 # considered significant
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
497 validation_frequency = n_minibatches # go through this many
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
498 # minibatche before checking the network
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
499 # on the validation set; in this case we
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
500 # check every epoch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
501
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
502
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
503 best_params = None
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
504 best_validation_loss = float('inf')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
505 best_iter = 0
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
506 test_score = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
507 start_time = time.clock()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
508 # have a maximum of `n_iter` iterations through the entire dataset
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
509 for iter in xrange(n_iter* n_minibatches):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
510
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
511 # get epoch and minibatch index
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
512 epoch = iter / n_minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
513 minibatch_index = iter % n_minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
514
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
515 # get the minibatches corresponding to `iter` modulo
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
516 # `len(train_batches)`
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
517 x,y = train_batches[ minibatch_index ]
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
518 cost_ij = train_model(x)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
519
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
520 if (iter+1) % validation_frequency == 0:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
521 # compute zero-one loss on validation set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
522 this_validation_loss = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
523 for x,y in valid_batches:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
524 # sum up the errors for each minibatch
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
525 this_validation_loss += test_model(x)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
526 # get the average by dividing with the number of minibatches
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
527 this_validation_loss /= len(valid_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
528
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
529 print('epoch %i, minibatch %i/%i, validation error %f ' % \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
530 (epoch, minibatch_index+1, n_minibatches, \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
531 this_validation_loss))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
532
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
533 # save value in file
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
534 result_file.write(str(epoch) + ' ' + str(this_validation_loss)+ '\n')
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
535
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
536
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
537 # if we got the best validation score until now
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
538 if this_validation_loss < best_validation_loss:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
539
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
540 #improve patience if loss improvement is good enough
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
541 if this_validation_loss < best_validation_loss * \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
542 improvement_threshold :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
543 patience = max(patience, iter * patience_increase)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
544
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
545 best_validation_loss = this_validation_loss
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
546 best_iter = iter
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
547 # test it on the test set
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
548
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
549 test_score = 0.
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
550 for x,y in test_batches:
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
551 test_score += test_model(x)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
552 test_score /= len(test_batches)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
553 print((' epoch %i, minibatch %i/%i, test error of best '
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
554 'model %f ') %
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
555 (epoch, minibatch_index+1, n_minibatches,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
556 test_score))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
557
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
558 if patience <= iter :
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
559 print('iter (%i) is superior than patience(%i). break', iter, patience)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
560 break
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
561
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
562
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
563 end_time = time.clock()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
564 print(('Optimization complete with best validation score of %f ,'
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
565 'with test performance %f ') %
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
566 (best_validation_loss, test_score))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
567 print ('The code ran for %f minutes' % ((end_time-start_time)/60.))
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
568
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
569
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
570 result_file.close()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
571
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
572 return (best_validation_loss, test_score, (end_time-start_time)/60, best_iter)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
573
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
574
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
575 def experiment(state,channel):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
576
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
577 (best_validation_loss, test_score, minutes_trained, iter) = \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
578 sgd_optimization_mnist(state.learning_rate, state.n_iter, state.n_code_layer,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
579 state.complexity)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
580
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
581 state.best_validation_loss = best_validation_loss
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
582 state.test_score = test_score
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
583 state.minutes_trained = minutes_trained
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
584 state.iter = iter
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
585
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
586 return channel.COMPLETE
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
587
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
588 def experiment_nist(state,channel):
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
589
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
590 (best_validation_loss, test_score, minutes_trained, iter) = \
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
591 sgd_optimization_nist(state.learning_rate, state.n_iter, state.n_code_layer,
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
592 state.complexity)
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
593
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
594 state.best_validation_loss = best_validation_loss
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
595 state.test_score = test_score
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
596 state.minutes_trained = minutes_trained
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
597 state.iter = iter
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
598
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
599 return channel.COMPLETE
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
600
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
601
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
602 if __name__ == '__main__':
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
603
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
604 sgd_optimization_nist()
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
605
70a9df1cd20e initial commit for autoencoder training
youssouf
parents:
diff changeset
606