%% Sample RBF script: How does the width effect the function? %First define the data X=randn(1500,2); Y=exp(-(X(:,1).^2+X(:,2).^2)/4)+0.15*randn(1500,1); %Add some noise %% Split the data into training and testing sets % In this case, we'll use 300 points for training temp=randperm(1500); Xtrain=X(temp(1:300),:); Xtest=X(temp(301:end),:); Ytrain=Y(temp(1:300),:); Ytest=Y(temp(301:end),:); %% Create the Radial Basis Function. % For this example, we will use 10 points chosen at random from the data as % our set of centers temp=randperm(1500); Centers=X(temp(1:10),:); widths=10:-0.1:0.1; %% Loop through possible widths for j=1:length(widths); A=edm(Xtrain,Centers); Phi=rbf1(A,1,widths(j)); alpha=pinv(Phi)*Ytrain; % Compute the error using the test set: A=edm(Xtest,Centers); Phi=rbf1(A,1,widths(j)); Yout=Phi*alpha; Err(j)=norm(Ytest-Yout,'fro'); end [minErr,val]=min(Err); fprintf('The best width is %f\n',widths(val));