nloptr icon indicating copy to clipboard operation
nloptr copied to clipboard

auglag: pass ellipsis to gradient

Open jar1karp opened this issue 7 years ago • 5 comments

This fixes cases where both objective and gradient take more parameters than just controls and optimization algorithm uses derivatives.

jar1karp avatar Jul 27 '17 12:07 jar1karp

Is there any reason why this has not been merged? I just ran into the issue this PR is supposed to resolve today.

jmh530 avatar Aug 26 '20 13:08 jmh530

Thanks for contributing this PR. I can understand why you would propagate ellipsis to both function and gradient as they probably share the same optional parameters. However, why would you propagate these optional arguments to the constraints?

astamm avatar Jan 28 '22 10:01 astamm

@astamm I'm not the original author, it has been some time that I have looked at the issue, and I tend to use other algorithms more frequently than auglag, but sometimes you need to share the optional parameters from the objective/gradient with the constraints. For instance, in a robust portfolio optimization with a variance constraint, the covariance matrix would show up in both the objective/gradients and the constraints. You can rewrite it so that the variance constraint shows up in the objective, but sometimes that's not what you want to do.

jmh530 avatar Jan 28 '22 16:01 jmh530

@astamm It's been a few years, but it's exactly as @jmh530 wrote.

jar1karp avatar Feb 01 '22 09:02 jar1karp

Great. I'll give it some more thoughts. I know it was some years ago but I became maintainer only some months ago.

astamm avatar Feb 01 '22 09:02 astamm

Since we started the process of switching the default order of the inequality, the code for all the hin and heq related functions have changed and so this PR should not be merged. If it is critical to use the auglag convience wrapper, we can work on adding the ellipses, but please realize that auglag is just a convenience wrapper to setting up the the full nloptr call (see its source). Is it possible for you to pass the necessary parameters in the full nloptr call, like the following pseudocode? You will have to figure out the appropriate calls to opts, which @hwborchers did for you in writing auglag. You can look at its source code and at the unit test for auglag for examples of a full nloptr invocation.

nloptr(x0,
               eval_f = fn(x, parameters),
               eval_grad_f = gr(x, parameters),
               lb = lower,
               ub = upper,
               eval_g_ineq = hin(x, parameters),
               eval_jac_g_ineq = hinjac(, parameters),
               eval_g_eq = heq(x, parameters),
               eval_jac_g_eq = heqjac(x, parameters),
               opts = opts)

aadler avatar Jun 26 '24 21:06 aadler

I am following @aadler's advice. Please reopen an issue if current version is not satisfying for your use case.

astamm avatar Jun 27 '24 09:06 astamm