LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Levenburg Marquardt does not give same results as purchased Curve fitting software

I am trying to create a curve fitting application in labview that will loop through a number of formula and fit for each formula.  The user will then be able to select an equation based on the R-Squared value.  This is similar to an old software the we have called Table Curve.  However I am have trouble getting one formula to work properly.  What I did was enter a data set into Table Curve and let it do it's thing.  Attached is output from Table Curve. I have also attached a simple vi  that I can manual enter the data and formula string into.  I do not get good fitting results even if I enter the data from Table Curve.  Could somebody please have a look and offer some assistance?

 

Thanks

 

Terry.

Download All
0 Kudos
Message 1 of 6
(2,875 Views)

Double-check your X and Y inputs.

0 Kudos
Message 2 of 6
(2,865 Views)

Terry,

 

I cannot look at your VI now, but looking at the curve you posted raises some questions.

 

The curve shows only four points. The coefficient b is 5 orders of magnitude smaller than a or c.

 

Is this enough data to actually fit meaningfully to such an equation?

 

Is the data sufficiently precise to generate coefficients over 5 orders of magnitude and mean anything?  If one of the data point has 0.01% error, does that change the results?

 

What happens if you drop the b term out of the equation?

 

Lynn

0 Kudos
Message 3 of 6
(2,812 Views)

Thanks for the reply. I originally made this application using an older version of Labview. When I made the sample vi to post I am using a newer version of Labview and the X and Y input positions have changed. This still makes me feel kind of foolish for not picking that up.

 

However I still have a question.  As I have indicated I am trying to reproduce an older Curve Fitting program.    In the original program the x and y data is entered and when a button is clicked a list of models with corresponding R_Squared values is displayed in less than .1 second.  I am assuming that the software is going through all the models and determining which models work for the data set.

 

I have copied and formatted all the models from the software and  put them in a separate .txt file that my application uses to fill an array (~5000). Then in my vi I have  a loop  the goes through all the models and generates a list of models that does not produce an error, and has an R_squared value better that .99.  The time to do this takes about 30 seconds.  Do you know of anything that I might do to speed this process up?  Is there something in the original data that I can look at that will quickly eliminate models to use?

0 Kudos
Message 4 of 6
(2,805 Views)

What are the models? How many models are there? Do the models differ in the number of parameters? Do you have reasonable guesses for all the parameters?

 

Parsing a formula is relatively slow. You might want to do the VI model version. Fill a model folder with all desired models, then have the program list the folders, then iterate through all model references, fitting with each.

0 Kudos
Message 5 of 6
(2,791 Views)

 


@terry S wrote:

Thanks for the reply. I originally made this application using an older version of Labview. When I made the sample vi to post I am using a newer version of Labview and the X and Y input positions have changed. This still makes me feel kind of foolish for not picking that up.

 

However I still have a question.  As I have indicated I am trying to reproduce an older Curve Fitting program.    In the original program the x and y data is entered and when a button is clicked a list of models with corresponding R_Squared values is displayed in less than .1 second.  I am assuming that the software is going through all the models and determining which models work for the data set.

 

I have copied and formatted all the models from the software and  put them in a separate .txt file that my application uses to fill an array (~5000). Then in my vi I have  a loop  the goes through all the models and generates a list of models that does not produce an error, and has an R_squared value better that .99.  The time to do this takes about 30 seconds.  Do you know of anything that I might do to speed this process up?  Is there something in the original data that I can look at that will quickly eliminate models to use?


 

The X and Y inputs of the LM vi are a constant pain in the neck to me, so that is why I quickly spotted it.  The very first test I tried was to set the max iterations to 0 (you already created the constant for me), and this simply sets the best fit to your initial guess.  Then the issue was evident.

 

5000 Models will present a bit of a problem.  A few things to think about.  The model you show would be solved in less time by a linear Least Squares algorithm,  great for linear combinations of non-linear functions.  No derivatives or initial guesses to worry about.  Same is probably true for many of the models.  A common mistake is to see a non-linear function and assume that means you need a non-linear LS fit.

 

When you must use the LM method, try to use a VI (even if it means using a Formula Node), and if possible I strongly urge you to calculate the derivatives.  Probably the best way to get good results in the least amount of time is to provide good initial guesses.  This can be a challenge in an automated process.

 

Finally, the data set in your example is relatively small, if that is not the case I would suggest you decimate the data and do your trial fitting to a subset of the data.

0 Kudos
Message 6 of 6
(2,774 Views)