%
% CHOLINCSP_TEST - minimal test harness for CHOLINCSP
%
%    CHOLINCSP_TEST is a minimal test harness and demonstration program for
%    CHOLINCSP a vectorised MATLAB implementation of Fine and Scheinberg's
%    incomplete Cholesky factorisation with symmetric pivoting [1].
%
%    References :
%
%       [1] Fine, S. and Scheinberg, K., "Efficient SVM training using
%           low-rank kernel representations", Journal of Machine Learning
%           Research, vol. 2, pp 243-264, December 2001.
%
%    See also : CHOLINCSP

%
% File        : cholincsp_test.m
%
% Date        : Wednesday 11th August 2004
%
% Author      : Gavin C. Cawley
%
% Description : Minimal test harness for a vectorised MATLAB implementation
%               of Fine and Scheinberg's incomplete Cholesky factorisation
%               with symmetric pivoting [1].
%
% References  : [1] Fine, S. and Scheinberg, K., "Efficient SVM training
%                   using low-rank kernel representations", Journal of Machine
%                   Learning Research, vol. 2, pp 243-264, December 2001.
%
% History     : 10/08/2004 - v1.00
%
% Copyright   : (c) Dr Gavin C. Cawley, August 2004.
%
%    This program 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 2 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 program; if not, write to the Free Software
%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%

% start from a clean slate

clear all;

% set up demonstration parameters

d = 6;   % the dimensions of X
r = 4;   % the rank of X

% create a rank-defficient positive semi-definite symmetric matrix X

fprintf(1, '\n');
fprintf(1, 'X is a positive semi-definite symmetric matrix\n');

X = randn(d,r)*randn(r,d);
X = X'*X

fprintf(1, 'but it is not of full rank\n');
fprintf(1, '\n');
fprintf(1, '   >> rank(X)\n');

rank(X)

fprintf(1, 'looking at its eigenvalues...\n');
fprintf(1, '\n');
fprintf(1, '   >> eig(X)\n');

eig(X)'

fprintf(1, 'we can see CHOL fails as X is only positive SEMI-definite...\n');
fprintf(1, '\n');
fprintf(1, '   >> R = chol(X)\n');

try

   R = chol(X);

catch

   fprintf(1, ['\n' lasterr '\n\n']);

end

fprintf(1, 'performing an incomplete Cholesky factorisation...\n');
fprintf(1, '\n');
fprintf(1, '   >> [R,p] = cholincsp(X)\n');

[R,p] = cholincsp(X)

fprintf(1, 'R*R'' is a permutation of X,\n');
fprintf(1, '\n');
fprintf(1, '   >> R*R''\n');

R*R'

fprintf(1, '   >> X(p,p)\n');

X(p,p)

% bye bye...

