ppolabs / jlinda

jLinda - Java Library for Interferometric Data Analysis
9 stars 5 forks source link

Inconsistencies between polyfit and polyval methods of PolyUtils class #10

Open pmar opened 11 years ago

pmar commented 11 years ago

Description

There is (very annoying!) inconsistency between methods for fitting and evaluation of polynomials, in PolyUtils class.

For the correct estimation, and evaluation of polynomial, x, and y variables have to be reversed, either in fitting or evaluation of the polynomial. (See example).

Example of problem

If I fit polynomial using for example this call:

double[] coeffs = PolyUtils.polyFit2D(x, y, z, degree);

to correctly evaluate it for some point (x1,x2), I have to call:

polyval(y1, x1, coeffs)
pmar commented 11 years ago

Seems like that most of the fitting/eval methods of PolyUtils class are affected by this, although I tested and experienced this only in 2D fitting/eval.

Most likely this inconsistency is because how the A matrix in fitting (estimation) step(s) is designed, and how the coefficients are looped through in the evaluation method(s).

pmar commented 11 years ago

For live code example see: https://github.com/ppolabs/jlinda/commit/a407316a5a598e3ffbd4a0c6cda2525286a651ca