[SciPy-User] SciPy-User Digest, Vol 109, Issue 68

Robaula helmrp at yahoo.com
Thu Sep 27 18:18:43 EDT 2012



Bob & Paula H

On Sep 27, 2012, at 1:39 PM, scipy-user-request at scipy.org wrote:

> Message: 4
> Date: Thu, 27 Sep 2012 16:14:40 -0400
> From: "Moore, Eric (NIH/NIDDK) [F]" <eric.moore2 at nih.gov>
> Subject: Re: [SciPy-User] Flaws in fmin_cobyla
> To: "scipy-user at scipy.org" <scipy-user at scipy.org>
> Message-ID:
>    <A18C9F980755B44182031BAB3D1AA0A80457AF9BAA at NIHMLBX15.nih.gov>
> Content-Type: text/plain; charset="us-ascii"

.......snip.......

> The various data produced by fmin_cobyla routine are printed using a direct call to PRINT from within the fortran routine. This is less than optimal because if you are not running in a terminal (ie, at python, or ipython) you won't see any of the output.
> 
> So try executing the example or changing the disp parameter while running from the console, and they will work as expected.
> 
> I'd say this is a big gotcha that should be noted in the docs at least.  The better choice would really be to patch cobyla2.f so that this would work even in the ipython qtconsole or wherever Bob is running his code.
> 
> If there really is something to line 165 (https://github.com/scipy/scipy/blob/master/scipy/optimize/cobyla.py#L165) it's not obvious to me.  Could you elaborate? 
> 
> Eric

Thanks! This explains a lot of this "now you see it, now you don't" business. FYI, I haven't even seen a terminal in the last 25-30 years. I'm retired with no access to any commercial or academic support, and running on a Gateway desktop under Windows 7 and the latest Python 2.7.x and NumPy/SciPy versions. So I'd love to have a sentence or two from you noting the difference in returns depending on whether console is being used or not. I'd like to use them in my prospective revision of fmin_cobyla's docstring.

Wonder how many other SciPy wrapped-Fortran programs have the same behavior?

Well, I think it's line number 165. Whatever the right number, it's the return command from "def fmin_cobyla". That line says to return from fmin_cobyla the Results stuff it got from fmin_cobyla's call to _minimize_cobyla. But -- when you find it, pay close attention to it's last five characters, which are ['x']. Those five characters pick out just the part of the Results dictionary that corresponds to the key 'x', I.e., the final value of the argument of the objective function. One "fix" would be to modify the return statement to return just the argument, and to return all of the Results stuff otherwise. OTOH, Ralf Gommers might properly object on the grounds of it's effect on existing code.

As far as "gotcha", well, it certainly got me! Again, thanks for your astute observations!


More information about the SciPy-User mailing list