gnudatalanguage / gdl

GDL - GNU Data Language
GNU General Public License v2.0
274 stars 61 forks source link

SVD fit in GDL? #1290

Open AstroArtie opened 2 years ago

AstroArtie commented 2 years ago

I just found out that IDL's implementation of SVD fitting is based on a Numerical Recipes (NR) routine, that seems to be compiled (probably Fortran) code. I understand that NR routines cannot be included in the official GDL package, but if there is a relatively simple way to include SVD-fit, would it be possible to post instructions? Thanks for all your work!

alaingdl commented 2 years ago

Yes you are true : we cannot copy code from NR. And we had requests for that since a while. Let's see what we can do. Maybe Eigen3 or the GSL may help ?

GillesDuvert commented 2 years ago

Eigen:: has the BDCSVD() algorithm. GSL has gsl_linalg_SV_decomp etc. Speed should be on the Eigen:: side I presume. See also code available in https://www.codeproject.com/Articles/1268576/Singular-Values-Decomposition-SVD-In-Cplusplus11-B OTOH, a conversion of the NR (fortran or C) code to IDL syntax ( in C: 3 functions, ~300 lines of code) should be considered, as it can be done by anybody with a minimum of IDL knowledge, not C++. The problem with using directly NR code is that the code (i.e., its TEXT) is copyrighted.

alaingdl commented 2 years ago

1/ (to be sure) are you speaking on SVDFIT() ?! 2/ could you provide an example (not from IDL doc.) we can use for test suite ?

Thanks

A.

GillesDuvert commented 2 years ago

above comment by @alaingdl is a question to @AstroArtie I presume.

AstroArtie commented 1 year ago

@alaingdl : Sorry for looong delay - this part of my work got a bit side-tracked. Here is the requested, simple example computed with IDL's svdfit:

> for i=0, 9 do print, i, x(i), y(i), yerr(i)
       0       3.6661002       2.7571447     0.054864578
       1       3.6817800       2.7542315     0.061871536
       2       3.6704472       2.6392808     0.059556611
       3       3.6970126       2.9625556     0.069721878
       4       3.6811890       2.7740209     0.059141863
       5       3.6755459       2.6536186     0.060683209
       6       3.6936651       2.9905055     0.066833146
       7       3.6999013       3.1468284     0.066083357
       8       3.6954474       2.9688542     0.067633145
       9       3.6816563       3.0195100     0.066223271
> print, svdfit(x, y, 2, measure_errors=yerr)
      -40.884174       11.874856

Your help is most appreciated! Cheers, Regner

Danamir commented 5 months ago

Did you finally come to a solution to run SVDFIT in GDL ? We just encountered the problem on our project.

GillesDuvert commented 5 months ago

Hm, this issue was, I'm afraid, forgotten. :blush: In the meantime, could'nt you use CURVEFIT instead (or TNMIN). TNMIN is available at https://pages.physics.wisc.edu/~craigm/idl/down/tnmin.pro

DamienAlbert commented 5 months ago

Our team successfully replaced the svdfit by a poly_fit call, with the same results in our specific case.