-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestW.m
27 lines (27 loc) · 780 Bytes
/
estW.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
% Function
function [W] = estW(X,S,Wo)
K = 1; % Number of optimization iterations
% [n,m] = size(X);
% Normalization of X
X = normalize(X);
d = size(S,1);
% W = rand(m,d);
% W = randn(m,d);
% W = Wo+randn(m,d);
% W = double(Wo~=0);
% W = double(Wo>0.25);
W = Wo;
L=X*W;
for k=1:K
for i=1:d
disp(i);
options = optimoptions('fmincon','Display','iter','MaxFunEvals',1e5);
ind = W(:,i)~=0;
% abs() before sum
fun=@(w)(-1*sum(([S(i,1:i-1) S(i,i+1:end)].*corr(X(:,ind)*w,[L(:,1:i-1) L(:,i+1:end)])))/d);
W(ind,i) = fmincon(fun,W(ind,i),[],[],[],[],[],[],[],options);
L=X*W;
end
end
%criterion=mean(diag(transpose(W)*corr(X)*W));
end