MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / pretraining_functions

Method pretraining_functions

code/DBN.py:143–189  ·  view source on GitHub ↗

Generates a list of functions, for performing one step of gradient descent at a given layer. The function will require as input the minibatch index, and to train an RBM you just need to iterate, calling the corresponding function on all minibatch indexes. :ty

(self, train_set_x, batch_size, k)

Source from the content-addressed store, hash-verified

141 self.errors = self.logLayer.errors(self.y)
142
143 def pretraining_functions(self, train_set_x, batch_size, k):
144 '''Generates a list of functions, for performing one step of
145 gradient descent at a given layer. The function will require
146 as input the minibatch index, and to train an RBM you just
147 need to iterate, calling the corresponding function on all
148 minibatch indexes.
149
150 :type train_set_x: theano.tensor.TensorType
151 :param train_set_x: Shared var. that contains all datapoints used
152 for training the RBM
153 :type batch_size: int
154 :param batch_size: size of a [mini]batch
155 :param k: number of Gibbs steps to do in CD-k / PCD-k
156
157 '''
158
159 # index to a [mini]batch
160 index = T.lscalar('index') # index to a minibatch
161 learning_rate = T.scalar('lr') # learning rate to use
162
163 # begining of a batch, given `index`
164 batch_begin = index * batch_size
165 # ending of a batch given `index`
166 batch_end = batch_begin + batch_size
167
168 pretrain_fns = []
169 for rbm in self.rbm_layers:
170
171 # get the cost and the updates list
172 # using CD-k here (persisent=None) for training each RBM.
173 # TODO: change cost function to reconstruction error
174 cost, updates = rbm.get_cost_updates(learning_rate,
175 persistent=None, k=k)
176
177 # compile the theano function
178 fn = theano.function(
179 inputs=[index, theano.In(learning_rate, value=0.1)],
180 outputs=cost,
181 updates=updates,
182 givens={
183 self.x: train_set_x[batch_begin:batch_end]
184 }
185 )
186 # append `fn` to the list of functions
187 pretrain_fns.append(fn)
188
189 return pretrain_fns
190
191 def build_finetune_functions(self, datasets, batch_size, learning_rate):
192 '''Generates a function `train` that implements one step of

Callers 1

test_DBNFunction · 0.95

Calls 1

get_cost_updatesMethod · 0.45

Tested by 1

test_DBNFunction · 0.76