2D weight function approximation

I need to approximate a table-specific 2D function similar to the one

x0 y0 x1 y1 ... xn yn 

for each point I have a "weight" (standard error for this measure). I need to write a function like this:

 typedef std::vector< double > DVector; void approximate2D( const DVector & x , const DVector & y , const DVector & weights , double newMeasuredX , double newMeasuredY , double newMeasuredWeight , double & outApproximatedX , double & outApproximatedY ); 

to get one value (outApproximatedX; outApproximatedY) depends on the previous values ​​and the new measured value.

RMS error (RMS) should be used as follows: if the RMS error is minimal, then the desired function should approach this point, if the RMS error is maximum, then this point should be used with a minimal contribution.

The approximation should be linear (I think), since I know that the desired function is a straight line.

Googled about half a day and did not find any offers.

Thanks.

+4
source share
3 answers

To minimize the maximum squares of the nearest squares to the straight line ax + by = r, you cannot use matrix equations, since the problem is no longer linear.

The distance to the line can be determined as follows. Then the function you want to minimize is f ( a , b , r ). This task is somewhat simplified when a 2 + b 2 = 1.

Concepts

If you expand it, it will become quite complex. I managed to break it down and simplify it a bit.

Calculations, calculations, calculations!

To calculate this from many points (O ( n 2 )), it can slow down. However, there is an easy optimization. Instead of calculating the amounts over and over, you can store partial results:

Something that looks like an algorithm

Here & sigma; variables are batteries for general terms. Each time you want to add another point to the calculation, you update 9 variables and use them to calculate a, b and r, as before.

+3
source

What you want is a space filling curve for either the Hilbert curve or the Peano curve. Sfc is a good approximation of a 2D or XD grid.

+1
source

Thanks a lot for MizardX. Great help. Here is what I wrote (if anyone needs it :))
http://liveworkspace.org/code/815e2cc0810ab8ef14951252cca3fbbf

PS I can not vote for MizardX (no reputation). Can anyone do this for me?

+1
source

Source: https://habr.com/ru/post/1344373/


All Articles