"Regression" consists in finding a function (typically a polynom) that passes by a set of points (x,y), and can be used to make "prediction" (e.g. find a y
for a value x
that is not in the points'set).
C
: $$p(x)=1+x+x^2+x^3$$power(x,n)
function for x^n
.xs=[0, 0.1, 0.2, ..., 1]
malloc
function (from stdlib.h
)ys
such as ys[i]=p(xs[i])
X=[1,x,x^2,x^3]
.mult
that multiply a vector by a constant value.sum
of two vectors, and a another one that compute the dot
product.p
by using a dot product, ie. find W
such as p(x)=W.X
.W
such as p(x)
passes by all the values of (xs
,ys
). To proceed, encode the following algorithm:
W
, eg. [0.1,-0.2,0.3,-0.4]
i
from 0 to 50000y=p(xs[i%10])
e=ys[i%10]-y
W = W+0.01*e*X