Download this file

26 lines (23 with data), 564 Bytes

 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
function [R,tau] = mcholinc(H,verbose)
% Computes Cholesky of H+tau*I, for suitably large tau that matrix is pd
p = size(H,1);
beta = norm(H,'fro');
if min(diag(H)) > 1e-12
tau = 0;
else
if verbose
fprintf('Small Value on Diagonal, Adjusting Hessian\n');
end
tau = max(beta/2,1e-12);
end
while 1
[R,posDef] = chol(H+tau*eye(p));
if posDef == 0
break;
else
if verbose
fprintf('Cholesky Failed, Adjusting Hessian\n');
end
tau = max(2*tau,beta/2);
end
end