sgd icon indicating copy to clipboard operation
sgd copied to clipboard

Unit testing

Open dustinvtran opened this issue 9 years ago • 5 comments

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

dustinvtran avatar Apr 20 '15 17:04 dustinvtran

  • Check MSE with glm; fail if not close enough

dustinvtran avatar May 10 '15 17:05 dustinvtran

Here are some more ides.

Fix a linear model with 5 parameters. Sample Y, X.

  1. Compute one step of explicit SGD. Check whether θ1-θ0 = a_1 * (Y1-θ0*Χ1) Χ1

  2. Compute one step of implicit SGD. Check whether θ1-θ0 = a_1 * (Y1-θ1*Χ1) Χ1

  3. Repeat 1) and 2) a few times, for random datapoints.

  4. Calculate MSE of glmnet. If MSE(SGD) > 0.1 + MSE(glmnet) then fail the test.

  5. Calculate time of glmnet. If time(SGD) > 1sec + time(glmnet) then fail the test.

ptoulis avatar May 10 '15 17:05 ptoulis

  1. and 2) will be implemented as assertions in DEBUG mode c++ code.

  2. is implemented as: if MSE(SGD) > 1e-2, then fail the test.

  3. will be added as a unit test in R. This test won't run on CRAN.

lantian2012 avatar May 15 '15 18:05 lantian2012

  • Write down 1,2 bad SGD:
  1. zero learning rate
  2. random signs: θn = θn-1 +/- grad. where "+/-" is a random sign.

ptoulis avatar May 15 '15 22:05 ptoulis

  1. 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.

dustinvtran avatar May 15 '15 22:05 dustinvtran