Re: [SciPy-User] optimize.fmin_slsqp bounds problem
Please provide a self-contained reproducible example. What is the exact objfn?
I don't get any errors with
------------------------------ import numpy as np from scipy.optimize import fmin_slsqp>
np.random.seed(1234) y = np.random.randn(9) * 100 def objfn(x): return ((x - y)**2).sum()
bounds = [(-1e-09, 1e-08), (1e-07, 1e-05), (1e-07, 1e-05), (1e-10, 1e-08), (1e-10, 1e-08), (1e-10, 1e-08), (80.0, 200.0), (1.0, 5.0), (1.0, 5.0)] x0 = np.array([ 0.00000000e+00, 1.01000000e-06, 3.03000000e-06, 1.00000000e-09, 1.00000000e-09, 1.00000000e-09, 1.50000000e+02, 2.00000000e+00, 2.00000000e+00]) res = fmin_slsqp(objfn, np.array(x0,dtype=float),bounds=bounds,full_output=True) ------------------------------
The algorithm and code used (with permission from ACM) is this: http://dl.acm.org/citation.cfm?id=192124
The only way to understand what goes wrong is probably to look in the Fortran code and see what it does.
-- Pauli Virtanen
Well my objective function is a quite complex recursive function of the 9 input parameters which in the end returns the sum of the squared deviation as expected by fmin_slsqp (it involves several of my own modules and a large dataset, so too long to be posted). I have checked that the return value is valid (not NAN eg) and as you see there is a single iteration done. I also have checked the minimizer with examples similar to yours, and it worked. I'll have to get my hand Fortran dirty it seems, I just hoped someone had alreay had this kind of symptom and found a "trivial" error. Thanks anyway! JF Helmholtz-Zentrum Geesthacht Zentrum für Material- und Küstenforschung GmbH Max-Planck-Straße 1 I 21502 Geesthacht I Deutschland/Germany Geschäftsführer/Board of Management: Prof. Dr. Wolfgang Kaysser, Dipl.-Ing. Michael Ganß Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: MinDirig Wilfried Kraus Amtsgericht Lübeck HRB 285 GE (Register Court) Internet: http://www.hzg.de
09.10.2013 23:43, Jean-Francois.Moulin@hzg.de kirjoitti: [clip]
Well my objective function is a quite complex recursive function of the 9 input parameters which in the end returns the sum of the squared deviation as expected by fmin_slsqp (it involves several of my own modules and a large dataset, so too long to be posted).
In such a case, you can record the values of the objective function and coordinates for each call in a file. Assuming the rounding error is not too bad, the result should be reproducible. -- Pauli Virtanen
10.10.2013 00:10, Pauli Virtanen kirjoitti:
09.10.2013 23:43, Jean-Francois.Moulin@hzg.de kirjoitti: [clip]
Well my objective function is a quite complex recursive function of the 9 input parameters which in the end returns the sum of the squared deviation as expected by fmin_slsqp (it involves several of my own modules and a large dataset, so too long to be posted).
[clip]
In such a case, you can record the values of the objective function and coordinates for each call in a file. Assuming the rounding error is not too bad, the result should be reproducible.
... but if you manage to find the reason why it fails yourself, please follow up. It seems possible that the issue is a bug in the original Fortran code, as the conditions that lead to MODE=4 exit are not all that clearly laid out there. E.g. stuff like this IF(diff(one+fac,one).LE.ZERO) GOTO 50 # -> exit with mode=4 that apparently tries to work around rounding errors, but which optimizing compilers may just optimize away. -- Pauli Virtanen
... but if you manage to find the reason why it fails yourself, please follow up.
It seems possible that the issue is a bug in the original Fortran code, as the conditions that lead to MODE=4 exit are not all that clearly laid out there.
E.g. stuff like this
IF(diff(one+fac,one).LE.ZERO) GOTO 50 # -> exit with mode=4
that apparently tries to work around rounding errors, but which optimizing compilers may just optimize away.
-- Pauli Virtanen
Here is some follow up (I would not have dropped the topic whithout mentioning the results of my dayly commute work ;0) It seems that although my X0 respects the initial conditions, during the evaluation of the gradients some forbidden regions of the parameter space are explored. The affected parameters seem to have a very weak (maybe down to zero) influence on the function output. So the chi2 landscape is very very flat in these directions. While performing the first iteration the function is then evaluated outside of the bounds for these parameters or I fall in one of these rounding traps you mention. I will try to rewrite my model without these apparently irrelevant parameters and see if it converges to something physically reasonable. I'll keep posting... Helmholtz-Zentrum Geesthacht Zentrum für Material- und Küstenforschung GmbH Max-Planck-Straße 1 I 21502 Geesthacht I Deutschland/Germany Geschäftsführer/Board of Management: Prof. Dr. Wolfgang Kaysser, Dipl.-Ing. Michael Ganß Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: MinDirig Wilfried Kraus Amtsgericht Lübeck HRB 285 GE (Register Court) Internet: http://www.hzg.de
participants (2)
-
Jean-Francois.Moulin@hzg.de
-
Pauli Virtanen