Talk:Polynomial regression: Difference between revisions

no edit summary
No edit summary
 
(6 intermediate revisions by 5 users not shown)
Line 1:
== which norm to be used? ==
 
In which norm the approximation has to be done? Euclidean? C-norm? The basis seem to be x<sup>n</sup>? --[[User:Dmitry-kazakov|Dmitry-kazakov]] 14:10, 4 June 2008 (MDT)
 
Line 7 ⟶ 9:
==About fortran==
It is quickly coded, and while trying to remember things. It works anyway, but I suppose there's a better way. the method I've followed is straightforwardly from [http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html Wolfram.com] --[[User:ShinTakezou|ShinTakezou]] 23:58, 18 December 2008 (UTC)
 
----
 
Good work with the Fortran routine. However, the scaling of the independent variable is missing without which the fitting will fail in many cases. For this purpose one needs the ''mean'' and ''standard deviation'' of the independent variable (vx in the code). Now scale vx to vxcopy and do everything using vxcopy. The code should be changed as follows. I am using this modified version for big applications in my work.
allocate(ipiv(n))
allocate(work(lwork))
allocate(XT(n, size(vx)))
allocate(X(size(vx), n))
allocate(XTX(n, n))
vxcopy = vx !=== make a copy of the independent variable
mu = stdmean(size(vxcopy), vxcopy) !=== call the function stdmean and get mu(1) - mean, mu(2) - standard deviation
vxcopy = (vxcopy - mu(1)) / mu(2) !=== scale the coordinates
 
! prepare the matrix
do i = 0, d
do j = 1, size(vx)
X(j, i+1) = vxcopy(j)**i !=== do the rest with vxcopy
end do
end do
 
--[[User:Raghu|Raghu]] 12:31, 12 July 2011 (UTC)
 
== Fortran matmul use ==
 
I am re working the Fortran example to use in a Delphi project.
 
The matrix multiply at the end of the example looks to be in the incorrect order.
 
I believe it should be.
 
 
polyfit = matmul( XTX, matmul(XT, vy))
 
 
 
I would appreciate if somebody with the Fortran language available could confirm.
:The matrix product is associative, so mathematically there is no difference. Computationally, however, there is one, explained at [[Matrix chain multiplication]]. [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 16:33, 13 August 2020 (UTC)
 
== FORTRAN DGETRx ==
 
Where can I read what
call DGETRF(n, n, XTX, lda, ipiv, info)
call DGETRI(n, XTX, lda, ipiv, work, lwork, info)
do? ..[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 18:13, 18 December 2016 (UTC)
:In [http://www.netlib.org/lapack/ LAPACK]'s documentation. [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 16:27, 13 August 2020 (UTC)
 
== Not what I expected ==
Adding here in case others get confused as I did...
 
I was expecting this code to generate a polynomial that matched to a series of x,y points, so that I could then use that formula to extrapolate. However, it seems that all the coefficients are sensitive to the absolute magnitude of the x values. :( For example, if I change the original data x values from 0-11 to 1000-1011 I get the answer
y = 2998001 - 5998*x - 0.036*x*x
 
I was expecting that it would change the first coefficient, but this is clearly a completely differently shaped parabola from y = 1 + 2x +3x*x
 
Fortunately, my data is a time series and in order, so I can subtract the initial x value from all the following x values.
2

edits