function write_svr(x_train,beta,pp,bias,ker,filename) % This function creates an analytic SVR equation for a given set of % training points and SVR parameters. This does not build the metamodel, % it writes a text file of a prebuilt metamodel.SVR parameters can % be easily taken from an SVR model built using the MATLAB toolbox % developed by Gunn 1998. % This function is set up to use MATLAB syntax for the output equation. % % ---Variable Descriptions--- % x_train = normalized design(training points): in an % [num_of_points by num_of_variables] matrix % beta = SVR parameter("Difference of Lagrange Multipliers" - Gunn Toolbox) % pp = SVR Kernel parameter % bias = SVR bias % ker = SVR kernel function % --Currently Supported Kernel Functions-- % ker = 'rbfal' = referred to as "RBF" in literature and not included in % the base Gunn SVR toolbox % ker = 'rbf' = referred to as "Gaussian RBF" or "Gaussian" in the % literature and called "RBF" in Gunn's toolbox % ker = 'linear'= referred to as "linear" in literature and Gunn % filename = string containing the filname to save the equation as, % must be "filename.txt" % SVR parameters pn = num2str(pp); % number of design variables and number of training points. ndv = size(x_train,2); ntrn = size(x_train,1); % open output file with specified filename fout = fopen(filename,'w'); i = 0; for n = 1:ntrn for m = 1:ndv i = i + 1; % here p0 p1 p2 and p3 represent portions of each line in the text % file in sequential order. if i == 1 p0 = 'y_svr='; else p0 = '+'; end % write the SVR based on which Kernel function is specified if strcmp(ker,'rbfal') == 1; % typically referred to as RBF % in the literature if m == 1 p1 = [num2str(beta(n)) '.*exp(-' num2str(pn) '.*((']; p3 = '...'; elseif m == ndv p3 = '))...'; else p1 = '('; p3 = '...'; end p2 = ['(x' num2str(m) '-' num2str(x_train(n,m),12) ').^2)']; if m == ndv && n == ntrn p3 = ['))+' num2str(bias)]; end elseif strcmp(ker,'rbf') == 1; % typically referred to as Gaussian % RBF or Guassian in the literature % (gunn's SVR toolbox uses rbf) if m == 1 p1 = [num2str(beta(n)) '.*exp(-((']; p3 = '...'; elseif m == ndv p3 = [')./(2*' num2str(pn) '^2))...']; else p1 = '('; p3 = '...'; end p2 = ['(x' num2str(m) '-' num2str(x_train(n,m),12) ').^2)']; if m == ndv && n == ntrn p3 = [')./(2*' num2str(pn) '^2))+' num2str(bias)]; end elseif strcmp(ker,'linear') == 1; if m == 1 p1 = [num2str(beta(n)) '.*(((']; p3 = '...'; elseif m == ndv p3 = '))...'; else p1 = '('; p3 = '...'; end p2 = ['(x' num2str(m) '.*' num2str(x_train(n,m),12) '))']; if m == ndv && n == ntrn p3 = ['))+' num2str(bias)]; end end fprintf(fout,'%s\n',[p0 p1 p2 p3]); end end fclose(fout)