annotate toolboxes/FullBNT-1.0.7/netlab3.3/demprgp.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function demprgp(action);
Daniel@0 2 %DEMPRGP Demonstrate sampling from a Gaussian Process prior.
Daniel@0 3 %
Daniel@0 4 % Description
Daniel@0 5 % This function plots the functions represented by a Gaussian Process
Daniel@0 6 % model. The hyperparameter values can be adjusted on a linear scale
Daniel@0 7 % using the sliders (though the exponential of the parameters is used
Daniel@0 8 % in the covariance function), or by typing values into the text boxes
Daniel@0 9 % and pressing the return key. Both types of covariance function are
Daniel@0 10 % supported. An extra function specific parameter is needed for the
Daniel@0 11 % rational quadratic function.
Daniel@0 12 %
Daniel@0 13 % See also
Daniel@0 14 % GP
Daniel@0 15 %
Daniel@0 16
Daniel@0 17 % Copyright (c) Ian T Nabney (1996-2001)
Daniel@0 18
Daniel@0 19 if nargin<1,
Daniel@0 20 action='initialize';
Daniel@0 21 end;
Daniel@0 22
Daniel@0 23 if strcmp(action,'initialize')
Daniel@0 24
Daniel@0 25 % Bounds on hyperparameter values
Daniel@0 26 biasminval = -3.0; biasmaxval = 3.0;
Daniel@0 27 noiseminval = -20; noisemaxval = -2;
Daniel@0 28 fparminval = 0.0; fparmaxval = 2.0;
Daniel@0 29 inwminval = 0; inwmaxval = 8;
Daniel@0 30 % Initial hyperparameter values
Daniel@0 31 bias = (biasminval+biasmaxval)/2;
Daniel@0 32 noise = (noiseminval+noisemaxval)/2;
Daniel@0 33 inweights = (inwminval+inwmaxval)/2;
Daniel@0 34 fpar = (fparminval+fparmaxval)/2;
Daniel@0 35 fpar2 = (fparminval+fparmaxval)/2;
Daniel@0 36
Daniel@0 37 gptype = 'sqexp';
Daniel@0 38
Daniel@0 39 % Create FIGURE
Daniel@0 40 fig=figure( ...
Daniel@0 41 'Name','Sampling from a Gaussian Process prior', ...
Daniel@0 42 'Position', [50 50 480 380], ...
Daniel@0 43 'NumberTitle','off', ...
Daniel@0 44 'Color', [0.8 0.8 0.8], ...
Daniel@0 45 'Visible','on');
Daniel@0 46
Daniel@0 47 % List box for covariance function type
Daniel@0 48 nettype_box = uicontrol(fig, ...
Daniel@0 49 'Style', 'listbox', ...
Daniel@0 50 'Units', 'normalized', ...
Daniel@0 51 'HorizontalAlignment', 'center', ...
Daniel@0 52 'Position', [0.52 0.77 0.40 0.12], ...
Daniel@0 53 'String', 'Squared Exponential|Rational Quadratic', ...
Daniel@0 54 'Max', 1, 'Min', 0, ... % Only allow one selection
Daniel@0 55 'Value', 1, ... % Initial value is squared exponential
Daniel@0 56 'BackgroundColor',[0.60 0.60 0.60],...
Daniel@0 57 'CallBack', 'demprgp GPtype');
Daniel@0 58
Daniel@0 59 % Title for list box
Daniel@0 60 uicontrol(fig, ...
Daniel@0 61 'Style', 'text', ...
Daniel@0 62 'Units', 'normalized', ...
Daniel@0 63 'Position', [0.52 0.89 0.40 0.05], ...
Daniel@0 64 'String', 'Covariance Function Type', ...
Daniel@0 65 'BackgroundColor', get(fig, 'Color'), ...
Daniel@0 66 'HorizontalAlignment', 'center');
Daniel@0 67
Daniel@0 68 % Frames to enclose sliders
Daniel@0 69 bottom_row = 0.04;
Daniel@0 70 slider_frame_height = 0.15;
Daniel@0 71 biasframe = uicontrol(fig, ...
Daniel@0 72 'Style', 'frame', ...
Daniel@0 73 'Units', 'normalized', ...
Daniel@0 74 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 75 'String', 'bias', ...
Daniel@0 76 'HorizontalAlignment', 'left', ...
Daniel@0 77 'Position', [0.05 bottom_row 0.35 slider_frame_height]);
Daniel@0 78
Daniel@0 79 bpos = get(biasframe, 'Position');
Daniel@0 80 noise_frame_bottom = bpos(2) + bpos(4) + 0.02;
Daniel@0 81 noiseframe = uicontrol(fig, ...
Daniel@0 82 'Style', 'frame', ...
Daniel@0 83 'Units', 'normalized', ...
Daniel@0 84 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 85 'Position', [0.05 noise_frame_bottom 0.35 slider_frame_height]);
Daniel@0 86
Daniel@0 87 npos = get(noiseframe, 'Position');
Daniel@0 88 inw_frame_bottom = npos(2) + npos(4) + 0.02;
Daniel@0 89 inwframe = uicontrol(fig, ...
Daniel@0 90 'Style', 'frame', ...
Daniel@0 91 'Units', 'normalized', ...
Daniel@0 92 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 93 'Position', [0.05 inw_frame_bottom 0.35 slider_frame_height]);
Daniel@0 94
Daniel@0 95 inwpos = get(inwframe, 'Position');
Daniel@0 96 fpar_frame_bottom = inwpos(2) + inwpos(4) + 0.02;
Daniel@0 97 % This frame sometimes has multiple parameters
Daniel@0 98 uicontrol(fig, ...
Daniel@0 99 'Style', 'frame', ...
Daniel@0 100 'Units', 'normalized', ...
Daniel@0 101 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 102 'Position', [0.05 fpar_frame_bottom 0.35 2*slider_frame_height]);
Daniel@0 103
Daniel@0 104 % Frame text
Daniel@0 105 slider_text_height = 0.05;
Daniel@0 106 slider_text_voffset = 0.08;
Daniel@0 107 uicontrol(fig, ...
Daniel@0 108 'Style', 'text', ...
Daniel@0 109 'Units', 'normalized', ...
Daniel@0 110 'HorizontalAlignment', 'left', ...
Daniel@0 111 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 112 'Position', [0.07 bottom_row+slider_text_voffset ...
Daniel@0 113 0.06 slider_text_height], ...
Daniel@0 114 'String', 'bias');
Daniel@0 115
Daniel@0 116 % Frame text
Daniel@0 117 noiseframe = uicontrol(fig, ...
Daniel@0 118 'Style', 'text', ...
Daniel@0 119 'Units', 'normalized', ...
Daniel@0 120 'HorizontalAlignment', 'left', ...
Daniel@0 121 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 122 'Position', [0.07 noise_frame_bottom+slider_text_voffset ...
Daniel@0 123 0.08 slider_text_height], ...
Daniel@0 124 'String', 'noise');
Daniel@0 125
Daniel@0 126 % Frame text
Daniel@0 127 uicontrol(fig, ...
Daniel@0 128 'Style', 'text', ...
Daniel@0 129 'Units', 'normalized', ...
Daniel@0 130 'HorizontalAlignment', 'left', ...
Daniel@0 131 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 132 'Position', [0.07 inw_frame_bottom+slider_text_voffset ...
Daniel@0 133 0.14 slider_text_height], ...
Daniel@0 134 'String', 'inweights');
Daniel@0 135
Daniel@0 136 % Frame text
Daniel@0 137 uicontrol(fig, ...
Daniel@0 138 'Style', 'text', ...
Daniel@0 139 'Units', 'normalized', ...
Daniel@0 140 'HorizontalAlignment', 'left', ...
Daniel@0 141 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 142 'Position', [0.07 fpar_frame_bottom+slider_frame_height+ ...
Daniel@0 143 slider_text_voffset 0.06 slider_text_height], ...
Daniel@0 144 'String', 'fpar');
Daniel@0 145
Daniel@0 146 uicontrol(fig, ...
Daniel@0 147 'Style', 'text', ...
Daniel@0 148 'Units', 'normalized', ...
Daniel@0 149 'HorizontalAlignment', 'left', ...
Daniel@0 150 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 151 'Position', [0.07 fpar_frame_bottom+slider_text_voffset ...
Daniel@0 152 0.06 slider_text_height], ...
Daniel@0 153 'String', 'fpar2', ...
Daniel@0 154 'Tag', 'fpar2text', ...
Daniel@0 155 'Enable', 'off');
Daniel@0 156
Daniel@0 157 % Slider
Daniel@0 158 slider_left = 0.07;
Daniel@0 159 slider_width = 0.31;
Daniel@0 160 slider_frame_voffset = 0.02;
Daniel@0 161 biasslide = uicontrol(fig, ...
Daniel@0 162 'Style', 'slider', ...
Daniel@0 163 'Units', 'normalized', ...
Daniel@0 164 'Value', bias, ...
Daniel@0 165 'BackgroundColor', [0.8 0.8 0.8], ...
Daniel@0 166 'Position', [slider_left bottom_row+slider_frame_voffset ...
Daniel@0 167 slider_width 0.05], ...
Daniel@0 168 'Min', biasminval, 'Max', biasmaxval, ...
Daniel@0 169 'Callback', 'demprgp update');
Daniel@0 170
Daniel@0 171 % Slider
Daniel@0 172 noiseslide = uicontrol(fig, ...
Daniel@0 173 'Style', 'slider', ...
Daniel@0 174 'Units', 'normalized', ...
Daniel@0 175 'Value', noise, ...
Daniel@0 176 'BackgroundColor', [0.8 0.8 0.8], ...
Daniel@0 177 'Position', [slider_left noise_frame_bottom+slider_frame_voffset ...
Daniel@0 178 slider_width 0.05], ...
Daniel@0 179 'Min', noiseminval, 'Max', noisemaxval, ...
Daniel@0 180 'Callback', 'demprgp update');
Daniel@0 181
Daniel@0 182 % Slider
Daniel@0 183 inweightsslide = uicontrol(fig, ...
Daniel@0 184 'Style', 'slider', ...
Daniel@0 185 'Units', 'normalized', ...
Daniel@0 186 'Value', inweights, ...
Daniel@0 187 'BackgroundColor', [0.8 0.8 0.8], ...
Daniel@0 188 'Position', [slider_left inw_frame_bottom+slider_frame_voffset ...
Daniel@0 189 slider_width 0.05], ...
Daniel@0 190 'Min', inwminval, 'Max', inwmaxval, ...
Daniel@0 191 'Callback', 'demprgp update');
Daniel@0 192
Daniel@0 193 % Slider
Daniel@0 194 fparslide = uicontrol(fig, ...
Daniel@0 195 'Style', 'slider', ...
Daniel@0 196 'Units', 'normalized', ...
Daniel@0 197 'Value', fpar, ...
Daniel@0 198 'BackgroundColor', [0.8 0.8 0.8], ...
Daniel@0 199 'Position', [slider_left fpar_frame_bottom+slider_frame_height+ ...
Daniel@0 200 slider_frame_voffset slider_width 0.05], ...
Daniel@0 201 'Min', fparminval, 'Max', fparmaxval, ...
Daniel@0 202 'Callback', 'demprgp update');
Daniel@0 203
Daniel@0 204 fpar2slide = uicontrol(fig, ...
Daniel@0 205 'Style', 'slider', ...
Daniel@0 206 'Units', 'normalized', ...
Daniel@0 207 'Value', fpar2, ...
Daniel@0 208 'BackgroundColor', [0.8 0.8 0.8], ...
Daniel@0 209 'Position', [slider_left fpar_frame_bottom+slider_frame_voffset ...
Daniel@0 210 slider_width 0.05], ...
Daniel@0 211 'Min', fparminval, 'Max', fparmaxval, ...
Daniel@0 212 'Callback', 'demprgp update', ...
Daniel@0 213 'Tag', 'fpar2slider', ...
Daniel@0 214 'Enable', 'off');
Daniel@0 215
Daniel@0 216 % Text display of hyper-parameter values
Daniel@0 217
Daniel@0 218 format = '%8f';
Daniel@0 219
Daniel@0 220 hp_left = 0.20;
Daniel@0 221 hp_width = 0.17;
Daniel@0 222 biasval = uicontrol(fig, ...
Daniel@0 223 'Style', 'edit', ...
Daniel@0 224 'Units', 'normalized', ...
Daniel@0 225 'Position', [hp_left bottom_row+slider_text_voffset ...
Daniel@0 226 hp_width slider_text_height], ...
Daniel@0 227 'String', sprintf(format, bias), ...
Daniel@0 228 'Callback', 'demprgp newval');
Daniel@0 229
Daniel@0 230 noiseval = uicontrol(fig, ...
Daniel@0 231 'Style', 'edit', ...
Daniel@0 232 'Units', 'normalized', ...
Daniel@0 233 'Position', [hp_left noise_frame_bottom+slider_text_voffset ...
Daniel@0 234 hp_width slider_text_height], ...
Daniel@0 235 'String', sprintf(format, noise), ...
Daniel@0 236 'Callback', 'demprgp newval');
Daniel@0 237
Daniel@0 238 inweightsval = uicontrol(fig, ...
Daniel@0 239 'Style', 'edit', ...
Daniel@0 240 'Units', 'normalized', ...
Daniel@0 241 'Position', [hp_left inw_frame_bottom+slider_text_voffset ...
Daniel@0 242 hp_width slider_text_height], ...
Daniel@0 243 'String', sprintf(format, inweights), ...
Daniel@0 244 'Callback', 'demprgp newval');
Daniel@0 245
Daniel@0 246 fparval = uicontrol(fig, ...
Daniel@0 247 'Style', 'edit', ...
Daniel@0 248 'Units', 'normalized', ...
Daniel@0 249 'Position', [hp_left fpar_frame_bottom+slider_frame_height+ ...
Daniel@0 250 slider_text_voffset hp_width slider_text_height], ...
Daniel@0 251 'String', sprintf(format, fpar), ...
Daniel@0 252 'Callback', 'demprgp newval');
Daniel@0 253
Daniel@0 254 fpar2val = uicontrol(fig, ...
Daniel@0 255 'Style', 'edit', ...
Daniel@0 256 'Units', 'normalized', ...
Daniel@0 257 'Position', [hp_left fpar_frame_bottom+slider_text_voffset ...
Daniel@0 258 hp_width slider_text_height], ...
Daniel@0 259 'String', sprintf(format, fpar), ...
Daniel@0 260 'Callback', 'demprgp newval', ...
Daniel@0 261 'Enable', 'off', ...
Daniel@0 262 'Tag', 'fpar2val');
Daniel@0 263
Daniel@0 264
Daniel@0 265 % The graph box
Daniel@0 266 haxes = axes('Position', [0.5 0.28 0.45 0.45], ...
Daniel@0 267 'Units', 'normalized', ...
Daniel@0 268 'Visible', 'on');
Daniel@0 269
Daniel@0 270 % The SAMPLE button
Daniel@0 271 uicontrol(fig, ...
Daniel@0 272 'Style','push', ...
Daniel@0 273 'Units','normalized', ...
Daniel@0 274 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 275 'Position',[0.5 bottom_row 0.13 0.1], ...
Daniel@0 276 'String','Sample', ...
Daniel@0 277 'Callback','demprgp replot');
Daniel@0 278
Daniel@0 279 % The CLOSE button
Daniel@0 280 uicontrol(fig, ...
Daniel@0 281 'Style','push', ...
Daniel@0 282 'Units','normalized', ...
Daniel@0 283 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 284 'Position',[0.82 bottom_row 0.13 0.1], ...
Daniel@0 285 'String','Close', ...
Daniel@0 286 'Callback','close(gcf)');
Daniel@0 287
Daniel@0 288 % The HELP button
Daniel@0 289 uicontrol(fig, ...
Daniel@0 290 'Style','push', ...
Daniel@0 291 'Units','normalized', ...
Daniel@0 292 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 293 'Position',[0.66 bottom_row 0.13 0.1], ...
Daniel@0 294 'String','Help', ...
Daniel@0 295 'Callback','demprgp help');
Daniel@0 296
Daniel@0 297 % Save handles to objects
Daniel@0 298
Daniel@0 299 hndlList=[fig biasslide noiseslide inweightsslide fparslide ...
Daniel@0 300 biasval noiseval inweightsval ...
Daniel@0 301 fparval haxes nettype_box];
Daniel@0 302 set(fig, 'UserData', hndlList);
Daniel@0 303
Daniel@0 304 demprgp('replot')
Daniel@0 305
Daniel@0 306
Daniel@0 307 elseif strcmp(action, 'update'),
Daniel@0 308
Daniel@0 309 % Update when a slider is moved.
Daniel@0 310
Daniel@0 311 hndlList = get(gcf, 'UserData');
Daniel@0 312 biasslide = hndlList(2);
Daniel@0 313 noiseslide = hndlList(3);
Daniel@0 314 inweightsslide = hndlList(4);
Daniel@0 315 fparslide = hndlList(5);
Daniel@0 316 biasval = hndlList(6);
Daniel@0 317 noiseval = hndlList(7);
Daniel@0 318 inweightsval = hndlList(8);
Daniel@0 319 fparval = hndlList(9);
Daniel@0 320 haxes = hndlList(10);
Daniel@0 321 nettype_box = hndlList(11);
Daniel@0 322
Daniel@0 323
Daniel@0 324 bias = get(biasslide, 'Value');
Daniel@0 325 noise = get(noiseslide, 'Value');
Daniel@0 326 inweights = get(inweightsslide, 'Value');
Daniel@0 327 fpar = get(fparslide, 'Value');
Daniel@0 328 fpar2 = get(findobj('Tag', 'fpar2slider'), 'Value');
Daniel@0 329
Daniel@0 330 format = '%8f';
Daniel@0 331 set(biasval, 'String', sprintf(format, bias));
Daniel@0 332 set(noiseval, 'String', sprintf(format, noise));
Daniel@0 333 set(inweightsval, 'String', sprintf(format, inweights));
Daniel@0 334 set(fparval, 'String', sprintf(format, fpar));
Daniel@0 335 set(findobj('Tag', 'fpar2val'), 'String', ...
Daniel@0 336 sprintf(format, fpar2));
Daniel@0 337
Daniel@0 338 demprgp('replot');
Daniel@0 339
Daniel@0 340 elseif strcmp(action, 'newval'),
Daniel@0 341
Daniel@0 342 % Update when text is changed.
Daniel@0 343
Daniel@0 344 hndlList = get(gcf, 'UserData');
Daniel@0 345 biasslide = hndlList(2);
Daniel@0 346 noiseslide = hndlList(3);
Daniel@0 347 inweightsslide = hndlList(4);
Daniel@0 348 fparslide = hndlList(5);
Daniel@0 349 biasval = hndlList(6);
Daniel@0 350 noiseval = hndlList(7);
Daniel@0 351 inweightsval = hndlList(8);
Daniel@0 352 fparval = hndlList(9);
Daniel@0 353 haxes = hndlList(10);
Daniel@0 354
Daniel@0 355 bias = sscanf(get(biasval, 'String'), '%f');
Daniel@0 356 noise = sscanf(get(noiseval, 'String'), '%f');
Daniel@0 357 inweights = sscanf(get(inweightsval, 'String'), '%f');
Daniel@0 358 fpar = sscanf(get(fparval, 'String'), '%f');
Daniel@0 359 fpar2 = sscanf(get(findobj('Tag', 'fpar2val'), 'String'), '%f');
Daniel@0 360
Daniel@0 361 set(biasslide, 'Value', bias);
Daniel@0 362 set(noiseslide, 'Value', noise);
Daniel@0 363 set(inweightsslide, 'Value', inweights);
Daniel@0 364 set(fparslide, 'Value', fpar);
Daniel@0 365 set(findobj('Tag', 'fpar2slider'), 'Value', fpar2);
Daniel@0 366
Daniel@0 367 demprgp('replot');
Daniel@0 368
Daniel@0 369 elseif strcmp(action, 'GPtype')
Daniel@0 370 hndlList = get(gcf, 'UserData');
Daniel@0 371 nettype_box = hndlList(11);
Daniel@0 372 gptval = get(nettype_box, 'Value');
Daniel@0 373 if gptval == 1
Daniel@0 374 % Squared exponential, so turn off fpar2
Daniel@0 375 set(findobj('Tag', 'fpar2text'), 'Enable', 'off');
Daniel@0 376 set(findobj('Tag', 'fpar2slider'), 'Enable', 'off');
Daniel@0 377 set(findobj('Tag', 'fpar2val'), 'Enable', 'off');
Daniel@0 378 else
Daniel@0 379 % Rational quadratic, so turn on fpar2
Daniel@0 380 set(findobj('Tag', 'fpar2text'), 'Enable', 'on');
Daniel@0 381 set(findobj('Tag', 'fpar2slider'), 'Enable', 'on');
Daniel@0 382 set(findobj('Tag', 'fpar2val'), 'Enable', 'on');
Daniel@0 383 end
Daniel@0 384 demprgp('replot');
Daniel@0 385
Daniel@0 386 elseif strcmp(action, 'replot'),
Daniel@0 387
Daniel@0 388 % Re-sample from the prior and plot graphs.
Daniel@0 389
Daniel@0 390 oldFigNumber=watchon;
Daniel@0 391
Daniel@0 392 hndlList = get(gcf, 'UserData');
Daniel@0 393 biasslide = hndlList(2);
Daniel@0 394 noiseslide = hndlList(3);
Daniel@0 395 inweightsslide = hndlList(4);
Daniel@0 396 fparslide = hndlList(5);
Daniel@0 397 haxes = hndlList(10);
Daniel@0 398 nettype_box = hndlList(11);
Daniel@0 399 gptval = get(nettype_box, 'Value');
Daniel@0 400 if gptval == 1
Daniel@0 401 gptype = 'sqexp';
Daniel@0 402 else
Daniel@0 403 gptype = 'ratquad';
Daniel@0 404 end
Daniel@0 405
Daniel@0 406 bias = get(biasslide, 'Value');
Daniel@0 407 noise = get(noiseslide, 'Value');
Daniel@0 408 inweights = get(inweightsslide, 'Value');
Daniel@0 409 fpar = get(fparslide, 'Value');
Daniel@0 410
Daniel@0 411
Daniel@0 412 axes(haxes);
Daniel@0 413 cla
Daniel@0 414 set(gca, ...
Daniel@0 415 'Box', 'on', ...
Daniel@0 416 'Color', [0 0 0], ...
Daniel@0 417 'XColor', [0 0 0], ...
Daniel@0 418 'YColor', [0 0 0], ...
Daniel@0 419 'FontSize', 14);
Daniel@0 420 ymin = -10;
Daniel@0 421 ymax = 10;
Daniel@0 422 axis([-1 1 ymin ymax]);
Daniel@0 423 set(gca,'DefaultLineLineWidth', 2);
Daniel@0 424
Daniel@0 425 xvals = (-1:0.01:1)';
Daniel@0 426 nsample = 10; % Number of samples from prior.
Daniel@0 427 hold on
Daniel@0 428 plot([-1 0; 1 0], [0 ymin; 0 ymax], 'b--');
Daniel@0 429 net = gp(1, gptype);
Daniel@0 430 net.bias = bias;
Daniel@0 431 net.noise = noise;
Daniel@0 432 net.inweights = inweights;
Daniel@0 433 if strcmp(gptype, 'sqexp')
Daniel@0 434 net.fpar = fpar;
Daniel@0 435 else
Daniel@0 436 fpar2 = get(findobj('Tag', 'fpar2slider'), 'Value');
Daniel@0 437 net.fpar = [fpar fpar2];
Daniel@0 438 end
Daniel@0 439 cn = gpcovar(net, xvals);
Daniel@0 440 cninv = inv(cn);
Daniel@0 441 cnchol = chol(cn);
Daniel@0 442 set(gca, 'DefaultLineLineWidth', 1);
Daniel@0 443 for n = 1:nsample
Daniel@0 444 y = (cnchol') * randn(size(xvals));
Daniel@0 445 plot(xvals, y, 'y');
Daniel@0 446 end
Daniel@0 447
Daniel@0 448 watchoff(oldFigNumber);
Daniel@0 449
Daniel@0 450 elseif strcmp(action, 'help'),
Daniel@0 451
Daniel@0 452 % Provide help to user.
Daniel@0 453
Daniel@0 454 oldFigNumber=watchon;
Daniel@0 455
Daniel@0 456 helpfig = figure('Position', [100 100 480 400], ...
Daniel@0 457 'Name', 'Help', ...
Daniel@0 458 'NumberTitle', 'off', ...
Daniel@0 459 'Color', [0.8 0.8 0.8], ...
Daniel@0 460 'Visible','on');
Daniel@0 461
Daniel@0 462 % The HELP TITLE BAR frame
Daniel@0 463 uicontrol(helpfig, ...
Daniel@0 464 'Style','frame', ...
Daniel@0 465 'Units','normalized', ...
Daniel@0 466 'HorizontalAlignment', 'center', ...
Daniel@0 467 'Position', [0.05 0.82 0.9 0.1], ...
Daniel@0 468 'BackgroundColor',[0.60 0.60 0.60]);
Daniel@0 469
Daniel@0 470 % The HELP TITLE BAR text
Daniel@0 471 uicontrol(helpfig, ...
Daniel@0 472 'Style', 'text', ...
Daniel@0 473 'Units', 'normalized', ...
Daniel@0 474 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 475 'Position', [0.26 0.85 0.6 0.05], ...
Daniel@0 476 'HorizontalAlignment', 'left', ...
Daniel@0 477 'String', 'Help: Sampling from a Gaussian Process Prior');
Daniel@0 478
Daniel@0 479 helpstr1 = strcat(...
Daniel@0 480 'This demonstration shows the effects of sampling from a Gaussian', ...
Daniel@0 481 ' process prior. The parameters bias, noise, inweights and fpar', ...
Daniel@0 482 ' control the corresponding terms in the covariance function of the',...
Daniel@0 483 ' Gaussian process. Their values can be adjusted on a linear scale',...
Daniel@0 484 ' using the sliders, or by typing values into the text boxes and',...
Daniel@0 485 ' pressing the return key. After setting these values, press the',...
Daniel@0 486 ' ''Sample'' button to see a new sample from the prior.');
Daniel@0 487
Daniel@0 488 helpstr2 = strcat(...
Daniel@0 489 'Observe how inweights controls horizontal length-scale of the',...
Daniel@0 490 ' variation in the functions, noise controls the roughness of the',...
Daniel@0 491 ' functions, and the bias controls the size of the', ...
Daniel@0 492 ' vertical offset of the signal.');
Daniel@0 493 helpstr3 = strcat(...
Daniel@0 494 'There are two types of covariance function supported by', ...
Daniel@0 495 ' Netlab which can be selected using the ''Covariance Function', ...
Daniel@0 496 ' Type'' menu.');
Daniel@0 497 helpstr4 = strcat(...
Daniel@0 498 'The squared exponential has a single fpar which', ...
Daniel@0 499 ' controls the vertical scale of the process.');
Daniel@0 500 helpstr5 = strcat(...
Daniel@0 501 'The rational quadratic has two fpar values. The first is', ...
Daniel@0 502 ' is a scale parameter inside the rational function like the',...
Daniel@0 503 ' first fpar for the squared exponential covariance, while the', ...
Daniel@0 504 ' second gives the exponent of the rational function (i.e. the',...
Daniel@0 505 ' rate of decay of the covariance function.');
Daniel@0 506 % Set up cell array with help strings
Daniel@0 507 hstr(1) = {helpstr1};
Daniel@0 508 hstr(2) = {''};
Daniel@0 509 hstr(3) = {helpstr2};
Daniel@0 510 hstr(4) = {''};
Daniel@0 511 hstr(5) = {helpstr3};
Daniel@0 512 hstr(6) = {''};
Daniel@0 513 hstr(7) = {helpstr4};
Daniel@0 514 hstr(8) = {''};
Daniel@0 515 hstr(9) = {helpstr5};
Daniel@0 516
Daniel@0 517 % The HELP text
Daniel@0 518 helpui = uicontrol(helpfig, ...
Daniel@0 519 'Style', 'Text', ...
Daniel@0 520 'Units', 'normalized', ...
Daniel@0 521 'ForegroundColor', [0 0 0], ...
Daniel@0 522 'HorizontalAlignment', 'left', ...
Daniel@0 523 'BackgroundColor', [1 1 1], ...
Daniel@0 524 'Min', 0, ...
Daniel@0 525 'Max', 2, ...
Daniel@0 526 'Position', [0.05 0.2 0.9 0.57]);
Daniel@0 527 [hstrw, newpos] = textwrap(helpui, hstr);
Daniel@0 528 set(helpui, 'String', hstrw, 'Position', [0.05, 0.2, 0.9 newpos(4)]);
Daniel@0 529
Daniel@0 530 % The CLOSE button
Daniel@0 531 uicontrol(helpfig, ...
Daniel@0 532 'Style','push', ...
Daniel@0 533 'Units','normalized', ...
Daniel@0 534 'BackgroundColor', [0.6 0.6 0.6], ...
Daniel@0 535 'Position',[0.4 0.05 0.2 0.1], ...
Daniel@0 536 'String','Close', ...
Daniel@0 537 'Callback','close(gcf)');
Daniel@0 538
Daniel@0 539 watchoff(oldFigNumber);
Daniel@0 540
Daniel@0 541 end;
Daniel@0 542