10-23-2019 06:52 AM
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
Solved! Go to Solution.
10-23-2019 07:33 AM - edited 10-23-2019 07:36 AM
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!
10-23-2019 08:01 AM
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
10-23-2019 08:47 AM
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
10-23-2019 08:49 AM
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
10-23-2019 09:14 AM
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"?
10-23-2019 09:24 AM
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
10-23-2019 09:46 AM
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.
10-23-2019 10:53 AM
10-23-2019 11:18 AM
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.