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
Inclusion of PRIMA solvers in lme4 #744
Comments
This is a really interesting idea. Quick question: are the versions of these solvers that are available through the NLopt library also based on old code, or do they include your updates? |
Hi @bbolker , Thank you for the response. The NLopt library is based on a C translation (by f2c) of the original Fortran 77 implementation, the old code by Professor Powell. Thanks, |
Thanks. I definitely like the idea of wrapping the PRIMA functions to make them available to the R community, although I will say in advance that it won't necessarily be easy (e.g., interfacing R objective functions with the Fortran code, making sure that the Fortran code is compliant with all the standards insisted on by the CRAN (R package archive) maintainers, etc ... |
I fully understand and agree. It is the objective of PRIMA to make these powerful solvers available to everyone in her/his favorite languages. This objective, of course, as you mentioned, is nontrivial. But I will work towards this direction. However, since I cannot take care of everything even if I want to, I will also try to communicate with major players and leaders in the respective communities (R, Python, Julia, ...) like you to see whether there is some interest on your side. You are the experts anyway. BTW, I personaly do not think the old Fortran 77 code or its machine-generated C code has a better shape than the modernized PRIMA implementation. If the former can meet the standards, then the latter will likely. Of course, I am biased :) |
@zaikunzhang I would note that I have tried the PRIMA version of BOBYQA in the MixedModels.jl package for Julia using your PRIMA.jl package to replace the NLopt version. It is much easier to configure the optimization problem with PRIMA than with the NLopt version. I did find that the PRIMA implementation of BOBYQA took more iterations to converge but that could be a matter of the convergence tolerances, etc. |
Thank you @dmbates for your comments. I am glad that you found
Would it be possible for you to show us how you called PRIMA, and what was the exact output? Indeed, we never report the number of "iterations", because it is a concept irrelevant in derivative-free optimization. We are only concerned about the number of function evaluations and the quality of the solution. See https://github.com/orgs/libprima/discussions/145 for more elaboration. I am curious about what you really observed. Thank you. |
I'm not sure if this came up in other parts of this discussion but there is a C API for libprima, which is what was used in PRIMA.jl. As a result, the interfacing part of the |
I have been experimenting with using the optimizers from PRIMA.jl instead of the NLopt.jl optimizers in the The results are encouraging. For linear mixed models the more difficult model fits often require considerably fewer objective evaluations with PRIMA. The differences in the objective at the minimum for the two implementations of BOBYQA are either negligible (less than 0.001 for this objective) or favor PRIMA. In only one case did the PRIMA result exceed the NLopt result by more than 0.001 (column fdiff in the table below, expressed as NLopt objective - PRIMA objective). You will need to look at the original code to see the data sets and the models being fit.
Even more interesting is some experimentation with the optimization for Generalized Linear Mixed Models, as fit by |
Hi @dmbates , thank you very much for these very encouraging experiments! What kind of constraints does your problems have? I suppose they only have bound constrains. cc @emmt and @amontoison, who coded the Julia binding for the Fortran backend of PRIMA. |
@zaikunzhang The constraints in this type of problem are simple: a subset of the parameters are required to be non-negative. I re-did the table adding
The first two rows are identical because the models are identical but generated from slightly different formulas. Many of these problems are trivial as optimization problems but some toward the bottom of the table are of interest. |
Thank you @dmbates . Are the nonnegtivity constraints relaxiable in the sense that the objective function is still well defined if these constraints are violated? If yes, you may try LINCOA as well. It is an infeasible method, but it may use less function evaluations. Thank you. |
Generally not relatable ... |
@zaikunzhang It is possible to evaluate the objective when the non-negativity constraints are violated but such a case corresponds to another set of parameters that do not violate the constraints. In the straightforward cases we are optimizing an objective with respect to the elements in the lower triangle of the Cholesky factor of a positive semi-definite symmetric matrix. For definiteness we require the elements on the diagonal of the factor to be non-negative. There are occasions where models will converge to a singular Cholesky factor and we want to know that. We could remove the non-negativity constrains on the diagonal elements of the factor but the objective for parameters providing negative diagonal elements in a Cholesky factor is the same as the factor with all the signs in those column(s) being flipped. In statistical terms, we are estimating one or more covariance matrices parameterized by their Cholesky factor. It is the multivariate analogue of estimating a variance parameterized by its standard deviation, which must be non-negative. |
@zaikunzhang Did you mean to suggest NEWUOA for the unconstrained problem when you wrote LINCOA? |
@zaikunzhang Here is the table using NEWUOA instead of BOBYQA with the non-negativity constraints. As you can see the difficult problems (kb07 formula 3, oxide formula 2, d3 formula 1) get to a comparable optimum but take many more evaluations.
The dyestuff2 example does converge on the boundary using BOBYQA and provides the same fit with NEWUOA. |
@dmbates, thanks for the clarification above - it made me realize I've been thinking about this too loosely, and that we could think of points where any of the diagonal elements of the Cholesky vector are zero not as being on the boundary of the feasible space, but rather as being at points where (unless the first derivatives happen to go to zero at the point) the maximum has a cusp rather than a well-defined curvature ... |
I did mean LINCOA. It can handle bound constraints (as well as linear constraints), but the iterates may violate the bounds, which are expected to be satisfied asymptotically. NEWUOA cannot handle constraints. NLopt extends it to bound-constrained problems by truncating the variables when they volatile the bounds (if my memory is correct), which seems quite heuristic. |
How did you do this? I suppose you are using NLopt, right? PRIMA does not and will not make NEWUOA handle bounds. |
@zaikunzhang I misunderstood your initial suggestion to mean that I should try removing the bounds altogether and apply NEWUOA to the unconstrained problem. Please ignore that table. Thank you for your clarification about LINCOA handling the constraints differently and possibly achieving convergence in fewer evaluations. It turns out that LINCOA does significantly worse than the PRIMA implementation of BOBYQA in some of these cases
The last line, where LINCOA declares convergence at an objective value 3.408 greater than that from NLopt's bobyqa, means that we would not want to use this approach. My thanks for your taking the time to respond on this issue. We look forward to using libprima and PRIMA.jl in out MixedModels.jl package. |
Dear lme4 maintainers
This is Dr. Zaikun Zhang from The Hong Kong Polytechnic University. Together with Professor N.I.M. Gould, I am responsible for maintaining the renowned derivative-free optimization solvers of the late Professor M.J.D. Powell, namely COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. I am the author of PRIMA, which provides the reference implementation for these solvers. They are widely used by engineers and scientists. For instance, see Section 1 of a recent paper on Powell's solvers as well as the Google searches of COBYLA and BOBYQA.
I note that lme4 provides COBYLA and BOBYQA. However, they are based on a version corresponding to the old Fortran 77 implementation of these solvers, which is not maintained anymore. Even though the original Fortran 77 implementation is truly a masterpiece, it contains many bugs (mostly due to the language itself), which can lead to segmentation faults or infinite loops. For example, see Section 4.4 of the above paper and many GitHub issues. It is strongly discouraged to use the Fortran 77 version of these solvers anymore.
That said, it might be desirable to include the PRIMA implementation of these solvers into lme4 via an R interface, in order to make these renowned solvers available to the R community. I will be happy to assist on the Fortran side if you would like to do so.
Thanks and regards,
Zaikun ZHANG
Ph.D. and Assistant Professor
Dept. App. Math., Hong Kong Polytechnic University
The text was updated successfully, but these errors were encountered: