📄 demprgp.m
字号:
'Units','normalized', ...
'BackgroundColor', [0.6 0.6 0.6], ...
'Position',[0.5 bottom_row 0.13 0.1], ...
'String','Sample', ...
'Callback','demprgp replot');
% The CLOSE button
uicontrol(fig, ...
'Style','push', ...
'Units','normalized', ...
'BackgroundColor', [0.6 0.6 0.6], ...
'Position',[0.82 bottom_row 0.13 0.1], ...
'String','Close', ...
'Callback','close(gcf)');
% The HELP button
uicontrol(fig, ...
'Style','push', ...
'Units','normalized', ...
'BackgroundColor', [0.6 0.6 0.6], ...
'Position',[0.66 bottom_row 0.13 0.1], ...
'String','Help', ...
'Callback','demprgp help');
% Save handles to objects
hndlList=[fig biasslide noiseslide inweightsslide fparslide ...
biasval noiseval inweightsval ...
fparval haxes nettype_box];
set(fig, 'UserData', hndlList);
demprgp('replot')
elseif strcmp(action, 'update'),
% Update when a slider is moved.
hndlList = get(gcf, 'UserData');
biasslide = hndlList(2);
noiseslide = hndlList(3);
inweightsslide = hndlList(4);
fparslide = hndlList(5);
biasval = hndlList(6);
noiseval = hndlList(7);
inweightsval = hndlList(8);
fparval = hndlList(9);
haxes = hndlList(10);
nettype_box = hndlList(11);
bias = get(biasslide, 'Value');
noise = get(noiseslide, 'Value');
inweights = get(inweightsslide, 'Value');
fpar = get(fparslide, 'Value');
fpar2 = get(findobj('Tag', 'fpar2slider'), 'Value');
format = '%8f';
set(biasval, 'String', sprintf(format, bias));
set(noiseval, 'String', sprintf(format, noise));
set(inweightsval, 'String', sprintf(format, inweights));
set(fparval, 'String', sprintf(format, fpar));
set(findobj('Tag', 'fpar2val'), 'String', ...
sprintf(format, fpar2));
demprgp('replot');
elseif strcmp(action, 'newval'),
% Update when text is changed.
hndlList = get(gcf, 'UserData');
biasslide = hndlList(2);
noiseslide = hndlList(3);
inweightsslide = hndlList(4);
fparslide = hndlList(5);
biasval = hndlList(6);
noiseval = hndlList(7);
inweightsval = hndlList(8);
fparval = hndlList(9);
haxes = hndlList(10);
bias = sscanf(get(biasval, 'String'), '%f');
noise = sscanf(get(noiseval, 'String'), '%f');
inweights = sscanf(get(inweightsval, 'String'), '%f');
fpar = sscanf(get(fparval, 'String'), '%f');
fpar2 = sscanf(get(findobj('Tag', 'fpar2val'), 'String'), '%f');
set(biasslide, 'Value', bias);
set(noiseslide, 'Value', noise);
set(inweightsslide, 'Value', inweights);
set(fparslide, 'Value', fpar);
set(findobj('Tag', 'fpar2slider'), 'Value', fpar2);
demprgp('replot');
elseif strcmp(action, 'GPtype')
hndlList = get(gcf, 'UserData');
nettype_box = hndlList(11);
gptval = get(nettype_box, 'Value');
if gptval == 1
% Squared exponential, so turn off fpar2
set(findobj('Tag', 'fpar2text'), 'Enable', 'off');
set(findobj('Tag', 'fpar2slider'), 'Enable', 'off');
set(findobj('Tag', 'fpar2val'), 'Enable', 'off');
else
% Rational quadratic, so turn on fpar2
set(findobj('Tag', 'fpar2text'), 'Enable', 'on');
set(findobj('Tag', 'fpar2slider'), 'Enable', 'on');
set(findobj('Tag', 'fpar2val'), 'Enable', 'on');
end
demprgp('replot');
elseif strcmp(action, 'replot'),
% Re-sample from the prior and plot graphs.
oldFigNumber=watchon;
hndlList = get(gcf, 'UserData');
biasslide = hndlList(2);
noiseslide = hndlList(3);
inweightsslide = hndlList(4);
fparslide = hndlList(5);
haxes = hndlList(10);
nettype_box = hndlList(11);
gptval = get(nettype_box, 'Value');
if gptval == 1
gptype = 'sqexp';
else
gptype = 'ratquad';
end
bias = get(biasslide, 'Value');
noise = get(noiseslide, 'Value');
inweights = get(inweightsslide, 'Value');
fpar = get(fparslide, 'Value');
axes(haxes);
cla
set(gca, ...
'Box', 'on', ...
'Color', [0 0 0], ...
'XColor', [0 0 0], ...
'YColor', [0 0 0], ...
'FontSize', 14);
ymin = -10;
ymax = 10;
axis([-1 1 ymin ymax]);
set(gca,'DefaultLineLineWidth', 2);
xvals = (-1:0.01:1)';
nsample = 10; % Number of samples from prior.
hold on
plot([-1 0; 1 0], [0 ymin; 0 ymax], 'b--');
net = gp(1, gptype);
net.bias = bias;
net.noise = noise;
net.inweights = inweights;
if strcmp(gptype, 'sqexp')
net.fpar = fpar;
else
fpar2 = get(findobj('Tag', 'fpar2slider'), 'Value');
net.fpar = [fpar fpar2];
end
cn = gpcovar(net, xvals);
cninv = inv(cn);
cnchol = chol(cn);
set(gca, 'DefaultLineLineWidth', 1);
for n = 1:nsample
y = (cnchol') * randn(size(xvals));
plot(xvals, y, 'y');
end
watchoff(oldFigNumber);
elseif strcmp(action, 'help'),
% Provide help to user.
oldFigNumber=watchon;
helpfig = figure('Position', [100 100 480 400], ...
'Name', 'Help', ...
'NumberTitle', 'off', ...
'Color', [0.8 0.8 0.8], ...
'Visible','on');
% The HELP TITLE BAR frame
uicontrol(helpfig, ...
'Style','frame', ...
'Units','normalized', ...
'HorizontalAlignment', 'center', ...
'Position', [0.05 0.82 0.9 0.1], ...
'BackgroundColor',[0.60 0.60 0.60]);
% The HELP TITLE BAR text
uicontrol(helpfig, ...
'Style', 'text', ...
'Units', 'normalized', ...
'BackgroundColor', [0.6 0.6 0.6], ...
'Position', [0.26 0.85 0.6 0.05], ...
'HorizontalAlignment', 'left', ...
'String', 'Help: Sampling from a Gaussian Process Prior');
helpstr1 = strcat(...
'This demonstration shows the effects of sampling from a Gaussian', ...
' process prior. The parameters bias, noise, inweights and fpar', ...
' control the corresponding terms in the covariance function of the',...
' Gaussian process. Their values can be adjusted on a linear scale',...
' using the sliders, or by typing values into the text boxes and',...
' pressing the return key. After setting these values, press the',...
' ''Sample'' button to see a new sample from the prior.');
helpstr2 = strcat(...
'Observe how inweights controls horizontal length-scale of the',...
' variation in the functions, noise controls the roughness of the',...
' functions, and the bias controls the size of the', ...
' vertical offset of the signal.');
helpstr3 = strcat(...
'There are two types of covariance function supported by', ...
' Netlab which can be selected using the ''Covariance Function', ...
' Type'' menu.');
helpstr4 = strcat(...
'The squared exponential has a single fpar which', ...
' controls the vertical scale of the process.');
helpstr5 = strcat(...
'The rational quadratic has two fpar values. The first is', ...
' is a scale parameter inside the rational function like the',...
' first fpar for the squared exponential covariance, while the', ...
' second gives the exponent of the rational function (i.e. the',...
' rate of decay of the covariance function.');
% Set up cell array with help strings
hstr(1) = {helpstr1};
hstr(2) = {''};
hstr(3) = {helpstr2};
hstr(4) = {''};
hstr(5) = {helpstr3};
hstr(6) = {''};
hstr(7) = {helpstr4};
hstr(8) = {''};
hstr(9) = {helpstr5};
% The HELP text
helpui = uicontrol(helpfig, ...
'Style', 'Text', ...
'Units', 'normalized', ...
'ForegroundColor', [0 0 0], ...
'HorizontalAlignment', 'left', ...
'BackgroundColor', [1 1 1], ...
'Min', 0, ...
'Max', 2, ...
'Position', [0.05 0.2 0.9 0.57]);
[hstrw, newpos] = textwrap(helpui, hstr);
set(helpui, 'String', hstrw, 'Position', [0.05, 0.2, 0.9 newpos(4)]);
% The CLOSE button
uicontrol(helpfig, ...
'Style','push', ...
'Units','normalized', ...
'BackgroundColor', [0.6 0.6 0.6], ...
'Position',[0.4 0.05 0.2 0.1], ...
'String','Close', ...
'Callback','close(gcf)');
watchoff(oldFigNumber);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -