Mercurial > pylearn
changeset 723:2881c67026c1
* when creating the sgd minimizer, the user can ask that step_cost compute other
outputs at the same same. This allows for example to compute the cost, at the
same time as the output class (more efficient)
author | desjagui@atchoum.iro.umontreal.ca |
---|---|
date | Tue, 26 May 2009 18:45:09 -0400 |
parents | e915f5c9bb21 |
children | 98a99aafd14a |
files | pylearn/algorithms/sgd.py |
diffstat | 1 files changed, 11 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/algorithms/sgd.py Tue May 26 17:39:43 2009 -0400 +++ b/pylearn/algorithms/sgd.py Tue May 26 18:45:09 2009 -0400 @@ -5,7 +5,9 @@ class StochasticGradientDescent(theano.Module): """Fixed stepsize gradient descent""" - def __init__(self, args, cost, params, gradients=None, stepsize=None, updates=None): + def __init__(self, args, cost, params, + gradients=None, stepsize=None, + updates=None, auxout=None): """ :param stepsize: the step to take in (negative) gradient direction :type stepsize: None, scalar value, or scalar TensorVariable @@ -13,6 +15,8 @@ :param updates: extra symbolic updates to make when evating either step or step_cost (these override the gradients if necessary) :type updatess: dict Variable -> Variable + :type auxout: auxiliary outputs, list containing output symbols to + compute at the same time as cost (for efficiency) """ super(StochasticGradientDescent, self).__init__() self.stepsize_init = None @@ -34,12 +38,12 @@ if updates is not None: self._updates.update(updates) - + auxout = auxout if auxout else [] self.step = theano.Method( - args, [], + args, auxout, updates=self._updates) self.step_cost = theano.Method( - args, cost, + args, [cost]+auxout, updates=self._updates) updates = property(lambda self: self._updates.copy()) @@ -52,6 +56,7 @@ :returns: standard minimizer constructor f(args, cost, params, gradient=None) """ - def f(args, cost, params, gradient=None, updates=None): - return StochasticGradientDescent(args, cost, params, gradient, stepsize, updates=updates) + def f(args, cost, params, gradient=None, updates=None, auxout=None): + return StochasticGradientDescent(args, cost, params, gradient, stepsize, + updates=updates, auxout=auxout) return f