bzr branch
http://darksoft.org/webbzr/ani/mrses
1
by Suren A. Chilingaryan
Initial import |
1 |
function res=mrses_orig(A,B,k,Niter,Ncycle,distmod) |
2 |
||
3 |
if (nargin<6) |
|
4 |
distmod=1; |
|
5 |
end
|
|
6 |
if (nargin<5) |
|
7 |
Ncycle=1000; |
|
8 |
end
|
|
9 |
if (nargin<4) |
|
10 |
Niter=500; |
|
11 |
end
|
|
12 |
if (nargin<3) |
|
13 |
k=5; |
|
14 |
end
|
|
15 |
if (nargin<2) |
|
16 |
error('As minimum two matrixes needed for MRSES'); |
|
17 |
end
|
|
18 |
if (nargin>6) |
|
19 |
error('Too much parameters'); |
|
20 |
end
|
|
21 |
||
22 |
||
23 |
sa=size(A);sb=size(B); |
|
24 |
if (sa(2)==sb(2)) |
|
25 |
genes=sa(2); |
|
26 |
else
|
|
27 |
error('Features dimension mismatch'); |
|
28 |
end
|
|
29 |
||
30 |
||
31 |
optki=zeros(Ncycle,k); |
|
32 |
for icycle=1:Ncycle |
|
33 |
% SELECT k GENES {ki} FOR TEST AND EXCLUDE THEM FROM ALL GENES {ke}
|
|
34 |
tt=randperm(genes); |
|
35 |
||
36 |
ki=tt(1:k); |
|
37 |
ke=tt(k+1:end); |
|
38 |
||
39 |
for iter=1:Niter |
|
40 |
dist1=bmc(A(:,ki),B(:,ki)); |
|
41 |
||
42 |
xki=ceil(rand(1)*k); |
|
43 |
xke=ceil(rand(1)*(genes-k)); |
|
44 |
||
45 |
t=ki(xki); |
|
46 |
ki(xki)=ke(xke); |
|
47 |
ke(xke)=t; |
|
48 |
||
49 |
dist2=bmc(A(:,ki),B(:,ki)); |
|
50 |
||
51 |
if(dist2(distmod)<dist1(distmod)) % COMPARES BHATA DISTANCES 1-bhata, 2-mahal, 3-corr |
|
52 |
t=ki(xki); |
|
53 |
ki(xki)=ke(xke); |
|
54 |
ke(xke)=t; |
|
55 |
end
|
|
56 |
||
57 |
end
|
|
58 |
optki(icycle,:)=ki; |
|
59 |
end
|
|
60 |
optki=reshape(optki,1,[]); |
|
61 |
[n,g]=hist(optki,1:genes); |
|
62 |
H=[n./Ncycle;g]; |
|
63 |
res=flipud(sortrows(H')); |
|
64 |
||
65 |
||
66 |
% DISTANCE CALCULATOR
|
|
67 |
function [rbhata,rmahal,rcorr]=bmc(x1,x2) |
|
68 |
||
69 |
c1=cov(x1,1); |
|
70 |
c2=cov(x2,1); |
|
71 |
c=(c1+c2)./2; |
|
72 |
||
73 |
m1=mean(x1); |
|
74 |
m2=mean(x2); |
|
75 |
||
76 |
rmahal=((m2-m1)/c)*(m2-m1)'; |
|
77 |
rcorr=2.*log(det(c)./sqrt(det(c1).*det(c2))); |
|
78 |
rbhata=rmahal./8+rcorr./4; |