andresy/torch — pull request #10 by abeschneider (2012-02-22 23:19:54+00:00)
Title: I needed a way to do a derivative check on a Sequential...

In order to write the derivativeCheck I needed to provide a method to get all the parameters from a Sequential, so I added getParameters(). This essentially just calls getParameters() on the modules and concatenate them. Additionally, Sequential:fromParameters() was needed, which subsequently requires Modules:fromParameters().

Unfortunately, I couldn't see a good way to write a generic fromParameters() function, since a Module has no listing of its parameters. Thus, I wrote one just for Linear with the idea that it could be implemented for other modules. However, if Modules kept a list of their parameters, this could be moved into Module.

The function Sequential:derivativeCheck(input, output, criterion, epsilon) perturbs each parameter +/- epsilon to calculate the derivative and match against the computed gradient. I've added a method to the unit test that creates an auto encoder to test out the function.