This file is indexed.

/usr/share/octave/packages/octgpr-1.2.0/demo_octgpr.m is in octave-octgpr 1.2.0-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
% Copyright (C) 2008  VZLU Prague, a.s., Czech Republic
% 
% Author: Jaroslav Hajek <highegg@gmail.com>
% 
% This file is part of OctGPR.
% 
% OctGPR is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this software; see the file COPYING.  If not, see
% <http://www.gnu.org/licenses/>.
% 

% -*- texinfo -*- 
% @deftypefn {Function File} demo_octgpr (1, nsamp = 150)
% @deftypefnx {Function File} demo_octgpr (2, ncnt = 20, npt = 500)
% @deftypefnx {Function File} demo_octgpr (3, ncnt = 50, nsamp = 500)
% OctGPR package demo function.
% First argument selects available demos:
%
% @itemize
% @item 1. GPR regression demo @*
% A function is sampled (with small noise), then reconstructed using GPR
% regression.  @var{nsamp} specifies the number of samples.
% @seealso{gpr_train, gpr_predict}
% @item 2. RBF centers selection demo @*
% Radial basis centers are selected amongst random points.
% @var{ncnt} specifies number of centers, @var{npt} number of points.
% @item 2. PGP regression demo @*
% A function is densely sampled (with small noise), 
% radial basis centers are selected, then the function is reconstructed 
% using PGP regression.  @var{nsamp} specifies the number of samples,
% @var{ncnt} specifies number of centers.
% @end itemize
% @end deftypefn
function demo_octgpr (number, varargin)
  
  global prntfmt = '';

  if (nargin < 1)
    print_usage ();
  elseif (ischar (number))
    prntfmt = number;
  elseif (isscalar (number))
    figure ();
    if (! isempty (prntfmt))
      figure (gcf, "visible", "off");
    endif

    switch (number)
    case 1
      demo_octgpr1 (varargin{:})
    case 2
      demo_octgpr2 (varargin{:})
    case 3
      demo_octgpr3 (varargin{:})
    otherwise
      error ("demo_octgpr: invalid demo number")
    endswitch
  else
    print_usage ();
  endif

endfunction

function demo_octgpr_pause (idemo, iplot)
  global prntfmt;
  if (isempty (prntfmt))
    pause;
  else
    print (sprintf (prntfmt, idemo, iplot));
    fflush (stdout);
  endif
endfunction

% define the test function (the well-known matlab "peaks" plus some sines)
function z = testfun1 (x, y)
  z = 4 + 3 * (1-x).^2 .* exp(-(x.^2) - (y+1).^2) ...
      + 10 * (x/5 - x.^3 - y.^5) .* exp(-x.^2 - y.^2) ...
      - 1/3 * exp(-(x+1).^2 - y.^2) ...
      + 2*sin (x + y + 1e-1*x.*y);
endfunction

function demo_octgpr1 (nsamp = 150)
  global prntfmt;
  tit = "a peaked surface";
  disp (tit);

  % create the mesh onto which to interpolate
  t = linspace (-3, 3, 50);
  [xi,yi] = meshgrid (t, t);

  % evaluate
  zi = testfun1 (xi, yi);
  zimax = max (vec (zi)); zimin = min (vec (zi));
  subplot (2, 2, 1);
  mesh (xi, yi, zi);
  title (tit);
  subplot (2, 2, 3);
  contourf (xi, yi, zi, 20);
  demo_octgpr_pause (1, 1);

  tit = sprintf ("sampled at %d random points", nsamp);
  disp (tit);
  % create random samples
  xs = rand (nsamp,1); ys = rand (nsamp,1);
  xs = 6*xs-3; ys = 6*ys - 3;
  % evaluate at random samples
  zs = testfun1 (xs, ys);
  xys = [xs ys];

  subplot (2, 2, 2);
  plot3 (xs, ys, zs, ".+");
  title (tit);
  subplot (2, 2, 3);
  hold on
  plot (xs, ys, "+6");
  hold off
  subplot (2, 2, 4);
  plot (xs, ys, ".+");
  demo_octgpr_pause (1, 2);

  tit = "GPR model with heuristic hypers";
  disp (tit);
  ths = 1 ./ std (xys);
  GPM = gpr_train (xys, zs, ths, 1e-5);
  zm = gpr_predict (GPM, [vec(xi) vec(yi)]);
  zm = reshape (zm, size(zi));
  zm = min (zm, zimax); zm = max (zm, zimin);
  subplot (2, 2, 2);
  mesh (xi, yi, zm);
  title (tit);
  subplot(2, 2, 4);
  hold on
  contourf (xi, yi, zm, 20);
  plot (xs, ys, "+6");
  hold off
  demo_octgpr_pause (1, 3);

  tit = "GPR model with MLE training";
  disp (tit);
  fflush (stdout);
  GPM = gpr_train (xys, zs, ths, 1e-5, {"tol", 1e-5, "maxev", 400, "numin", 1e-8});
  zm = gpr_predict (GPM, [vec(xi) vec(yi)]);
  zm = reshape (zm, size (zi));
  zm = min (zm, zimax); zm = max (zm, zimin);
  subplot (2, 2, 2);
  mesh (xi, yi, zm);
  title (tit);
  subplot(2, 2, 4);
  hold on
  contourf (xi, yi, zm, 20);
  plot (xs, ys, "+6");
  hold off
  demo_octgpr_pause (1, 4);
  close

