[SciPy-user] Optimization Working only with a Specific Expression of the input Parameters

Lorenzo Isella lorenzo.isella at gmail.com
Fri Mar 2 14:30:35 EST 2007


Hi Brandon,
Thanks for your advice, but I am a bit confused: myvar1 is simply a 
fitting parameter (i.e. it is used to return an output), nothing is 
stored in it to start from.
I do not define it anywhere.
It is not an array. Furthermore, I have to say that if I define the 
error function as the absolute difference between my data and the 
function I want to use for the fitting, then the code executes even 
without raising any parameter to the second power, but returns nonsense 
(negative variance and so on).
Instead, without the abs(), I still get the same problem mentioned in my 
previous email.
There is something I must be misunderstanding...it is not a tough 
optimization at all the one I am carrying out...
Cheers

Lorenzo









Hello,

I'm just an amateur, but it seems to me like the array data in myvar1 are
likely integers. When you raise the data to a power of type float (i.e.
2.0) all the members of the array are automatically converted to real
(float) types. Easiest and fastest thing I know to do would be:

      myvar1 = myvar1*1.0

Or, and probably preferred (assuming you are using the numpy array type and
have imported it):

      myvar1 = numpy.array(myvar1,dtype=float)

Brandon

At 08:25 AM 3/2/2007, you wrote:

> >Dear All,
> >I was trying to fit some data using the leastsq package in
> >scipy.optimize. The function I would like to use to fit my data is:
> >
> >log(10.0)*A1/sqrt(2.0*pi)/log(myvar1)*exp(-((log(x/mu1))**2.0)/2.0/log(myvar1)/log(myvar1)))
> >
> >  where A1, mu1 and myvar1 are fitting parameters.
> >For some reason, I used to get an error message from scipy.optimize
> >telling me that I was not working with an array of floats.
> >I suppose that this is due to the fact that the optimizer also tries
> >solving for negative values of mu1 and myvar1, for which the log
> >function (x is always positive) does not exist.
> >In fact, if I use the fitting function:
> >
> >log(10.0)*A1/sqrt(2.0*pi)/log(myvar1**2.0)*exp(-((log(x/mu1**2.0))**2.0)/2.0/log(myvar1**2.0)/log(myvar1**2.0)))
> >
> >Where mu1 and myvar1 appear squared, then the problem does not exist
> >any longer and the results are absolutely ok.
> >Can anyone enlighten me here and confirm this is what is really going on?
> >Kind Regards
> >
> >Lorenzo
> >_______________________________________________
> >SciPy-user mailing list
> >SciPy-user at scipy.org
> >http://projects.scipy.org/mailman/listinfo/scipy-user
>   


Brandon C. Nuttall

> >Dear All,
> >I was trying to fit some data using the leastsq package in
> >scipy.optimize. The function I would like to use to fit my data is:
> >
> >log(10.0)*A1/sqrt(2.0*pi)/log(myvar1)*exp(-((log(x/mu1))**2.0)/2.0/log(myvar1)/log(myvar1)))
> >
> >  where A1, mu1 and myvar1 are fitting parameters.
> >For some reason, I used to get an error message from scipy.optimize
> >telling me that I was not working with an array of floats.
> >I suppose that this is due to the fact that the optimizer also tries
> >solving for negative values of mu1 and myvar1, for which the log
> >function (x is always positive) does not exist.
> >In fact, if I use the fitting function:
> >
> >log(10.0)*A1/sqrt(2.0*pi)/log(myvar1**2.0)*exp(-((log(x/mu1**2.0))**2.0)/2.0/log(myvar1**2.0)/log(myvar1**2.0)))
> >
> >Where mu1 and myvar1 appear squared, then the problem does not exist
> >any longer and the results are absolutely ok.
> >Can anyone enlighten me here and confirm this is what is really going on?
> >Kind Regards
> >
> >Lorenzo
> >_______________________________________________
> >SciPy-user mailing list
> >SciPy-user at scipy.org
> >http://projects.scipy.org/mailman/listinfo/scipy-user
>   


Brandon C. Nuttall





More information about the SciPy-User mailing list