-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_data_analyses_drop_rate.asv
154 lines (112 loc) · 3.14 KB
/
matrix_data_analyses_drop_rate.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
clear
newcolors = ["#0072BD", "#D95319", "#EDB120", "#7E2F8E","#77AC30","#4DBEEE",];
% colors = blue , orange,yellow,purple,green,turquoise,red
S = ["Wf_dr_0.09.mat";
"Wf_dr_0.02.mat";
"Wf_dr_0.005.mat"
];
dr = [0.09,0.02,0.005];
max_errors=zeros(length(S),4000);
load("max_errors_dr.mat");
for s = 1:length(S)
load(S(s));
n_epochs = size(Wfs,3);
n_neuron = size(Wfs,1);
alpha = linspace(0,2*pi,n_neuron+1);alpha = alpha(1:end-1)';
F = [cos(alpha),sin(alpha)]';
vn= vecnorm(F,2,1);
mu = 1*1e-5;
lambdaD = 10;
lambdaV = 0;
F = 0.03*F./vn;
A = [0 , 1 ; -1, -10];
J = size(A,1);
Threshold = (vecnorm(F,2,1)'.^2 + mu)/2;
TE = 1;
dt = 0.1e-3;
t= dt:dt:TE;
n_time = length(t);
pt= 0.01*n_time;
c = 10*[zeros(J,15*pt),ones(J,30*pt),0*-1*ones(J,30*pt),zeros(J,25*pt)];
c = 10*(sin(3*pi*t)*)
Wf_true = round(-F'*F - mu*eye(n_neuron),9);
Ws_true = round(F'*(A+lambdaD*eye(J))*F,9);
[xE,xT,~,~,~]= simulate_network(A,c,F,Threshold,n_time,dt,...
Ws_true,Wf_true,lambdaD,lambdaV);
x = 1:n_epochs;
eigs =zeros(n_neuron,n_epochs);
largest_rel_dev = zeros(1,n_epochs);
means = zeros(1,n_epochs);
stds = zeros(1,n_epochs);
max_error = zeros(1,n_epochs);
err = 0;
for i = 1:n_epochs
mat = Wfs(:,:,i);
true_matrix = Wf_true;
% Error
% try
% [xE,xT,~,~,~]= simulate_network(A,c,F,Threshold,n_time,dt,...
% Ws_true,mat,lambdaD,lambdaV);
% max_error(i) = max(abs(xE-xT),[],"all");
% catch exception
% err = err+1;
% max_error(i) = NaN;
% end
% Eigenvalues
eigs(:,i) = eig(mat);
% Largest deviations
dM = mat-true_matrix;
dM2 = dM./true_matrix;
dM2 = abs(dM2);
[v,k] = max(dM2(~isinf(dM2)),[],"all","linear");
largest_rel_dev(i) = dM2(k);
% statistic deviations
stds(i) = std(dM,1,"all");
means(i)= mean(abs(dM2),"all");
end
% max_errors(s,1:n_epochs)=max_error;
display(num2str(err) +"matrices didnt converge")
%semilogx(x,means)
%%
if(s == 1)
f = figure();
f.Position =[0,600,1300,700];
tt = tiledlayout(3,1,"TileSpacing","tight","Padding","none");
end
nexttile(1,[1,1])
semilogx(x,eigs(1:2,:),"LineWidth",3,"Marker",".","MarkerSize",5,"Color",newcolors(s))
hold on
ax = gca;
grid on
ax.FontSize = 20;
if(s == 1)
semilogx([1,10000],[-0.024,-0.024],"Color",[0.9290 0.6940 0.1250])
text(1.5,-0.024+0.0003,"optimal","FontSize",20,"Color",...
[0.9290 0.6940 0.1250],"Interpreter","latex",...
"EdgeColor",[0.9290 0.6940 0.1250],"LineWidth",1,...
"VerticalAlignment","bottom");
end
legend(["$p = 0.09$","","","$p = 0.02$","","$p = 0.005$",""],"FontSize",30,"Interpreter","latex");
xticklabels({});
nexttile(2,[1,1])
semilogx(x,largest_rel_dev,"LineWidth",3,"Marker",".","MarkerSize",5)
hold on
ax = gca;
grid on
ax.FontSize = 20;
xticklabels({});
ax = nexttile(3,[1,1]);
semilogx(x,max_errors(s,x),"LineWidth",3,"Marker",".","MarkerSize",5)
ylim([0,3])
hold on
grid on
ax = gca;
%ax.YTick = ticks;
ax.FontSize = 20;
xlabel("\# Epoch","FontSize",30,"Interpreter","latex");
end
folder = "/home/max/Documents/University/Master Thesis/plots/Learning/";
prompt = "File name: ";
name = input(prompt,"s");
dest = strcat(folder,name)
exportgraphics(f,dest,"ContentType","vector");