% Script to show the effects of the width of the Gaussian in 1-d functions %The data will be random: numcenters=15; ridx=randperm(numcenters); x=2*randn(1,numcenters*4); centers=x; y=sin(3*x)+0.2*randn(size(x)); t=linspace(-2,2); yt=sin(3*t); widths=5:-0.1:0.1; for j=1:length(widths) %Get the Weights from the training data A=edm(x',centers'); Phi=rbf1(A,1,widths(j)); Phi=[Phi, ones(length(x),1)]; W=pinv(Phi)*y'; %Get predicted values on the new data: A=edm(t',centers'); Phi=rbf1(A,1,widths(j)); Phi=[Phi, ones(length(t),1)]; Yout=Phi*W; figure(1) plot(x,y,'k*',t,yt,'b-',t,Yout,'r-'); axis([-2 2 -2 2]); pause(0.1); Err(j)=sum(abs(Yout-yt').^2); end % You can plot the whole error vector, but notice that the error decreases % through the first 12, then increases (then increases wildly at the end!). % This suggests that the optimal width is the 12th value of the widths % vector, or: 3.90