Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[3a718b]: inst / @CovarSMW / CovarSMW.m Maximize Restore History

Download this file

CovarSMW.m    47 lines (39 with data), 1.5 kB

 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
% Covariance matrix than can be inverted using the Sherman-Morrison-Woodbury
% forumla.
%
% CSMW = CovarSMW(C,B)
%
% Create the covariance matrix CSMW = C + B*B' than can be inverted efficiently
% using the Sherman-Morrison-Woodbury formula, if size(B,2) is much smaller than
% size(C,1):
%
% inv(C + B*B') = inv(C) - inv(C)*B*inv(B'*inv(C)*B + I)*B'*inv(C)
%
% The symetric matrix C should implement the methods: size, diag, mtimes,
% mldivde and the matrix B should implement the methods: size, tranpose, mtimes,
% sum.
function retval = CovarSMW(C,B)
if size(C,1) ~= size(C,2)
error('C should be square matrix');
end
if size(C,1) ~= size(B,1)
error('size of C and B are not compatible');
end
self.C = C;
self.B = B;
self.D = inv(B' * (C \ B) + eye(size(B,2)));
retval = class(self,'CovarSMW');
% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be>
%
% 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, see <http://www.gnu.org/licenses/>.