function [y_pred,lambda] = get_ypred_rbf(x,y,x_test,c,choice) % This function builds an RBF metamodel and predicts the function value at % test points. % This function can also be used to calculate lambda based on the given % design points to use for analytic functions. A value for x_test must % be defined since the function expects it. % ---Variable Descriptions--- % x = normalized design(training points): in an % [num_of_points by num_of_variables] matrix % y = vector of function values at each x % x_test = test points: in an % [num_of_points by num_of_variables] matrix % c = user chosen RBF constant (good general value is c = 1) % choice = user chosen RBF radial basis function choice % (good general value is choice = 3) % --Currently Supported Basis Funcitons-- % choice = 1 -> Thin Plate; phi = r^2*ln(c*r) % choice = 2 -> Gaussian; phi = exp(-c*r^2) % choice = 3 -> Multiguadric; phi = sqrt(r^2+c^2) % choice = 4 -> Inverse Multiquadric; phi = 1/sqrt(r^2+c^2) n = size(x,1); % number of training points n_test = size(x_test,1); % number of test points % Define matrix A for i=1:n for j=1:n xj=x(j,:); xi=x(i,:); r=norm(xj-xi); phi = get_phi(r,c,choice); A(i,j) = phi; end end % Solve for lambda lambda = A\y; % Calculate the RBF prediction at test points for j = 1:n_test y_pred(j,1) = 0; xj = x_test(j,:); for i = 1:n xi = x(i,:); r = norm(xj-xi); phi = get_phi(r,c,choice); y_pred(j,1)=y_pred(j,1)+lambda(i)*phi; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function phi = get_phi(r,c,choice) % choice: 1=thin-plate, 2=gaussian, 3=multiquadric, 4=inverse multiquadric if choice == 1 if r==0 phi = 0; else phi = r^2*log(c*r); end elseif choice == 2 phi = exp(-c*r^2); elseif choice == 3 phi = sqrt(r^2+c^2); elseif choice == 4 phi = 1/sqrt(r^2+c^2); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%