stevengj / nlopt

library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization
Other
1.88k stars 584 forks source link

std::invalid_argument when running BFGS #455

Closed ilansmolySR closed 2 years ago

ilansmolySR commented 2 years ago

I get the following termination message:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  nlopt invalid argument

When I execute the following code:

    nlopt::opt opt;
    opt = nlopt::opt(nlopt::algorithm::LD_LBFGS_NOCEDAL,9);
    opt.set_min_objective(myfunc, points_vector);
    opt.set_xtol_rel(1e-4);
    opt.set_ftol_rel(1e-4);
    opt.set_xtol_abs(1e-4);
    opt.set_ftol_abs(1e-4);
    opt.set_maxeval(10000);

    double minf;
    nlopt::result result = opt.optimize(*init_guess, minf);

I also tried adding the following lines:

 opt.set_maxeval(10000);
    opt.set_vector_storage(30);
    opt.set_lower_bounds({-10,-10,-10,-10,-10,-10,-10,-10,-10});
    opt.set_upper_bounds({10,10,10,10,10,10,10,10,10});

but I still get the same termination message above.

When I run the same code with Nelder-Mead algorithm i.e. with opt = nlopt::opt(nlopt::algorithm::LN_NELDERMEAD,9); instead of opt = nlopt::opt(nlopt::algorithm::LD_LBFGS_NOCEDAL,9); the program runs perfectly.

ilansmolySR commented 2 years ago

It seems that the reason for this prblem was that LD_LBFGS_NOCEDAL is not supported and LD_LBFGS should be used instead.

stevengj commented 2 years ago

Yes, LD_LBFGS_NOCEDAL is an undocumented constant left over from the days when I had an internal implementation using Nocedal's L-BFGS code, which I couldn't distribute due to ACM TOMS licensing restrictions. IIRC the licensing on that particular code has been changed, so we could probably use it if we wanted to.

jschueller commented 2 years ago

Do you think its worth resurrecting it ? Else I propose to drop that constant or at least throw an explicit error when this algorithm is selected.