From: Geico Caveman on
On 2010-08-10 12:15:39 -0500, "Steven_Lord" <slord(a)mathworks.com> said:

>
>
> "Geico Caveman" <spammers-go-here(a)spam.invalid> wrote in message
> news:2010081011203216807-spammersgohere(a)spaminvalid...
>> On 2010-08-10 08:51:38 -0500, "Steven_Lord" <slord(a)mathworks.com> said:
>>
>>>
>>>
>>> "Geico Caveman" <spammers-go-here(a)spam.invalid> wrote in message
>>> news:2010080916101916807-spammersgohere(a)spaminvalid...
>>>> Hello,
>>>>
>>>> I have multipeak 1-D data that often takes a lot of steps to converge
>>>> after specifiying initial guesses. The fit ends up being rather good
>>>> most of the time, but sometimes, initial guesses are a little off, and
>>>> the fit goes haywire.
>>>>
>>>> The whole fitting process takes a lot of time (typically - 3 minutes or
>>>> so per dataset, and I usually work with about 20-50 datasets in a
>>>> single run).
>>>>
>>>> Is there a way to access intermediate parameters so that I can plot the
>>>> fit to give myself visual feedback on how the fitting is going ?
>>>
>>> That depends on what function you're using to perform the fitting. If
>>> you're using a function from Optimization Toolbox, look at the
>>> OutputFcn option in the documentation for OPTIMSET.
>>
>> No. I am using a custom string consisting of mixed Gaussian and
>> Lorentzian peaks.
>
> That tells us what type of curve you're fitting. It doesn't tell us
> what function you're using to fit that curve. Without that
> information, the best advice I can give you is to have the function
> that evaluates your function as part of the curve fitting DISP,
> FPRINTF, etc. the parameters with which it was called. Depending on
> what functions you're using, there may be better approaches (like the
> OutputFcn option I suggested above.)
>
>> I am using something like (and the number of terms is user determined):
>>
>> g1*exp(-((x-g2)/g3)^2) + l1*l2/((x-l3)^2+l2^2) + Gaussian 2 + Gaussian 3 etc.
>>
>> I just want to find a way to access intermediate g1, l1, etc.


I am afraid I do not understand (maybe I am being a little slow today).

I am fitting some experimental data (not a curve). (There are no
functions being called, or anything.)

The string (fitfunctionstring1 in the code below) I mentioned about is
the argument to fittype(). The generated fittype object from there is
used to as an argument for the fit.

Here is the code fragment for better concreteness:

ftype1=fittype(fitfunctionstring1,'coefficients',coefficientlist1,'independent','x');
[fit1,gof1,output1]=fit(xdata1,ydata1,ftype1,opts1);

xdata1

and ydata1 are experimental data. opts1 is a structure that contains
various fitting parameters.

From: Steven_Lord on


"Geico Caveman" <spammers-go-here(a)spam.invalid> wrote in message
news:2010081111321516807-spammersgohere(a)spaminvalid...
> On 2010-08-10 12:15:39 -0500, "Steven_Lord" <slord(a)mathworks.com> said:

*snip*

>>> No. I am using a custom string consisting of mixed Gaussian and
>>> Lorentzian peaks.
>>
>> That tells us what type of curve you're fitting. It doesn't tell us what
>> function you're using to fit that curve. Without that information, the
>> best advice I can give you is to have the function that evaluates your
>> function as part of the curve fitting DISP, FPRINTF, etc. the parameters
>> with which it was called. Depending on what functions you're using,
>> there may be better approaches (like the OutputFcn option I suggested
>> above.)
>>
>>> I am using something like (and the number of terms is user determined):
>>>
>>> g1*exp(-((x-g2)/g3)^2) + l1*l2/((x-l3)^2+l2^2) + Gaussian 2 + Gaussian 3
>>> etc.
>>>
>>> I just want to find a way to access intermediate g1, l1, etc.
>
>
> I am afraid I do not understand (maybe I am being a little slow today).

The word "fit" was a little overloaded in this conversation, which didn't
help matters any.

> I am fitting some experimental data (not a curve). (There are no functions
> being called, or anything.)
>
> The string (fitfunctionstring1 in the code below) I mentioned about is the
> argument to fittype(). The generated fittype object from there is used to
> as an argument for the fit.

That's the information I was looking for -- you're using the FIT function to
identify the parameters that make the curve whose equation is given by your
string agree with the data you have.

> Here is the code fragment for better concreteness:
>
> ftype1=fittype(fitfunctionstring1,'coefficients',coefficientlist1,'independent','x');
> [fit1,gof1,output1]=fit(xdata1,ydata1,ftype1,opts1);
>
> xdata1
> and ydata1 are experimental data. opts1 is a structure that contains
> various fitting parameters.

Unfortunately, the FIT function doesn't have the same capability to call
something like the OutputFcn that some of the Optimization Toolbox fitting
functions do -- the best I can see is that you could specify the Display
option [assuming you're doing NonlinearLeastSquares fitting] but that won't
show you the fitting parameters. That sounds like a reasonable enhancement
request for FIT for you to submit, though -- and if you do decide to submit
that enhancement, please be sure to explain how you would use this option to
give the developers a clear picture of your use case.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com