ALGLIB forum
It is currently Thu Sep 21, 2023 2:52 pm

All times are UTC

Forum rules

1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Fitting 2-dimensional data with linear least squares fitting
PostPosted: Tue Jul 12, 2016 7:59 am 

Joined: Tue Jul 12, 2016 7:03 am
Posts: 1

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.

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.

 Post subject: Re: Fitting 2-dimensional data with linear least squares fit
PostPosted: Tue Jul 12, 2016 9:34 am 
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 891
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.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group