libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
292 stars 36 forks source link

Add data pointer (C layer only) #86

Closed jschueller closed 10 months ago

jschueller commented 10 months ago

In the C layer it can be useful to be able to reach user data from the objective function callback, this adds an extra pointer argument that is re-passed through the objective callback.

zaikunzhang commented 10 months ago

Hi @jschueller Julien, I agree that it will be useful. It sounds like the C version of "user defined args, f(x, *args)", right?

  1. Since we implement it, could we also test it to some extent?
  2. To implement the Python version of "user defined args, f(x, *args)", you will not need to use the data_ptr in the C interface, right? As far as I see, it can be implemented using a lambda function (if I understand this concept correctly) easily, right?

Thanks

jschueller commented 10 months ago
  1. ok lets do that
  2. yes, in Python the language is more powerful: its done it using the objective function decorator
jschueller commented 10 months ago

all good

zaikunzhang commented 10 months ago

1.

f = 0.0/0.0;

What about

f = NAN;

where NAN is a macro from math.h.

  1. cmake --build . --target tests --parallel 4

    Do we still run the C and Fortran examples? Or they have been renamed to tests? I think we should run them, and examples is a better name.

Thanks.

jschueller commented 10 months ago
  1. I read NAN is not alwasy supported, but let me try
  2. yes, we run every tests that are not a stress test, this command only build the tests including tests based on examples
zaikunzhang commented 10 months ago
  // check data is ok
  if (data != data_ref)
  {
    printf("invalid data\n");
    *f = NAN;
  }

So we will not be informed by the test if there is a discrepancy between data and data_ref unless we check the message. What about raising an error so that we know if there is a problem?

jschueller commented 10 months ago

we check at the end that the evaluation number is ok

zaikunzhang commented 10 months ago

I read NAN is not alwasy supported, but let me try

If it is not always supported, we should not use it in the production code, but maybe ok for a test ...

zaikunzhang commented 10 months ago

we check at the end that the evaluation number is ok

It is here, return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); right? If yes, OK.

jschueller commented 10 months ago

yes