LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty with Levenberg-Marquardt Fitting (yes, another one :)

Hey guys,

I've been working for a couple days with the Levenberg-Marquardt "Nonlinear Curve Fit.vi" in Labview 8.20.  I'm reasonably familiar with Labview, but I'm pretty new to fitting and statistics in general so I hope you guys can help me out.  I read through the other posts on this vi, but didn't see my particular problem there.

I am trying to fit my experimental data with the function Y(x) = (k1+k2*x^m)*(1-x^n); so there are 4 parameters (k1, k2, m, and n).

I originally was doing my fitting in a graphing program called SigmaPlot that also uses the Levenberg-Marquardt method for fitting.  With SigmaPlot, I get a pretty good fit (R^2 = 0.9999) in only 17 iterations with reasonable initial guesses.  I wanted to move the analysis to Labview since there is a lot of data manipulation that occurs before the fit that I would like to automate instead of doing it manually in spreadhseet programs.  But when I try to perform the same fit in Labview, the best fit I get is R^2 = 0.990 and that is starting with the optimum values from the SigmaPlot fit and I have to have several hundred iterations to get to this fit.

So I'm wondering what the differences are between these two programs.  I figure, even if both are using the same method, there are probably still some differences in the way the method is implemented.  The only options within the SigmaPlot program are StepSize and Tolerance, which I have set to 0.1 and 0.0001 respectively.  I have tried adjusting the tolerance in Labview, but it doesn't seem to make much difference between 1E-4 and 1E-12 except for run time to get the same fit.

I've attached a zip with both a simplified form of my vi and a pdf image of my fit from SigmaPlot in case that helps.  I saved the data into the array control to make the example easier.  I have tried both the function as a formula string and as a vi and that didn't seem to make any difference, but at least gives me a little more info coming out of the fit.

So I'd appreciate any suggestions you guys have.  Thanks,

-Tim
0 Kudos
Message 1 of 8
(3,467 Views)


@PolymerTim wrote:
I am trying to fit my experimental data with the function Y(x) = (k1+k2*x^m)*(1-x^n); so there are 4 parameters (k1, k2, m, and n).

Your formula is incorrect, it should be Y(x) = (k1+k2*x^m)*(1-x)^n; Also note that you don't need the FOR loop.

 

See for example equation (1) in http://ieeexplore.ieee.org/iel5/6144/26776/101109TCAPT2005853171.pdf

🙂

Message Edited by altenbach on 10-04-2007 09:05 AM

0 Kudos
Message 2 of 8
(3,451 Views)
Your formula cannot work, because the parameters are highly correlated and there is an infinite amount of equally good (actually bad, compared to the good formula :)) solutions.
 
I typically convert the covariance matrix into a correlation matrix. With your formula, many offdiagonal elements are very close to 1.
0 Kudos
Message 3 of 8
(3,445 Views)
Arrghh I can't believe I missed the typo in the equation.  That completely fixes the differences between the Labview fit and the SigmaPlot fit.  Well, at least it was a simple problem to solve 🙂  Thank you very much.
 
Thanks also for pointing out the unneccessary For Loop.  I guess that's what I get for just starting with the template and not thinking about it too hard.
 
You did find the exact model I am using.  I am do an isothermal cure kinetics study on a system (epoxy/amine) that is known to be autocatalytic.  For this reason, two k's (k1 and k2) are used as opposed to the simpler model: I can't find it now, but I think it was Y(x) = k * x^m * (1-x)^n.
 
Can you tell me how to get the correlation matrix from the covariance matrix?  I am generally familiar with the correlation matrix, but not with the math to get it from the covariance.  Maybe this would be the tool I need to try some of the different models available and find one that fits my data with less correlated parameters.
 
Thank you again for your help.
 
-Tim
0 Kudos
Message 4 of 8
(3,426 Views)

 


@PolymerTim wrote:
Can you tell me how to get the correlation matrix from the covariance matrix? 

I use the following (watch out for the autoindexing).

Message Edited by altenbach on 10-04-2007 11:26 PM

0 Kudos
Message 5 of 8
(3,420 Views)


@altenbach wrote:



And notice that you can delete the inner FOR loop on the right without any change in functionality. 😄
0 Kudos
Message 6 of 8
(3,402 Views)
Altenbach, why do you convert the covariance matrix into a correlation matrix?  For as much as I've been working with different fitters later, I really don't understand much about the statistics/theory.  Is there a good reference you'd recommend (web, book, whatever)?  Thanks!

PS - PolymerTim, are you at Wisconsin?

Message Edited by l1k on 10-05-2007 08:42 AM

0 Kudos
Message 7 of 8
(3,397 Views)
Thanks again altenbach.  I've got the correlation matrix working now and I guess that means I have to get back to the science part of my work.  I do enjoy these little excursions into programming Smiley Very Happy

l1k, I'm actually a grad student at Case Western Reserve University in Cleveland, OH.

-Tim
0 Kudos
Message 8 of 8
(3,380 Views)