# HG changeset patch # User desjagui@atchoum.iro.umontreal.ca # Date 1243377909 14400 # Node ID 2881c67026c1456454c0276115783dc36f5cbafe # Parent e915f5c9bb21775d5110f059da727075f3b9e310 * 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) diff -r e915f5c9bb21 -r 2881c67026c1 pylearn/algorithms/sgd.py --- 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