[SciPy-User] Lagrange Multipliers in optimize.slsqp

Guilherme P. de Freitas guilherme at gpfreitas.com
Tue Mar 2 14:57:17 EST 2010


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 at 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 at 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



More information about the SciPy-User mailing list