Lagrange Multipliers in optimize.slsqp
Hi all, Would it be possible for optimize.slsqp to return the Lagrange multipliers of the constraints? I don't know Fortran, but it seems that they are available in the original Fortran code: http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt... Thanks, Guilherme -- Guilherme P. de Freitas http://www.gpfreitas.com
On Thu, Feb 25, 2010 at 8:17 PM, Guilherme P. de Freitas <guilherme@gpfreitas.com> wrote:
Hi all,
Would it be possible for optimize.slsqp to return the Lagrange multipliers of the constraints? I don't know Fortran, but it seems that they are available in the original Fortran code:
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
That looks like the constraint of the the lsq subroutine part of sequential least squares algorithm. http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt... Skipper
On Thu, Feb 25, 2010 at 11:08 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
On Thu, Feb 25, 2010 at 8:17 PM, Guilherme P. de Freitas <guilherme@gpfreitas.com> wrote:
Hi all,
Would it be possible for optimize.slsqp to return the Lagrange multipliers of the constraints? I don't know Fortran, but it seems that they are available in the original Fortran code:
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
That looks like the constraint of the the lsq subroutine part of sequential least squares algorithm.
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
here is the workspace `w` description of the main slsqp routine http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt... w is available in python, but non of the content of it is used in python http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp.py#L345 So, correctly extracting the slices from the workspace w should be possible to get the Lagrange multipliers that were used. Josef
Skipper _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
On Fri, Feb 26, 2010 at 8:55 AM, <josef.pktd@gmail.com> wrote:
On Thu, Feb 25, 2010 at 11:08 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
On Thu, Feb 25, 2010 at 8:17 PM, Guilherme P. de Freitas <guilherme@gpfreitas.com> wrote:
Hi all,
Would it be possible for optimize.slsqp to return the Lagrange multipliers of the constraints? I don't know Fortran, but it seems that they are available in the original Fortran code:
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
That looks like the constraint of the the lsq subroutine part of sequential least squares algorithm.
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
here is the workspace `w` description of the main slsqp routine
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp/slsqp_opt...
w is available in python, but non of the content of it is used in python
http://projects.scipy.org/scipy/browser/trunk/scipy/optimize/slsqp.py#L345
So, correctly extracting the slices from the workspace w should be possible to get the Lagrange multipliers that were used.
Ah, this should be enough then to return the multipliers. See if it gives what you'd expect? Then you can file an enhancement ticket if you want the multipliers back. Index: slsqp.py =================================================================== --- slsqp.py (revision 6242) +++ slsqp.py (working copy) @@ -371,5 +371,6 @@ return [list(x), float(fx), int(majiter), - int(mode), + list(w[:m]), + int(mode), exit_modes[int(mode)] ] Skipper
Hi everyone,
Ah, this should be enough then to return the multipliers. See if it gives what you'd expect? Then you can file an enhancement ticket if you want the multipliers back.
Index: slsqp.py =================================================================== --- slsqp.py (revision 6242) +++ slsqp.py (working copy) @@ -371,5 +371,6 @@ return [list(x), float(fx), int(majiter), - int(mode), + list(w[:m]), + int(mode), exit_modes[int(mode)] ]
Skipper _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Thanks! That seems to give the right multipliers back. I'll file the ticket. Best, Guilherme -- Guilherme P. de Freitas http://www.gpfreitas.com
Just one note on this: the multipliers don't seem very accurate. On a *very* simple problem, the multiplier was correct only up to the 2nd decimal digit. Here is the problem: minimize - [ log(x) + log(y) ] subject to x + y = 8 The solution is at (4, 4) and the multiplier of the single equality constraint should be 1/4. The routine returns 0.2526. I thought this could be because I was not providing the derivatives, but that is not the case: when I provided the derivatives of both the objective function ('fprime') and the constraints ('fprime_eqcons'), I also got multipliers that were correct only up to the second decimal digit. Here is the full code if you want to verify it by yourself (first apply the modifications to slsqp.py as suggested by Skipper Seabold): import numpy as np from scipy.optimize import fmin_slsqp def u(x): return -np.sum(np.log(x)) def du(x): return -1.0/x def c(x): return np.sum(x) - 8 def dc(x): return np.ones((1, np.size(x))) initguess = np.array([1, 8]) sol = fmin_slsqp(func=u, x0=initguess, fprime=du, eqcons=[c], fprime_eqcons=dc, full_output=1, iprint=2, acc=1.0e-14) print(sol) keys = ('xopt', 'fopt', 'its', 'multipliers', 'exitmode', 'exitmsg') answer = dict(zip(keys, sol)) for key in answer: print(key, answer[key]) On Tue, Mar 2, 2010 at 11:14 AM, Guilherme P. de Freitas <guilherme@gpfreitas.com> wrote:
Hi everyone,
Ah, this should be enough then to return the multipliers. See if it gives what you'd expect? Then you can file an enhancement ticket if you want the multipliers back.
Index: slsqp.py =================================================================== --- slsqp.py (revision 6242) +++ slsqp.py (working copy) @@ -371,5 +371,6 @@ return [list(x), float(fx), int(majiter), - int(mode), + list(w[:m]), + int(mode), exit_modes[int(mode)] ]
Skipper _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Thanks! That seems to give the right multipliers back. I'll file the ticket.
Best,
Guilherme
-- Guilherme P. de Freitas http://www.gpfreitas.com
-- Guilherme P. de Freitas http://www.gpfreitas.com
Any opinions on how this change should be implemented? I'd prefer to keep the code clean, and the solution below is simple, but I'd rather not break current implementations of SLSQP that people have employed, as inserting a new element into the output likely would. I'm leaning towards allowing both boolean or integer types for the full_output argument. 0 or 1 would work as True and False do now, and 2 would return the Lagrange multipliers as well as everything else. On Tue, Mar 2, 2010 at 2:14 PM, Guilherme P. de Freitas <guilherme@gpfreitas.com> wrote:
Hi everyone,
Ah, this should be enough then to return the multipliers. See if it gives what you'd expect? Then you can file an enhancement ticket if you want the multipliers back.
Index: slsqp.py =================================================================== --- slsqp.py (revision 6242) +++ slsqp.py (working copy) @@ -371,5 +371,6 @@ return [list(x), float(fx), int(majiter), - int(mode), + list(w[:m]), + int(mode), exit_modes[int(mode)] ]
Skipper _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Thanks! That seems to give the right multipliers back. I'll file the ticket.
Best,
Guilherme
-- Guilherme P. de Freitas http://www.gpfreitas.com _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
-- - Rob Falck
I was wondering if it is worth outputting the multipliers at all... The low accuracy in a very simple example (see my previous post) makes me wonder how innacurate the estimated multipliers can be in a more complex problem. On Thu, Mar 4, 2010 at 5:55 PM, Rob Falck <robfalck@gmail.com> wrote:
Any opinions on how this change should be implemented? I'd prefer to keep the code clean, and the solution below is simple, but I'd rather not break current implementations of SLSQP that people have employed, as inserting a new element into the output likely would. I'm leaning towards allowing both boolean or integer types for the full_output argument. 0 or 1 would work as True and False do now, and 2 would return the Lagrange multipliers as well as everything else.
-- Guilherme P. de Freitas http://www.gpfreitas.com
participants (4)
-
Guilherme P. de Freitas
-
josef.pktd@gmail.com
-
Rob Falck
-
Skipper Seabold