[SciPy-User] Storing return values of optimize.fmin()

Warren Weckesser warren.weckesser@gmail....
Fri Jun 14 09:31:13 CDT 2013


On Mon, Apr 22, 2013 at 6:12 AM, Jeroen Meidam <jmeidam@nikhef.nl> wrote:

> Hi,
>
> I am using optimize.fmin to minimize a function over 2 parameters.
> In the documentation it says that the output is:
>     (xopt, {fopt, iter, funcalls, warnflag})
>
> I have no problem putting xopt into a variable, because this is simply
> done by writing:
>     xopt = fmin(function,x0)
> After which I can use xopt for anything I need it for.
>
> What I want however, is to store "fopt" into a variable, like I did with
> xopt. In the standard case, fopt is only returned as text in the output
> stream:
> "
> Optimization terminated successfully.
>          Current function value: -0.995801  <--- This is what I'm
> interested in
>          Iterations: 35
>          Function evaluations: 71
> "
>
> How can I store it into a variable? Is it possible?
>
>

Your email is dated April 22, so you might already have the answer by now,
but in case not:

Use the argument `full_output=True`.  For example:

 In [97]: xopt, fopt, iter, funcalls, warnflag = fmin(func, 0,
full_output=True)
Optimization terminated successfully.
         Current function value: 3.000000
         Iterations: 31
         Function evaluations: 62

In [98]: xopt
Out[98]: array([ 10.])

In [99]: fopt
Out[99]: 3.0


Warren



> Thanks,
> Jeroen
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130614/37036faa/attachment.html 


More information about the SciPy-User mailing list