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

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