Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

02-04-2016 08:38 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi,

I have a set of data: a set representing the independent variable and a set representing the dependent variable. I need to find the minimum number of cubic curves (find their coefficients) that reduce the mean square error less than a given tollerance. If the tollerance is higher than given one with 17 segments, then I need to throw an error.

Have you an idea which function blocks I need of?

I could use General Polynomial Fit VI with order 3 and its default method to check the residual. If the residual is higher than the given tollerance, then I could try to use two cubic curves and test them on different starting and ending points until the residual is less than the given tollerance. If the tollerance is not guaranteed, I add another curve and I test again the fitting as above. Iteratively until the residual is less than the given tollerance or until I would need to add the 18th cubic curve.

If there were something ready, I would appreciate.

Thanks.

Solved! Go to Solution.

02-04-2016 02:14 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Can you clarify a bit more about continuity and smoothness at the boundary between adjacent cubics? Are the individual cubics required to meet at the same point? Are the first derivatives required to be the same at the boundary?

-Jim

02-04-2016 02:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Maybe you could use cubic spline fit and look at the residual as a function of the e.g. the balance parameter.

02-07-2016 10:37 AM - edited 02-07-2016 10:38 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

The cubics are required to meet at the same point, but the first derivative can be discontinued. So the spline is not required.

My final algorithm is that:

1) Find first cubic curve with General Polynomial Fit VI, inserting 5 points [X,Y].

2) Subtract calculated Y from real Y to find error. If the absolute value of the error is greater than tollerance or there aren't more point, then go to step 3), in the other case, return to step 1 inserting a new point after the points already used.

3) Save the coefficient of the curve calculated on step 2, then reject all the points used with exception of the last point that cause the error greater than the tollerance. If there are more points and the curves calculated are less than 17, then return to point 1, in the other case exit.

There is a better way? Where I can find the explanation of the fitting algorithms?

Thanks.

02-09-2016 08:26 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

There is some numerical error in Labview Fitting Libraries, so I decide to create my own algorithm.

There is the algorithm attached.

The result is wrong. What is wrong in my VI? With four fitting points the numerical error should be very very low

Here the theory behind:

https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)#Using_a_quadratic_model

02-09-2016 01:16 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@Fabiobonelli wrote:There is some numerical error in Labview Fitting Libraries,

Can you be more specific?

Here are two possible alternatives using LabVIEW primitives. Seems to give the correct result.

02-09-2016 01:38 PM - edited 02-09-2016 01:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Also, your x-range is far from zero and over a relatively narrow range. This can cause problems with conditioning. Your data is probably OK, but this is something to consider if the data is even more extreme. You probably would get more accuracy of you would re-center on an average x value and correct for the shift later.

02-10-2016 04:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Please, can you test your VI adding another point to the four presented?

X = -6453

Y = -266

Check the residuals.

Thanks.

Solution

Accepted by topic author FabioBone

02-10-2016 03:37 PM - edited 02-10-2016 04:25 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@Fabiobonelli wrote:Please, can you test your VI adding another point to the four presented?

X = -6453

Y = -266

Check the residuals.

Thanks.

Did you even read my reply? You have a serious conditioning problem because the data is over a narrow range far from zero. For example -6500^3 is smaller than -2E11, i.e. a value that is many (many!) orders of magnitude different than the constant term (1). The resulting linear algebra problem is very ill conditioned and just blindly stepping on the gas pedal is ill adviced here.

This is not a problem with the LabVIEW implementation, but a __fundamental flaw__ that you would encouter equally (or even worse) if you would do your own math. No way around it. (See also)

My recommendation was to remove the offset from X and add it later again. Now things work correctly. (note that fitting to a second order polynomial still works without the tweak).

Try the attached and see for yourself.

02-11-2016 07:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I haven't got your warning. Using reconditioning offset, my algorithm works very well. I was searching how Labview fits the data and I didn't catch the error in input data.

Thank you.