[SciPy-dev] parameter control in scipy.optimize.leastsq
Sun Oct 19 05:28:54 CDT 2008
On Sun, Oct 19, 2008 at 12:06 PM, Robin <email@example.com> wrote:
> On Sun, Oct 19, 2008 at 10:37 AM, Maximilian Fabricius <firstname.lastname@example.org> wrote:
>> I have been using scipy for about one and a half years now and have
>> been extremely pleased.
>> In this time I have made extensive use of scipy.optimize.leastsq.
>> While I am generally fairly happy
>> with its performance, I think it does lacks one important feature
>> which I am used to from similar
>> routines in other languages. (Please excuse if I have just missed that
>> feature so far.)
>> I would like to be able to control which parameters actually are
>> fitted. For example I would like to be able to
>> leastsq( redsiduals, p0, args=(y), fit=([True,True,False,True]) )
>> where the parameter "fit" would tell leastsq to leave the parameter
>> p0 untouched while fitting the others.
> I think you can do this by 'wrapping' your existing function:
> Something like:
> fit_function = lambda x, fixed: residuals(x,x,fixed,x)
> Then you can call least squared with the fixed argument specified
> leastsq( fit_function, p0, args=(y,fixed))
> You can either have the fixed parameters passed as a argument to the
> lambda, or have them defined where the lambda is run (but I find it a
> bit confusiong becuase the scoping gets funny). I'm sure you could do
> something to get the [True, False] type notation you want - but since
> you will have to specify the fixed values as well.
> Scipy-dev mailing list
thank you for the quick reply.
Indeed, but this would still involve to swap parameters around between
fixed and non-fixed and
changing the lambda function manually rather then just switching the
fissint on and off
with a single variable.
But no doubt, a wrapper can be done.
More information about the Scipy-dev