Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird Condition in SGD #461

Closed
aytekinar opened this issue Oct 13, 2015 · 6 comments
Closed

Weird Condition in SGD #461

aytekinar opened this issue Oct 13, 2015 · 6 comments

Comments

@aytekinar
Copy link

In this file, there is a condition on line 63 which says:

if (overallObjective != overallObjective)
{
    Log::Warn << "SGD: converged to " << overallObjective << "; terminating"
        << " with failure.  Try a smaller step size?" << std::endl;
    return overallObjective;
}

Is this a bug, or what is the reasoning behind it?

@rcurtin
Copy link
Member

rcurtin commented Oct 14, 2015

Hi there,

If the step size is too large, the optimization may jump back and forth in a valley, taking progressively larger steps, until the overall objective diverges to NaN. That's the justification for the warning. In various situations where I've used SGD (that led to this comment being added), reducing the step size was usually a solution to the problem that caused convergence to a reasonable objective value.

I hope this is helpful; let me know if I should clarify further.

Thanks,
Ryan

@aytekinar
Copy link
Author

Hey,

Thanks for the answer. Sorry --- apparently I had not made myself clear enough. I was trying to ask the overallObjective != overallObjective comparison, actually. Do you say putting this comparison is good because when the objective function is inf (or, is it really nan?), it will not be equal to itself?

Thanks for your time

@rcurtin
Copy link
Member

rcurtin commented Oct 18, 2015

Yep, that's exactly it. See here:
http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c
(this actually suggests that the way I've written it isn't the best way, so perhaps it should be changed at some point...)

@stereomatchingkiss
Copy link
Contributor

Hi, maybe you can consider using

 bool isnan( double arg );

in c++11(any intention to upgrade to c++14?), maybe this is more portable and easier to read

@aytekinar
Copy link
Author

Yes, I agree with @stereomatchingkiss . My intention was not to disturb you with the subtleties like this, but to understand what was going on. Yet, if your style guide is not strictly against the use of C++11 or above, you might consider using bool std::isnan( double arg ) or bool std::isinf(double arg), both from the #include <cmath> library. That would make the code easier to read and more robust against compiler-dependent implementation issues. Thanks for the discussion!

@rcurtin
Copy link
Member

rcurtin commented Oct 19, 2015

Fixed in 09cd0d6; thanks for the suggestions. I think it's important to consider little readability details like this, so if you find anything else you think should be changed, please feel free to open more issues. :)

@rcurtin rcurtin closed this as completed Oct 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants