sgd icon indicating copy to clipboard operation
sgd copied to clipboard

Models using boost::math::tools::schroeder_iterate can get stuck

Open jonlachmann opened this issue 3 years ago • 4 comments

Hi, I am building a package that is using sgd. When doing tests I sometimes encountered models that got stuck in the sgd C++ part for no particular reason, crashing R in the end. I did address sanitizing, but everything checked out. Then I investigated where it got stuck, and it was while running the boost::math::tools::schroeder_iterate function for the update in implicit_sgd.h (rows 79 and 110). I made a fork at https://github.com/jonlachmann/sgd fixing this by just setting the max iterations for boost::math::tools::schroeder_iterate to 1000. I have no idea if this is a reasonable value, but it solves the problem.

Do you want me to create a pull request, or is this something that might need further looking into?

jonlachmann avatar Apr 21 '21 08:04 jonlachmann

Had the same problem. Installed your fork and now R doesn't crash anymore while using sgd. Thanks.

AlbertRapp avatar May 25 '22 12:05 AlbertRapp

Hey @jonlachmann Thanks for creating the fork. Appreciate it.

Sounds like a weird numerical issue. Do you have a data/code example to reproduce it by any chance?

ptoulis avatar May 29 '22 03:05 ptoulis

Hi! This was during the more intense part of writing my thesis. I do not really remember how I managed to get this to happen, and I ended up coding a more basic SGD from scratch to demonstrate the ideas in the thesis.

I was using different stochastic algorithms in a bayesian model selection setting, so I ran many thousand models, which some of the time gave strange errors that were edge cases of various implementations. Perhaps @AlbertRapp has something that is reproducible?

Anyway, I could try to see if I have any code that relates to this, but I am not too optimistic as the thesis period was very hectic. If you want to apply my fix in your codebase I would be happy to provide a PR.

jonlachmann avatar May 29 '22 09:05 jonlachmann

Sure, that would be great! Thanks.

ptoulis avatar Jun 01 '22 04:06 ptoulis