-
Notifications
You must be signed in to change notification settings - Fork 8
/
affinity_propagation.m
executable file
·35 lines (33 loc) · 1.13 KB
/
affinity_propagation.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
function idx = affinity_propagation(sbeG)
%AFFINITY_PROPAGATION - affinity propagation
%
% Systems Biology and Evolution Toolbox (SBEToolbox).
% Authors: Kranti Konganti, James Cai.
% (C) Texas A&M University.
%
% $LastChangedDate: 2012-12-28 19:01:43 -0600 (Fri, 28 Dec 2012) $
% $LastChangedRevision: 278 $
% $LastChangedBy: konganti $
%
N=size(sbeG,1); A=zeros(N,N); R=zeros(N,N); % Initialize messages
sbeG=sbeG+(eps*sbeG+realmin*100).*rand(N,N); % Remove degeneracies
lam=0.5; % Set damping factor
for iter=1:100
% Compute responsibilities
Rold=R;
AS=A+sbeG; [Y,I]=max(AS,[],2);
for i=1:N AS(i,I(i))=-realmax; end;
[Y2,I2]=max(AS,[],2);
R=sbeG-repmat(Y,[1,N]);
for i=1:N R(i,I(i))=sbeG(i,I(i))-Y2(i); end;
R=(1-lam)*R+lam*Rold; % Dampen responsibilities
% Compute availabilities
Aold=A;
Rp=max(R,0); for k=1:N Rp(k,k)=R(k,k); end;
A=repmat(sum(Rp,1),[N,1])-Rp;
dA=diag(A); A=min(A,0); for k=1:N A(k,k)=dA(k); end;
A=(1-lam)*A+lam*Aold; % Dampen availabilities
end;
E=R+A; % Pseudomarginals
I=find(diag(E)>0); K=length(I); % Indices of exemplars
[tmp c]=max(sbeG(:,I),[],2); idx=I(c); % Assignments