LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Testing of different polynomial fits

Solved!
Go to solution

Hello,

 

I would like to test different polynomial fits (different order, from 1-10) on my curve, and then to choose the one with the lowest mse value.

 

Is there any efficient way to do this without creating a new loop with General Polynomial Fit vi (every time with different polynomial order)?

 

Also, is there any way to write the polynomial equation from the coefficients which are in array?

 

Kind regards and thank you for your help.

 

Anna

 

0 Kudos
Message 1 of 15
(2,377 Views)

Hi Anna,

 


@Kikiriki wrote:

Is there any efficient way to do this without creating a new loop with General Polynomial Fit vi (every time with different polynomial order)?

Also, is there any way to write the polynomial equation from the coefficients which are in array?


A loop is probably the most efficient way to repeat a task several times. Why do you think you need to avoid "one more loop"?

Yes there is a way to evaluate the polynomial expression: the function is called "Polynomial Evaluation"…

 

I don't think the "lowest mse" will be a good choice for the polynomial order: most often higher order polynomials fit better to the given data points. The more interesting fact is the behaviour of the polynomial between your data points!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(2,356 Views)

Given n measurements y(i) at distinct values of x(i), you can find a polynomial of degree (n-1) that passes through all of the points!  This is (almost always) not the best model for describing the data.

 

I assume you are familiar with the expression for Standard Error of the Mean, where you divide a sum-of-squares by (n-1), with the "-1" in there because you are using (as part of your computation) the mean, a number derived from the data.  If you take "Stats", you'll learn that this adjustment makes the SEM an unbiased estimator.

 

If you fit a model with m parameters, one technique I've seen is to divide the squared residuals by the "degrees of freedom", which is n-m, number of points minus the parameters of the model.  But the best judge is to look at the data, look at the fit, and "use common sense".

 

Bob Schor

0 Kudos
Message 3 of 15
(2,341 Views)

Hi Bob,

 

I know the Polynomial fit is not the best model, but i need to find a model which is the most universal, since my data is not always the same, and the question was how to test more polynomial fits with different order with the aim to find the one which is the best.

I am trying to develop an approach in which I will import my experimental data and find the best fit automatically, but I am not so experienced in LV and I usually use the approach to create a loop, put data from two arrays by using tunnels, then put Polynomial fit. vi inside and set the order. By this approach, I will have 10 loops with polynomial fits of different order, which is a lot, and I dont know how to make it more simple.

 

Thank you for your help with evaluation, it will be better to use some other parameter than MSE, I was also considering that.

 

Kind regards,

Anna

0 Kudos
Message 4 of 15
(2,328 Views)

Dear Gerd,

 

Thank you for your advices.

Is it possible that after I obtain coefficients of the equation, I write an equation out of them?

 

Kind regards,

Anna

0 Kudos
Message 5 of 15
(2,324 Views)

Hi Anna,

 


@Kikiriki wrote:Is it possible that after I obtain coefficients of the equation, I write an equation out of them?

Sure: a polynomial is the sum of (p_i * x**i)…

What kind of equation do you need to "write"?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 15
(2,315 Views)

Hi, Gerd,

 

When I obtain the polynomial coefficients, they are in the form of 1D array. Is it possible that the program writes the equation, or I have to introduce parameter by parameter within the formula node.

I would like to generate numbers according to the fit which I obtain, but since my fit changes, and sometimes is polynome of fifth, sixth or some other order, it is very complicated to every time index the array, introduce the parameter into formula node and generate numbers according to the function.

 

Kind regards,

Anna

0 Kudos
Message 7 of 15
(2,308 Views)
Solution
Accepted by topic author Kikiriki

Search for a VI called Polynomial Evaluation. You give it your x (but confusingly they call the input a),  and your array of coefficients.  It gives you the result.

Message 8 of 15
(2,294 Views)

Hi Anna,

 

did you read my answer in message#2 carefully?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 15
(2,282 Views)

Use caution.  Your number of data points must be much greater than the order of the polynomial.

If not, you can results that are a really good fit, but meaningless.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 10 of 15
(2,270 Views)