From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nonlinear Curve Fit Error 20068?

Solved!
Go to solution

Trying to do a simple 3-exponential decay nonlinear curve fit.  I have a copy of this working in other VIs but it doesn't seem to work in this VI.  I'm using Altenbach's "scalablemultiexponentialdecay" as a model VI/template.  The data I'm trying to fit is a simple series RC decay, yes I realize that shouldn't have 3 exponential components, it's just model data.  I am able to fit it with the built in Exponential Fit function from the Math palette, however that only works if the parameter bounds input is wired and with rational constraints.  However, I get an error on the nonlinear curve fit that I don't understand (picture is attached) indicating that an INF or NaN is getting in the parameters.  I don't see where that's happening...

 

Any help or questions is appreciated.

 

3ExpDecay Block Diagram.png

3ExpDecay Front Panel.png

0 Kudos
Message 1 of 7
(5,052 Views)

Edit:

I tried to implement the fit with the 'formula string' version of the nonlinear fit VI, same error.

 

3ExpDecay Block Diagram2.png

 

0 Kudos
Message 2 of 7
(5,038 Views)
Well, are there invalid values getting onto the parameters?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 7
(5,034 Views)
Solution
Accepted by topic author afh

I didn't think so, just 0s for the 2nd two exponentials.  But, when I replace all the seededes guess with the same outputs as the single exponential fitter, it converges without error.   I guess I didn't realize it was that sensitive.  Thanks.

0 Kudos
Message 4 of 7
(5,023 Views)

Next time, try not to leave my name in a diagram comment of the posted model. I have nothing to do with that code! (My code is typically scalable so the model does not need to know the number of exponentials!)

 

And yes, if a single exponential gives you a reasonable fit, a model with three exponentials will most likely not produce anything meaningful. 😉 That's to be expected.

 

Also, if you start out with amplitudes of zero, the partial derivatives for all other parameters of that component is also zero, of course because the function does not change no matter what the decay is. With an amplitude of zero, any decay from -inf to +inf gives you an equally good fit. 😄

0 Kudos
Message 5 of 7
(5,008 Views)

I started with your scalable model, then stripped the scalabilty out of it in case that was causing trouble.  I appreciate your scalable model, it's one of the only comprehensible examples I can find about the nonlinear curve fit.  Since you're in the thread, what is the "data" input to the Nonlinear Curve Fit VI, where in your scalable example you take your Guess Cluster and convert it to a variant?  Is this important?  Sometimes I wire it to the NCF VI, sometimes I don't. 

 

I find a multiexponential fit to single exponential data tends to give me an accurate fit but with the amplitudes divided by the # of exponentials and the time constants the same.  

 

I don't know enough about the LM fit to know what the partial derivatives do.

0 Kudos
Message 6 of 7
(4,996 Views)

@afh wrote:

I started with your scalable model, then stripped the scalabilty out of it in case that was causing trouble..


What kind of trouble? Properly used, it should work just fine. 😄


@afh wrote:

what is the "data" input to the Nonlinear Curve Fit VI, where in your scalable example you take your Guess Cluster and convert it to a variant?  Is this important? 


It is important if the variant data is actually used inside the model. Look at the output of "variant to data". Does it go anywhere?  Else it is irrelevant. My model requires it to allow the ability to fit for a subset of all parameters, leaving some untouched by the fitting procedure. Do you understand the code at all?


@afh wrote:

 

I find a multiexponential fit to single exponential data tends to give me an accurate fit but with the amplitudes divided by the # of exponentials and the time constants the same.  

 


This is pointless, because you have near infinite correllations between the amplitudes. Basically you could be adding two identical exponentials, each with amplitude=0.5. The exact same curve could be reproduced with identical fit quality by making one amplitude 100001 and the other amplitude -100000. Don't fit for more parameters than the data represents! The fitting could even wander towards [Inf+1,-Inf] for the two amplitudes, causing it to blow up on the way. If two parameters are correlated, the change in one parameter can be compensated fully by a change in another parameter, making the result not unique.

 

This is the main reason my original code was scalable to work for any number of expoentials. Start with one, then two, etc. until the fit quality is within the error of the data. Don't just throw a overparameterized model at it.

 

In any case, don't leave diagram comments that are no longer appropriate. I am only responsible for the code I write myself and I don't want to take the blame if somebody randomly chops up my code, but leaves my name it. That's not nice.

 

 

 

 

0 Kudos
Message 7 of 7
(4,986 Views)