/usr/share/octave/packages/octgpr-1.2.0/rbf_centers.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 | % 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} {[U, ur, iu]} = rbf_centers (@var{X}, @var{nu}, @var{theta})
% Selects a given number of RBF centers based on Lloyd's clustering algorithm.
%
% @end deftypefn
function [U, ur, iu] = rbf_centers (X, nu, theta)
if (nargin == 3)
X *= diag (theta);
elseif (nargin != 2)
print_usage ();
endif
% the D^2 weighting initialization
D = Inf;
kk = 1:rows (X);
cp = kk;
for i = 1:nu
jj = sum (rand() * cp(end) < cp);
k(i) = kk(jj);
kk(jj) = [];
U = X(k(i),:);
D = min (D, pdist2_mw(X, U, 'ssq')');
cp = cumsum (D(kk));
endfor
% now perform the k-means algorithm
U = X(k,:);
D = pdist2_mw (U, X, 'ssq');
[xx, j] = min (D);
it = 0;
do
for i = 1:columns (X)
U(:,i) = accumarray (j.', X(:,i), [nu, 1]);
endfor
N = accumarray (j.', ones (1, length (j)), [nu, 1]);
U = diag (N) \ U;
i = find (all (U == 0, 2));
U(i,:) = X(ceil (rand (1, length (i)) * rows (X)), :);
j1 = j;
D = pdist2_mw (U, X, 'ssq');
[xx, j] = min (D);
fprintf (stderr, "k-means iteration %d\r", ++it);
until (all (j == j1))
fprintf (stderr, "\n");
if (nargout > 2)
iu = j;
endif
if (nargout > 1)
ur = zeros (nu, 1);
for i = 1:nu
ij = (j == i);
ur(i) = sqrt (max (D(i,ij)));
endfor
endif
if (nargin == 3)
U = dmult (U, 1./theta);
if (any(theta == 0))
U(:,theta == 0) = 0;
endif
endif
endfunction
|