-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfcn_match_strength.m
More file actions
51 lines (46 loc) · 1.13 KB
/
Copy pathfcn_match_strength.m
File metadata and controls
51 lines (46 loc) · 1.13 KB
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
function [aw,err] = fcn_match_strength(ar,w,s,niter,temp,dec)
n = length(ar);
[u,v] = find(triu(ar,1));
indx = (v - 1)*n + u;
aw = zeros(n);
aw(indx) = w;
aw = aw + aw';
sw = sum(aw,2);
errvec = abs(sw - s);
err = sum(errvec);
m = length(u);
errbest = err;
wbest = w;
fprintf('%i - %.3f\n',1,errbest);
for iter = 1:niter
x = randi(m);
y = randi(m);
ux = u(x);
vx = v(x);
uy = u(y);
vy = v(y);
swp = sw;
swp([ux,vx]) = swp([ux,vx]) - w(x) + w(y);
swp([uy,vy]) = swp([uy,vy]) + w(x) - w(y);
errvecp = errvec;
errvecp([ux,vx,uy,vy]) = abs(swp([ux,vx,uy,vy]) - s([ux,vx,uy,vy]));
errp = sum(errvecp);
if errp < err || rand < exp(-(errp - err)./temp);
w([x,y]) = w([y,x]);
err = errp;
errvec = errvecp;
sw = swp;
if err < errbest
errbest = err;
wbest = w;
end
end
temp = temp*dec;
% if mod(iter,50000) == 0
% fprintf('%i - %.3f\n',iter,errbest);
% end
end
fprintf('%i - %.3f\n',iter,errbest);
aw = zeros(n);
aw(indx) = wbest;
aw = aw + aw';