RegEx3.mw

Experiments on Support Vector Regression

 > currentdir("C:\\cygwin\\home\\cr569\\machine-len\\MapleReg"): with(LinearAlgebra): with(plots):

You need to edit the currentdir to the location of the file SVRegression.mpl in your machine.

Define a function to sample from:

 > f := x -> 2.5 + exp(-(x-.1)^2/2)*cos((x-0.01)*Pi)*(1+(x+.1)^3);

 > a := -1.5: b := 1.5:

 > p1 := plot(f(x),x=a..b): plot(f(x),x=a..b);

 > n := 30: sigma := 0.4:

 > XYp := get_sample(n,f,-1.5,1.5,sigma): p2 := XYp[3]:

Now XYp is a the list [X,Y,p2] with the data vectors X , Y and the plot p2.

 > display({p1,p2});

 >

Define all the parameters:

#### Get the Regression and a plot.
SVRegression := proc(xs,ys,n,k,kas,epsilon,c,tol,lower,upper)

## Input:

##        xs,ys                 the data

##        n                number of data points

##        k                The kernel function k(x,x',params)

##        kas                list of kernel parameters

##        epsilon                epsilon insensitive cost

##        c                smoothing parameter: c*(emp.risk) + |w|^2/2

##        tol                tolerance for supp. vecs. |lambda_i| > tol.

##        lower,upper        limits for plotting

##

## Output:

##        b0,dlambda        b0+fopt(x,dlambda...) is the estimate

##        aplot                plot of the estimate and data

###########################################################

The default kernel "k" is gaussian with parameter  kas = [2(sigma^2)]

 > epsilon := .4: c := 1.5: kas := [.5]: tol := 1.0E-7:

 > SVr := SVRegression(XYp[1],XYp[2],n,k,kas,epsilon,c,tol,a,b):

Get plot of the estimated regression curve (green) with a tube of side epsilon (blue), the data with the

support vectors marked with "+".

 > tube := op(plot_tube(SVr,XYp,epsilon,n,k,kas,tol,a,b)):

 > display({p1,tube,SVr[3]});

 >