sgd
sgd copied to clipboard
Unit testing
Add unit tests to tests/
folder.
Follow similar structure as https://github.com/hadley/dplyr/tree/master/tests. See http://r-pkgs.had.co.nz/tests.html
- Check MSE with glm; fail if not close enough
Here are some more ides.
Fix a linear model with 5 parameters. Sample Y, X.
-
Compute one step of explicit SGD. Check whether θ1-θ0 = a_1 * (Y1-θ0*Χ1) Χ1
-
Compute one step of implicit SGD. Check whether θ1-θ0 = a_1 * (Y1-θ1*Χ1) Χ1
-
Repeat 1) and 2) a few times, for random datapoints.
-
Calculate MSE of glmnet. If MSE(SGD) > 0.1 + MSE(glmnet) then fail the test.
-
Calculate time of glmnet. If time(SGD) > 1sec + time(glmnet) then fail the test.
-
and 2) will be implemented as assertions in DEBUG mode c++ code.
-
is implemented as: if MSE(SGD) > 1e-2, then fail the test.
-
will be added as a unit test in R. This test won't run on CRAN.
- Write down 1,2 bad SGD:
- zero learning rate
- random signs: θn = θn-1 +/- grad. where "+/-" is a random sign.
- needs to be improved by adding new convergence criterions, c.f., #54, so that it only stops when less than 1e-2. This way we ensure that, say, MSE(SGD) < 1e-2 not because it didn't run enough iterations but because it's just bad.