<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gradfunc(self, p):
 """ The gradient-computing function that gets passed to the optimizers, if needed. """

        self._set_stochastics(p)
        for i in xrange(self.len):
            self.grad[i] = self.diff(i)

        return -1 * self.grad