-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranemf.asv
87 lines (63 loc) · 2.08 KB
/
branemf.asv
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
%% Implementation of the BraneMF
clear all;close all;
addpath code
%% load networks
load('data/neighborhood.mat')
load('data/fusion.mat')
load('data/cooccurence_adjacency_w1.mat')
load('data/coexpression_adjacency_w1.mat')
load('data/experimental_adjacency_w1.mat')
load('data/database_adjacency_w1.mat')
A = full(net1);
A(:,:,2) = full(net2);
A(:,:,3) = full(net3);
A(:,:,4) = full(net4);
A(:,:,5) = full(net5);
A(:,:,6) = full(net6);
%% setting parameters
dim = 500; %size of embedding
alpha2 = 1; %weignting factor
N = size(A,1); % number of vertices
M = size(A,3); % number of layers
%% compute random walk matrix (make sure your system is compatible to execute python codes)
for i = 1:M
L(:,:,i) = pyrunfile("rw_mat.py", "m", A = A(:,:,i), w = 3); %A = adjacency matrix, w = window size
end
N = size(L,1); % number of vertices
M = size(L,3); % number of layers
%% initialization
B = (L(:,:,1)+L(:,:,2)+L(:,:,3)+L(:,:,4)+L(:,:,5)+L(:,:,6)/6);
niter = 100;
options = optimset('Display','iter');
figure()
[P,D,Q] = svds(B,6400,'largest');
p = P(:)';
q = Q(:)';
d =D(:)';
alpha = 0.1;
beta = 1;
%% begin joint decomposition
for i = 1:niter
fun = @comeig_lbfgs_A;
% solve P while fixing Q and D
[p,fval,exitflag,output] = lbfgs(@comeig_lbfgs_A,p,N,M,L,D,Q,alpha,beta, options);
P = reshape(p',N,N);
fun = @comeig2_lbfgs_A;
% solve Q while fixing P and D
[q,fval,exitflag,output] = lbfgs(@comeig2_lbfgs_A,q,N,M,L,D,P,alpha,beta,options);
Q = reshape(q',N,N);
fun = @comeig_lbfgs_A;
% evaluate the objective function
cost(i) = comeig_lbfgs_A(p,N,M,L,D,Q,alpha,beta);
plot(i,cost(i),'.r')
hold on, drawnow
% stopping criterion
if i > 1 && abs(cost(i)-cost(i-1)) < 10^(-5)
break
end
end
v = P(:,1:dim);
d = D(1:dim,1:dim);
emb = v*(d^(alpha2));
filename = strcat('yeast_branemf_w_a_',num2str(alpha),'_b_',num2str(beta),'_d_',num2str(dim),'_alpha_',num2str(aa),'.txt');
writematrix(emb,filename,'Delimiter','tab')