Mercurial > pylearn
comparison pylearn/algorithms/mcRBM.py @ 1395:54b2268db0d7
mcRBM.contrastive_grad accepts optional "consider_constant" arg
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Sat, 08 Jan 2011 17:14:44 -0500 |
parents | 6402b3309ece |
children | f82b80c841b2 |
comparison
equal
deleted
inserted
replaced
1394:48e8292e22e7 | 1395:54b2268db0d7 |
---|---|
263 :math: \sum_i free_energy(pos_v[i]) - free_energy(neg_v[i]) | 263 :math: \sum_i free_energy(pos_v[i]) - free_energy(neg_v[i]) |
264 | 264 |
265 """ | 265 """ |
266 return (free_energy_fn(pos_v) - free_energy_fn(neg_v)).sum() | 266 return (free_energy_fn(pos_v) - free_energy_fn(neg_v)).sum() |
267 | 267 |
268 def contrastive_grad(free_energy_fn, pos_v, neg_v, wrt, other_cost=0): | 268 def contrastive_grad(free_energy_fn, pos_v, neg_v, wrt, other_cost=0, consider_constant=[]): |
269 """ | 269 """ |
270 :param free_energy_fn: lambda (TensorType matrix MxN) -> TensorType vector of M free energies | 270 :param free_energy_fn: lambda (TensorType matrix MxN) -> TensorType vector of M free energies |
271 :param pos_v: positive-phase sample of visible units | 271 :param pos_v: positive-phase sample of visible units |
272 :param neg_v: negative-phase sample of visible units | 272 :param neg_v: negative-phase sample of visible units |
273 :param wrt: TensorType variables with respect to which we want gradients (similar to the | 273 :param wrt: TensorType variables with respect to which we want gradients (similar to the |
297 cost=contrastive_cost(free_energy_fn, pos_v, neg_v) | 297 cost=contrastive_cost(free_energy_fn, pos_v, neg_v) |
298 if other_cost: | 298 if other_cost: |
299 cost = cost + other_cost | 299 cost = cost + other_cost |
300 return theano.tensor.grad(cost, | 300 return theano.tensor.grad(cost, |
301 wrt=wrt, | 301 wrt=wrt, |
302 consider_constant=[neg_v]) | 302 consider_constant=consider_constant+[neg_v]) |
303 | 303 |
304 ########################################### | 304 ########################################### |
305 # | 305 # |
306 # Expressions that are mcRBM-specific | 306 # Expressions that are mcRBM-specific |
307 # | 307 # |