%% Sample RBF script. %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),:); A=edm(Xtrain,Centers); Phi=rbf1(A,1,3); alpha=pinv(Phi)*Ytrain; %% The error is measured by the error on the test set: %Compute the new EDM: A=edm(Xtest,Centers); Phi=rbf1(A,1,3); Yout=Phi*alpha; [m,n]=size(Ytest); %The error is the norm of the difference: for j=1:m Err(j)=norm(Ytest(j,:)-Yout(j,:)); end %% Plot in 3d plot3(Xtest(:,1),Xtest(:,2),Yout,'.');