-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualize.m
134 lines (114 loc) · 5.33 KB
/
Visualize.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function [e, active, AD, Perception, ToP, unqActive, unqA, Converge] = Visualize(Initiated_Pattern, Noise, pat, AllStates, w, scale, showHeat, ActFun, stateMag, PerceptionThreshold)
%main function that asynchronously updates network states.
%% input variables
%initiated pattern: initial state of the network
% Noise: desired SNR input
% pat: stored patterns
% AllStates: all possible energy states, generated by EnergyLandscape.m
% w: weights
% scale: scaling factor (do not use, artifact of earlier version of code)
% showHeat: show heat map for associations (extent of overlap between
% current network state and stored patterns
%ActFun: Activation function scaling factor to change threshold of
% activation (do not use)
% stateMag: do not use
% PerceptionThreshold: description in main
%% output variable
% e: energy trajectory of network over some time span
% active: number of active nodes over time span
% AD: association distribution, extent of overlap for each time point of
% network with each stored pattern
% remainder were added later and used to quantify results that are plotted
% at the very end.
%%
global n %number of stored patterns
global N %total number of nodes
global time %time over which network will run
global figurePause % toggle for realtime network evolution
global go
r = Initiated_Pattern;
e = NetEnergy(w, r, N, stateMag);
ToP = []; %time during which network is makign clear association
Vis = figure(); set(0, 'CurrentFigure', Vis)
SNR = Noise; %SNR
NoA = [];
for t=2:time;
maxidx = [];
r(:,t) = sign(w*awgn(r(:,t-1),SNR)-ActFun);
% r(:,t) = sign(w*imnoise(r(:,t-1),'Poisson')-ActFun);
overlap = (r(:,t)'*pat/N);
maxoverlap = max(overlap);
maxidx = find(overlap >= PerceptionThreshold);
active(:,t) = sum(1 == r(:,t));
AD(:,t) = overlap;
e(t) = NetEnergy(w, r(:,t), N, stateMag);
NoA= [NoA maxidx]; % store number of associations
if maxidx > 0;
ToP(1,t) = t;
ToP(2,t) = e(t);
end %time during which network is makign clear association
if figurePause >0 | t==max(time)
pause(figurePause);
set(0, 'CurrentFigure', Vis)
subplot(2,2,[1 2]); plot (e); xlim ([0 time]); xlabel ('Iteration Number'); ylabel('Network Energy');
% title ([ num2str(N) ' Nodes, ' num2str(n) ' Patterns, ' num2str(SNR) ' SNR, w^{', num2str(scale), '} Scaling, ActFun = ' num2str(ActFun)]);
title ([ num2str(N) ' Nodes, ' num2str(n) ' Patterns, SNR = ' num2str(SNR) ]);
if t==max(time) & ~isempty(ToP)
hold on; plot(ToP(1,:),ToP(2,:), 'o'); hold off
end
if length(AllStates)>0
maxState = refline(0,max(AllStates));
maxState.Color = 'r';
maxState.LineStyle = '--';
minState = refline(0,min(AllStates));
minState.Color = 'r';
minState.LineStyle = '--';
if go == 1;
set(gca, 'ylim', [(min(AllStates)-(0.1*max(AllStates))) (max(AllStates)+(0.1*max(AllStates)))]);
legend('Energy Trajectory',['>=' num2str(PerceptionThreshold*100) '% pattern overlap'], 'Energy Boundaries');
else
set(gca, 'ylim', [(min(AllStates)-(0.1*max(AllStates))) (max(AllStates)+(0.1*max(AllStates)))]);
legend('Energy Trajectory', ['>=' num2str(PerceptionThreshold*100) '% pattern overlap']);
end
end
set(0, 'CurrentFigure', Vis)
if showHeat ==1
subplot(223); imagesc(overlap); set (gca, 'xtick', [1:n]); xlabel('Pattern'); set (gca, 'ytick', []);
c = colorbar(); caxis([-1 1]); ylabel(c, 'Overlap with Stored Pattern'); colormap ('bone');
pause(0.0001);
for k = 1:n
Perception(k,t) =sum(NoA == k); %proportion of perception time taken on single pattern
Perception(k,t) = 100*Perception(k,t)/time;
if Perception(k,t) > 0
Converge(k) = 1;
else
Converge(k) = 0;
end
end
set(0, 'CurrentFigure', Vis)
subplot(224); bar(Perception(:,t)); title('Associations'); ylabel('Proportion of Time Perceiving (%)'); xlabel('Pattern');
else
for k = 1:n
Perception(k,t) =sum(NoA == k); %proportion of perception time taken on single pattern
Perception(k,t) = 100*Perception(k,t)/time;
if Perception(k,t) > 0
Converge(k) = 1;
else
Converge(k) = 0;
end
end
set(0, 'CurrentFigure', Vis)
subplot(2,2,[3 4]); bar(Perception(:,t)); title('Associations'); ylabel('Proportion of Time Perceiving (%)'); xlabel('Pattern');
ylim([0 100]);
end
end
end
active(:,t) = sum(1 == r(:,t));
for i = 1:N
if sum(1==r(i,:))>0;
unqA(i) = 1 ; %unique nodes that were activated
else
unqA(i) = 0;
end
end
unqActive = 100*sum(unqA)/N; %percent of entire network that is activated other entire time course (unique activations)