forked from jcollfont/inverseecg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tikhonovburak.m
64 lines (50 loc) · 1.64 KB
/
tikhonovburak.m
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
function [X_reg, lambda] =tikhonovburak(A,L,Y,lambdas,varargin)
% Function to calculate the Greensite inverse solution
% A - forward matrix
% L - regularization matrix
% Y - data
% X_reg - inverse solution
MANUALFLAG=0;
if(numel(varargin)>0)
if(strcmpi(varargin{1},'manual'))
MANUALFLAG=1;
end
end
LL=(L'*L);
AA=(A'*A);
for i=1:size(Y,2)
eta=zeros(numel(lambdas),1);
rho=zeros(numel(lambdas),1);
for k=1:numel(lambdas)
temp = (AA+lambdas(k)*LL)\(A'*Y(:,i));
eta(k)=norm(L*temp);
rho(k)=norm(Y(:,i)-A*temp);
end
% [lambda,rho_c,eta_c] = l_corner(rho,eta,lambdas);
if(MANUALFLAG==1)
figure(1), loglog(rho,eta)
[rho_c,eta_c]=ginput(1); [val,ind]=min(sum([rho-rho_c,eta-eta_c].^2,2)); lambda=lambdas(ind);
hold on, loglog(rho_c,eta_c,'ro'),hold off
else
rholog=log10(rho); etalog=log10(eta); Trho=2*numel(lambdas);
etalog=spline(rholog,etalog,linspace(min(rholog),max(rholog),Trho));
etalog=lowpassma(etalog,10);
lambdaspline=spline(rholog,lambdas,linspace(min(rholog),max(rholog),Trho));
% rholog=linspace(min(rholog),max(rholog),Trho);
detalog=diff(etalog,2);
signchanges=diff(sign(detalog));
lastchangeind=find(signchanges<0,1,'last');
lambda=lambdaspline(lastchangeind);
end
% figure(1)
% loglog(rho,eta,'b')
% hold on
% loglog(10^rholog(lastchangeind),10^etalog(lastchangeind),'ro')
% hold off
% pause
if ~numel(lambda)
lambda = lambdas(ceil(end/2));
end
X_reg(:,i) = (AA+lambda*LL)\(A'*Y(:,i));
fprintf('t=%i\n',i)
end