-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathridgeregmethod.m
More file actions
30 lines (27 loc) · 952 Bytes
/
ridgeregmethod.m
File metadata and controls
30 lines (27 loc) · 952 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
26
27
28
29
30
function [Ttilde,optlambda,gof]=ridgeregmethod(x,y,lambdas);
% Computation of the estimated linear transformation T (i.e. such that y=Tx)
% via a cross-validated version of the ridge regression method.
%
% INPUT
% x: patterns in the ROIX
% y: patterns in the ROIY
% lambdas: set of possible regulariation parameter
% OUTPUT
% Ttilde: estimated transformation
% optlambda: optimal regularization parameter
% gof: goodness-of-fit
% Alessio Basti 20/02/2019 (Basti et al. 2019)
k=1;
for i=lambdas
H=x'*pinv(x*x'+i*eye(size(x,1)))*x;
for j=1:size(x,2)
A(j,j)=1/(1-H(j,j));
end
CrossValid(k)=(norm(A*((eye(size(x,2))-H)*y'),'fro'))^2;
k=k+1;
end
[B C]=min(CrossValid);
optlambda=lambdas(C);
gof=100*(1-B/(size(x,2)*size(y,1)));
Ttilde=y*x'*pinv(x*x'+optlambda*eye(size(x,1)));
return