endfunction

function demo_octgpr2 (ncnt = 50, npt = 500)

  global prntfmt;
  npt = ncnt*ceil (npt/ncnt);
  U = rand (ncnt, 2);
  cs = min (pdist2_mw (U, 2) + diag (Inf (ncnt, 1)));
  X = repmat (U, npt/ncnt, 1) + repmat (cs', npt/ncnt, 2) .* randn (npt, 2);
  disp ("slightly clustered random points")
  plot (X(:,1), X(:,2), "+");
  demo_octgpr_pause (2, 1);

  [U, ur] = rbf_centers(X, ncnt);

  fi = linspace (0, 2*pi, 20);
  ncolors = rows (colormap);
  hold on
  for i = 1:rows (U)
    xc = U(i,1) + ur(i) * cos (fi);
    yc = U(i,2) + ur(i) * sin (fi);
    line (xc, yc);
  endfor
  hold off
  demo_octgpr_pause (2, 2);
  close

endfunction

function demo_octgpr3 (ncnt = 100, nsamp = 1000)

  global prntfmt;
  tit = "a peaked surface";
  disp (tit);

  % create the mesh onto which to interpolate
  t = linspace (-3, 3, 50);
  [xi,yi] = meshgrid (t, t);

  % evaluate
  zi = testfun1 (xi, yi);
  zimax = max (vec (zi)); zimin = min (vec (zi));
  subplot (2, 2, 1);
  mesh (xi, yi, zi);
  title (tit);
  subplot (2, 2, 3);
  contourf (xi, yi, zi, 20);
  demo_octgpr_pause (1, 1);

  tit = sprintf ("sampled at %d random points, selected %d centers", nsamp, ncnt);
  disp (tit);
  % create random samples
  xs = rand (nsamp,1); ys = rand (nsamp,1);
  xs = 6*xs-3; ys = 6*ys - 3;
  % evaluate at random samples
  zs = testfun1 (xs, ys);
  xys = [xs ys];

  % select centers using k-means
  xyc = rbf_centers (xys, ncnt);
  xc = xyc(:,1); yc = xyc(:,2);

  subplot (2, 2, 2);
  plot3 (xs, ys, zs, ".+");
  title (tit);
  subplot (2, 2, 3);
  hold on
  plot (xs, ys, "+6");
  hold off
  subplot (2, 2, 4);
  hold on
  plot (xs, ys, "+");
  plot (xc, yc, "o2");
  hold off
  demo_octgpr_pause (1, 2);

  tit = "PGP model with heuristic hypers";
  disp (tit);
  ths = 1 ./ std (xyc);
  GPM = pgp_train (xys, xyc, zs, ths, 1e-5);
  zm = pgp_predict (GPM, [vec(xi) vec(yi)]);
  zm = reshape (zm, size(zi));
  zm = min (zm, zimax); zm = max (zm, zimin);
  subplot (2, 2, 2);
  mesh (xi, yi, zm);
  title (tit);
  subplot(2, 2, 4);
  hold on
  contourf (xi, yi, zm, 20);
  plot (xs, ys, "+6");
  plot (xc, yc, "o5");
  hold off
  demo_octgpr_pause (1, 3);

  tit = "PGP model with MLE training";
  disp (tit);
  fflush (stdout);
  GPM = pgp_train (xys, xyc, zs, ths, 1e-3, {"tol", 1e-5, "maxev", 400});
  zm = pgp_predict (GPM, [vec(xi) vec(yi)]);
  zm = reshape (zm, size (zi));
  zm = min (zm, zimax); zm = max (zm, zimin);
  subplot (2, 2, 2);
  mesh (xi, yi, zm);
  title (tit);
  subplot(2, 2, 4);
  hold on
  contourf (xi, yi, zm, 20);
  plot (xs, ys, "+6");
  plot (xc, yc, "o5");
  hold off
  demo_octgpr_pause (1, 4);
  close

endfunction