Add stochastic gradient descent and restructure code

- add stochastic gradient descent
- add gradient for l_bfgs
- restructure loss and regularizer to unify usage of optimization
  algorithms
- add tests
- seed rand in tests to be robust against random effects