www.gusucode.com > stats 源码程序 matlab案例代码 > stats/ImpactofSpecifyingInitialKernelParameterValuesExample.m
%% Impact of Specifying Initial Kernel Parameter Values %% % Load the sample data. load(fullfile(matlabroot,'examples','stats','gprdata2.mat')) %% % The data has one predictor variable and continuous response. This is simulated % data. %% % Fit a GPR model using the squared exponential kernel function with default % kernel parameters. gprMdl1 = fitrgp(x,y,'KernelFunction','squaredexponential'); %% % Now, fit a second model, where you specify the initial values for the % kernel parameters. sigma0 = 0.2; kparams0 = [3.5, 6.2]; gprMdl2 = fitrgp(x,y,'KernelFunction','squaredexponential',... 'KernelParameters',kparams0,'Sigma',sigma0); %% % Compute the resubstitution predictions from both models. ypred1 = resubPredict(gprMdl1); ypred2 = resubPredict(gprMdl2); %% % Plot the response predictions from both models and the responses in training % data. figure(); plot(x,y,'r.'); hold on plot(x,ypred1,'b'); plot(x,ypred2,'g'); xlabel('x'); ylabel('y'); legend({'data','default kernel parameters',... 'kparams0 = [3.5,6.2], sigma0 = 0.2'},... 'Location','Best'); title('Impact of initial kernel parameter values'); hold off %% % The marginal log likelihood that |fitrgp| maximizes to estimate GPR parameters % has multiple local solutions; the solution that it converges to depends % on the initial point. Each local solution corresponds to a particular % interpretation of the data. In this example, the solution with the default % initial kernel parameters corresponds to a low frequency signal with high % noise whereas the second solution with custom initial kernel parameters % corresponds to a high frequency signal with low noise.