LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

non linear regression fit - syntax for LOCATIONS definition

Solved!
Go to solution

Hello, I am using non linear regression fit using the pre-defined vi called curve fitting. 

Basically, I have no problem to set this fitting, and get some consistent fitting coefficients. 

However, the error criteria is based on the number of iteration, usually 200. OK, it leads sometimes to error due to the maximum number of iteration is not enough to converge to the solution. I understand very well this criteria. If we set 200, this is because we want to go fast. I admit that setting 1000 rather than 200, can solve the problem. I already tested and OK, it is better. But the main concern of my message, is that I want to know the correct syntax to define the LOCATIONS in this curve fitting. What I cannot really understand is that I though that LOCATIONS are the initial conditions, but this is not the case, because initial condition can be defined by opening the curve fitting vi. However, there is a input called LOCATION but I don't understand how to use it correctly, and how to define the syntax of LOCATION. When creating a control, I get just a DBL. But I think it should be more complex. 

My fit is f(x) = a*exp(-x/b)+c

I know the range of b, and I don't care so much on a and c. 

In thee front panel, I would like to define the initial parameters of fit, and I have the opportunity to create a control on the LOCATIONS, but I don't understand what is LOCATION, and I don't know the syntax. 

Basically, I would like a kind of machine learning fitting, based on learning around the b coefficient range that I would like to define. 

Sorry, it is not clear. 

What are locations ? What is the syntax to define Locations ? 

What is the difference between location and initial conditions ? 

Some attached images of the curve fitting vi that I am using. 

0 Kudos
Message 1 of 8
(2,046 Views)

You need LOCATIONS if your data is not spaced equally in x. (signals have equal spacing with defined d0 and dt and once you define locations, d0 and dt is ignored instead. Why do you only define dt? Is d0 zero?)

 

Can you explain your use of the term "error criteria"? It's not obvious!

 

I would recommend to get away from the express VI as quickly as possible. there are better ways to do all that in the fitting palette.

 

Also, your data does not really look like an exponential at all. Don't you have a better model or better data with less noise?

0 Kudos
Message 2 of 8
(2,019 Views)

In any case, such a simple function should converge within significantly fewer than 200 iterations. Can you attach a simple VI containing your data?

 

For further reading, have a look at my interest group for nonlinear fitting. Maybe it can give you some ideas. (There is even the exponential fit VI  that should work once you allow an offset but I would stick with my example 😉 .)

0 Kudos
Message 3 of 8
(2,017 Views)

Here is a set of data for fitting. 

We indeed do not want to implement the basic exponential fitting but the non linear regression model, with the possibility to have a CONTROL on the number of iteration. The express vi prevents doing that during the RUN mode. So I tried to make it from the express vi, but it was not successful. Still I could not understand why, so I just wasted my sub-vi and tried to work with the express vi, by defining a number of iteration that might reduce the error events ... but basically, I would need about 5000 iteration sometimes. In fact, why I cannot get good fit with 200 iteration, is that the signal is a little  bit changing with time on the oscilloscope. This is due to the sample under test, and precision of alignment ... I cannot describe too much. Sorry for that. But I am doing a dynamic fit from each data acquisition from thee oscilloscope, every ~1sec ... the while loop elapsed time depends strongly on the express vi performances. 

 

The error criteria is simple : On the express vi, there is error in/out. I pick up error out, and I read the Boolean status. If it is True, there is an error, then I exclude the fit coefficients from my stats. But the main error is coming from "number iteration exceeded ..." and we use 200 iterations which is quite OK, but sometimes, not enough. 

 

About signals : it is coming from MSO64 oscilloscope, so the dt and x-axis spacing is OK. I do not care about t0 in the waveform. I think I don't need to use Locations, according to you valuable and clear description of this parameter. (it was not clear on the labview help). 

 

0 Kudos
Message 4 of 8
(1,996 Views)

Thanks for the data. I assume that the first column is time. What are the other two columns?

0 Kudos
Message 5 of 8
(1,966 Views)

You have not attach your code with the express VI and I am not in the mood to recreate it. The simple exponential fit works just fine, though. (Works equally well for the unscaled data in the second column)

 

As you can see from the difference at shorter times, you data contains at least two exponentials. One fast and one slow. Did you even look at my link? There is even a presentation from a few years ago (NI-Week 2017). Suitable solutions are right there!

 

altenbach_0-1646591648852.png

 

0 Kudos
Message 6 of 8
(1,960 Views)
Solution
Accepted by arienai

Using my old exponential fitting models, you data seems to fit well to two exponential and less well to a single exponential. Both converge in well under 200 iterations if the parameters guesses are reasonable.

 

See if the attached code make any sense. Modify as needed.

 

altenbach_0-1646598364970.png

 

Here is the model:

 

altenbach_2-1646598414028.png

 

 

 

0 Kudos
Message 7 of 8
(1,950 Views)

Dear Christian, thank you very much both for your good mood today, for your demo, and for the PDF, which are all extremely instructive, well documented, and clear. Due to the situation in EU at this moment, please let me several days/weeks before trying.

0 Kudos
Message 8 of 8
(1,940 Views)