forum.alglib.net
http://forum.alglib.net/

Fitting 2-dimensional data with linear least squares fitting
http://forum.alglib.net/viewtopic.php?f=2&t=3758
Page 1 of 1

Author:  habo [ Tue Jul 12, 2016 7:59 am ]
Post subject:  Fitting 2-dimensional data with linear least squares fitting

Hallo,

I am currently looking for a c++ algorithm which is able to fit a 2 dimensional non linear function. c[] coefficients are the needed output.

f(x,y) = c[0] * exp(-c[1]/x) * y^c[2].

In the the documentation of alglib it is mentioned that this would be possible (and I think gnuplot is using the alglib and is able to do multidimensional fitting). Here is the excerpt of the alglib docu:


Linear least squares

Most fitting algorithms implemented in ALGLIB are build on top of the linear least squares solver:

- Polynomial curve fitting (including linear fitting)
- Rational curve fitting using Floater-Hormann basis
- Spline curve fitting using penalized regression splines
- And, finally, linear least squares fitting itself

First three methods are important special cases of the 1-dimensional curve fitting. Last method can be used for 1-dimensional or multidimensional fitting.
...
to solve multidimensional problem, then you can use general linear or nonlinear least squares solver. These solvers can fit general form functions represented by basis matrix (LLS) or by callback which calculates function value at given point (NLS).


But when I look in the examples and lsfit functions only 1d arrays for f(x|c) can be defined and none 2d arrays for f(x,y|c). Can someone please give an example for multidimensional multivariate regression with the alglib (for example: given above or f(x,y) = ln x + y^0.5 or ...). No multidimensional fitting examples exists, when I was looking at least.

ps.
I do not want to 'log' the function in order to create a polynomial function (spline), because f(x,y) is just a more simplified version which may consists of additional terms (ex.: f(x,y) = c[0] * exp(-c[1]/x) * c[1]/x * y^c[2] * y).

Thx in advance.

Author:  Sergey.Bochkanov [ Tue Jul 12, 2016 9:34 am ]
Post subject:  Re: Fitting 2-dimensional data with linear least squares fit

notation "f(x|c)" assumes that both x and c are vectors, not scalars. If you study signature of the function being optimized, you will notice that it accepts real_1d_array for x and c. So, you may use x[0] for "your x", and x[1] for "your y". You just have to specify correct model dimensions during creation of the optimizer object.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/