Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Least Squares C# library [closed]

Tags:

c#

math

numerical

I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me.

I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2 etc. constant values or the calculated values "predictions".

Note: I am using Least Squares to create some forecasting reports for disk usage, database size and table size.

like image 904
Robert Wilkinson Avatar asked Dec 08 '08 20:12

Robert Wilkinson


People also ask

What is the least squares coefficient?

The least squares principle provides a way of choosing the coefficients effectively by minimising the sum of the squared errors. That is, we choose the values of β0,β1,…,βk β 0 , β 1 , … , β k that minimise T∑t=1ε2t=T∑t=1(yt−β0−β1x1,t−β2x2,t−⋯−βkxk,t)2.

What are least square means?

Least Squares Means can be defined as a linear combination (sum) of the estimated effects (means, etc) from a linear model. These means are based on the model used. In the case where the data contains NO missing values, the results of the MEANS and LSMEANS statements are identical.

What is the meaning of least squares in a regression model?

The method of least squares is a standard approach in regression analysis to approximate the solution of overdetermined systems (sets of equations in which there are more equations than unknowns) by minimizing the sum of the squares of the residuals (a residual being the difference between an observed value and the ...


3 Answers

Here is a link for C# code on to do exactly this: http://www.trentfguidry.net/post/2009/08/01/Linear-Regression-of-Polynomial-Coefficients.aspx

Good luck!

Edit: Apparently the above link is broken. I made another solution awhile back: http://procbits.com/2011/05/02/linear-regression-in-c-sharp-least-squares/

like image 93
JP Richardson Avatar answered Oct 19 '22 08:10

JP Richardson


In the general case you want an "optimizer" or "mimimizer". See http://en.wikipedia.org/wiki/Optimization_(mathematics)#Solvers for some exmples. I see that the first link (http://en.wikipedia.org/wiki/IMSL_Numerical_Libraries) claims to have c# support.


Edit: For the limited use that you propose (linear or quadratic polynomials), you could just go to any copy of Numerical Recipies, grab a straight ahead implementation, and translate to your language. A general minimizer is overkill.

But note, also, that polynomials may be poor predictors.

like image 20
dmckee --- ex-moderator kitten Avatar answered Oct 19 '22 08:10

dmckee --- ex-moderator kitten


You can check library form ALGLIB under GPL licence 2.0. They have source code for C#, C++,...

http://www.alglib.net/interpolation/leastsquares.php

like image 36
Vlad Bezden Avatar answered Oct 19 '22 09:10

Vlad Bezden