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

Method get_cost_updates

code/cA.py:196–228  ·  view source on GitHub ↗

This function computes the cost and the updates for one trainng step of the cA

(self, contraction_level, learning_rate)

Source from the content-addressed store, hash-verified

194 return T.nnet.sigmoid(T.dot(hidden, self.W_prime) + self.b_prime)
195
196 def get_cost_updates(self, contraction_level, learning_rate):
197 """ This function computes the cost and the updates for one trainng
198 step of the cA """
199
200 y = self.get_hidden_values(self.x)
201 z = self.get_reconstructed_input(y)
202 J = self.get_jacobian(y, self.W)
203 # note : we sum over the size of a datapoint; if we are using
204 # minibatches, L will be a vector, with one entry per
205 # example in minibatch
206 self.L_rec = - T.sum(self.x * T.log(z) +
207 (1 - self.x) * T.log(1 - z),
208 axis=1)
209
210 # Compute the jacobian and average over the number of samples/minibatch
211 self.L_jacob = T.sum(J ** 2) // self.n_batchsize
212
213 # note : L is now a vector, where each element is the
214 # cross-entropy cost of the reconstruction of the
215 # corresponding example of the minibatch. We need to
216 # compute the average of all these to get the cost of
217 # the minibatch
218 cost = T.mean(self.L_rec) + contraction_level * T.mean(self.L_jacob)
219
220 # compute the gradients of the cost of the `cA` with respect
221 # to its parameters
222 gparams = T.grad(cost, self.params)
223 # generate the list of updates
224 updates = []
225 for param, gparam in zip(self.params, gparams):
226 updates.append((param, param - learning_rate * gparam))
227
228 return (cost, updates)
229
230
231def test_cA(learning_rate=0.01, training_epochs=20,

Callers 1

test_cAFunction · 0.45

Calls 3

get_hidden_valuesMethod · 0.95
get_jacobianMethod · 0.95

Tested by 1

test_cAFunction · 0.36