[GRASS-dev] New module v.surf.trend but with external dependencies and ccmath problem

Hi all!

I wrote new GRASS module, v.surf.trend I think it could be useful.

v.surf.trend allow to fit set of points to trend surface at any degree of polynomial (in fact if more than 6 has any sense?)
Module v.surf.trend is ready to use (there remained some cosmetics) but is based on external dependencies: GNU Scientific library. It uses linear multifit with singular value matrix decomposition (gsl_multifit_linear). As I understood above this is not especially acceptable.

According some advice I decided to use function from ccmath and here is the problem.

There are two approach which allow to use multifit in ccmath:

function qrlsq which uses qr decomposition to solve linear least squares fitting and function lsqsv with singular value matrix decomposition

I assume that results shall be similar to that from gsl. In fact it is absolutely not.

I prepared testing version of the module. Is someone can help it is here: http://heretic.livenet.pl/heretic/v.surf.trend.tar.gz
(may be some problems with server)

To compile it gsl is necessary

This module performs calculating trend coefs with three methods:

1) gsl_multifit_linear gives perfect result up to 16 degree polynomial (and probably more but I stopped testing here). These results are in conicidence with result of trend from ArcGIS spatial analist

2) ccmath qrlsq gives perfect result to 3th degree of polynomial and good result on 4th degree but above (5 and more) coef are completely different from gsl and results are similar to good but with artifacts (see output)

3) ccmath svdlsq gives completely wrong results if degree of polynominal is greater than 2

if someone can help there only calc.c file is important: ccmath.c has function from ccmath library, vector.c process input vector file there is no help however and there are some issues like lack of 3D and WHERE support

or mabye there is different way to solve that problem. In general it would be nice to create that module without addational dependency

regards
Jarek

BTW:

there are two flags in current version -r and -s with no flag output is from gsl with -r output is from qr matrix reduction with -s flag svd matrix reduction

Hi Jarek,

Are you rescaling the coordinates before powering them? I see that you are
making some conversions in main.c, but they may not be enough. Try using the
unit square 0,1 instead, for example (x_i - min(x))/(max(x) - min(x)) or
something like this. Or see dscale() in the recommended R package
spatial/src/krc.c around line 452, which uses -1, 1 for the same reason, for
a code example.

Roger

-----
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/New-module-v-surf-trend-but-with-external-dependencies-and-ccmath-problem-tp5003754p5004442.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

Roger Bivand pisze:

Hi Jarek,

Are you rescaling the coordinates before powering them? I see that you are
making some conversions in main.c, but they may not be enough. Try using the
unit square 0,1 instead, for example (x_i - min(x))/(max(x) - min(x)) or
something like this. Or see dscale() in the recommended R package
spatial/src/krc.c around line 452, which uses -1, 1 for the same reason, for
a code example.

Roger

-----
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

Hi Roger!!
unfortunately not. The same problem. OK to polynom 2 for all three method.
Ok for polynominal 4 for gls and qr decomposition
Ok only for gls with polynom over the 5.

I think it is a problem of matrix decomposition and additional parameter called "balance" in gsl which is still out of my knowledge.

The funny is that solution I proposed is as very simple that probably it should not work, except that it work for gls library! The only problem is that it is external dependency (for Grass as far as I know not for R)

thanks for suggestion. I will try in that way also with krc

Jarek