LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nonlinear Curve Fit and using static data

I am trying to fit data to a 2D function using the Nonlinear Curve Fit VI in Labview 8.2.1, but I would like to also include 2 parameters that I don't want to be optimized.  I cannot directly use constants since every time I run the fitting I need to change the 2 parameter values.  I tried to modify the example by Altenbach according to my own application in the link below. 
I think the problem is that I don't completely understand how to use the static VI reference with the Nonlinear Curve Fit VI?  It looks like there is a static data control that I could use to add additional parameters, but I am not sure?  I can get Altenbach's code to work if I change the function to something different, and even if I change the number of inital fitted parameters.  I just can't figure out how I can add parameters using a control that will not be optimized.  I can attach an example, but it is very similar to Altenbach's code except the function is different, and I am trying to add additional parameters that are not optimized.  Thanks for any help.
 
Kevin Baker 
0 Kudos
Message 1 of 11
(4,414 Views)
It looks like the Lev-Mar Nonlinear fit is using the VI ellipsoid003 to calculate what the optimal coefficients need to be.  ellipsoid003 is also being used to generate the surface at the user defined guess values, and it is used again with the coefficients found Lev-Mar to generate the best fit surface.

I'm not entirely sure what you are trying to do.  If you would like to calculate the best fit according to the coefficients already in his example, and add other coefficients that are not optimized, I believe you could do this by replacing ellipsoid003 with 2 VIs.  One for the Lev-Mar VI for optimization that does not take the extra two coefficients, and the other VI (used with the call by reference nodes) for generating the surface.

Trey B
Applications Engineering
National Instruments
0 Kudos
Message 2 of 11
(4,394 Views)
Thanks Trey.  I am sorry I didn't make it clear what I was talking about before.  I am attaching an example that will hopefully clarify what I would like to do.  When I try to pass the static reference to the Nonlinear Fit VI it says gives me a broken wire and says "function conflict".  I am assuming the problem is that I inserted another control to the VI when I wasn't supposed to.  I just don't know of any other way to pass data into the VI, and still have the Nonlinear Fit VI still work?  What is the "data" control in the Nonlinear Fit VI used for anyway?  It seems that that it was want I need, but I don't know how to use it?  Thanks again for any help.
Download All
0 Kudos
Message 3 of 11
(4,382 Views)

You are almost there. Don't use any other inputs in the model!

Simply convert the cluster with the extra paramters to a variant (in the main program) and feed it to the "data" input.

Inside the model, you need to convert it back to the cluster, using a diagram constant of the cluster as type (see image).

Message Edited by altenbach on 07-19-2007 10:23 AM

0 Kudos
Message 4 of 11
(4,376 Views)

Hi Altenbach,

 

I am new with labview and trying to use the nonlinear curve fit vi. I have a general question on this vi: what is the purpose of data wiring option? I understand it needs a reference model, but why data? I have read through the examples from NI and found most of them do not have data option wired?

 

Many thanks,

John

0 Kudos
Message 5 of 11
(3,641 Views)

Sometimes the model requires aditional information, so the data variant is just a generic mechanism to relay that information from the toplevel to the model subVI. Yes, for simple models it is typically not used but it is convenient to have it.

 

For example in this demo, I allow the user to select which paramters to fit and which ones to keep fixed during fitting (advanced model). If some parameters are held fixed, they are not available at the [a] input, but the model still needs to know them. In this particular case, the variant contains an array of all parameters (fixed and variable) and an array of indices indicating which ones to substitute with the variable parameters from [a] for the model calculation. Without that, you would need to write a gigantic number of different models (combinatorial explosion!), one for each possible combination of parameter selection, hugely complicating the code.

 

In another example, you could also place an enum into the variant and use a case structure inside the model to switch between differently coded algorithms (code A, code B, code C e.g.) for performance comparison. It could be a boolean to decide if it should explicitely calculate partial derivatives inside the model or let the fitting routines do it externally. (e.g. to validate if the partial derivative calculations are actually correct).

 

In some of my examples, I provide a huge kernel matrix needed for the model calculation. My data variant typically contains a cluster of 5-10 elements.

 

There is an infinite number of uses for the data variant input. 😄

 

(You could of course provide the extra data via global or shared variables or an action engine, but that makes it very dangerous because the values could be changed from elsehwere while fitting is in progress.)

 

 

 

0 Kudos
Message 6 of 11
(3,622 Views)

Thank you so much Altenbach for your comprehensive answer, which helps me understand this data variant quite a lot. And thank you for continuously working on this nonlinear curve fitting vi. It is so useful.

 

John

0 Kudos
Message 7 of 11
(3,606 Views)

hi Altenbach,

 

I have another question on this nonlinear curve fit. That is:

 

Covariance matrix and Hessian matrix

I found one disagreement between Numerical Recipes and LabVIEW help on covariance matrix definition in Nonlinear Curve Fit VI.

 

In Numerical Recipes, the covariance matrix C is the inverse of the curviture matrix Alpha and Alpha is defined as half of the Hessian matrix D. In Numerical Recipes, D is defined as the second derivative matrix of the chi^2 merit function, at any parameter. Therefore, C = 2 D^-1.

 

On the other hand, LabVIEW help gives an equation C = (1/2) D^-1. The definition of D is given by the help: "where D is the Hessian of the function with respect to its parameters". I feel the definition of D in LabVIEW is not quite clear.

 

 

Could you help us on this factor of 4 difference on this covariance matrix definition?

 

 

Many thanks,

John

0 Kudos
Message 8 of 11
(3,543 Views)
Sorry posting by phone so I cannot check my notes. All i know is that using the covariance "as is" to calculate parameter errors gives the correct NIST certified results. Search the forum for the old discussion.
0 Kudos
Message 9 of 11
(3,539 Views)

Thanks Altenbach. I will tried to find them when I get some time.

 

John

0 Kudos
Message 10 of 11
(3,529 Views)