-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStep6_traveling_HCP.m
189 lines (168 loc) · 5.68 KB
/
Step6_traveling_HCP.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
%% HCP 复现CPCA行波
% 查看原始行波
clear;clc;
load('.\utility\CPCAsurf.mat');
for i = 1:3
figure
trimesh(Face_L+1., Vert_L(:,2),Vert_L(:,1),Vert_L(:,3), pca_comps(i,1:2562),'LineWidth',1.5);
colormap hsv
caxis([-pi,pi])
title(['CPCA comps ' num2str(i)])
end
colorbar
%% 参数设置
node = size(pca_comps,2);
V1 = [cos(pca_comps(1,:)') sin(pca_comps(1,:)')];
V2 = [cos(pca_comps(2,:)') sin(pca_comps(2,:)')];
V3 = [cos(pca_comps(3,:)') sin(pca_comps(3,:)')];
param.node = node;
endp = 30;
watchp = 25;
Mat = [V1 V2 V3] * pinv([V1 V2 V3]);
param.Mat = Mat; % 连接矩阵
param.inputtime = 10; % 输入时间
param.inputpulse = 0.0; % 输入大小
param.inputstd = 0.3;
param.sigma = 0.0;
param.Noise = [];
param.a = 1;
param.b = 10 * 2*pi;
param.alpha = 8*node;
param.dt = 0.01;
% 欧拉法
Af = zeros(1000, 3);
x = 2*pi*rand(1,node)'-pi;
X = zeros(node,1002);
U = sin(x - x');
tic
for t = 1:1001
U = sin(x - x');
dx = param.alpha * diag(Mat * U) / node;
x = x + 0.002 * dx;
X(:,t+1) = x;
Af(t,1) = abs(Wfunc(exp(1j*x'), exp(1j*pca_comps(1,:))))^2 -...
abs( Wfunc( exp(1j*x'), exp(-1j*pca_comps(1,:)) ) )^2;
Af(t,2) = abs(Wfunc(exp(1j*x'), exp(1j*pca_comps(2,:))))^2 -...
abs( Wfunc( exp(1j*x'), exp(-1j*pca_comps(2,:)) ) )^2;
Af(t,3) = abs(Wfunc(exp(1j*x'), exp(1j*pca_comps(3,:))))^2 -...
abs( Wfunc( exp(1j*x'), exp(-1j*pca_comps(3,:)) ) )^2;
t
end
toc
%% 历时 14125.090263 秒。
tic
inT = 0.23:0.02:0.43;
B = zeros(length(inT),length(inT));
for x = 1:length(inT)
for y = 1:length(inT)
for i = 1:3
param.Mat = [inT(x)*V1 inT(y)*V2 (1-inT(x)-inT(y))*V3] * pinv([V1 V2 V3]);
J = Kuramoto_Jakobi(pca_comps(i,:),param, 2);
D = eig(J);
if max(real(D)) > 2e-10
B(x,y) = B(x,y) + 2^(i-1);
end
% figure
% scatter(real(D),imag(D),'filled');
% xline(0);
% title(num2str(i))
end
toc
end
x
end
imagesc(inT,inT,flipud(B))
set(gca,'YTick', 0.24:0.02:0.42);
set(gca,'YTicklabel', {'0.42','0.40','0.38','0.36','0.34',...
'0.32','0.30', '0.28', '0.26', '0.24'});
% set(gca,'XTicklabel', {'0.22','0.24','0.26','0.28','0.30','0.32',...
% '0.34','0.36', '0.38', '0.40', '0.42', '0.44'});
% xlabel('$\lambda_{P2}$', 'FontSize',12, 'Interpreter', 'latex');
% ylabel('$\lambda_{P1}$', 'FontSize',12, 'Interpreter', 'latex');
% grid on
% 000 0
% 001 1
% 010 2
% 011 3
% 100 4
% 101 5
% 110 6
%% GPU 加速版
% pca_comps = gpuArray(pca_comps);
% pca_comps = single(pca_comps);
node = size(pca_comps,2);
V1 = [cos(pca_comps(1,:)') sin(pca_comps(1,:)')];
V2 = [cos(pca_comps(2,:)') sin(pca_comps(2,:)')];
V3 = [cos(pca_comps(3,:)') sin(pca_comps(3,:)')];
tic
inT = 0.23:0.01:0.43;
B = zeros(length(inT),length(inT));
for x = 1:length(inT)
for y = 1:length(inT)
for i = 1:3
M = [inT(x)*V1 inT(y)*V2 (1-inT(x)-inT(y))*V3] * pinv([V1 V2 V3]);
Q = M .* cos(pca_comps(i,:) - pca_comps(i,:)');
J = Q - diag(sum(Q,2));
D = eig(J);
if max(real(D)) > 2e-10
B(x,y) = B(x,y) + 2^(i-1);
end
% figure
% scatter(real(D),imag(D),'filled');
% xline(0);
% title(num2str(i))
end
toc
end
x
end
colormap pink
s = pcolor(B);
s.EdgeColor = [0.8 0.8 0.8];
set(gca,'XTick', 1.5:2:21.5);
set(gca,'XTicklabel', {'0.23','0.25','0.27','0.29','0.31','0.33',...
'0.35','0.37', '0.39', '0.41', '0.43'});
set(gca,'YTick', 1.5:2:21.5);
set(gca,'YTicklabel', {'0.23','0.25','0.27','0.29','0.31','0.33',...
'0.35','0.37', '0.39', '0.41', '0.43'});
xlabel('$\lambda_{P2}$', 'FontSize',16, 'Interpreter', 'latex');
ylabel('$\lambda_{P1}$', 'FontSize',16, 'Interpreter', 'latex');
%%
hold on
B_ = B';
for i = 2:20
for j = 1:20
if (B_(i,j) - B_(i-1, j) ~=0 )
if (ismember(B_(i,j), [0 2 4 6]) && ~ismember(B_(i-1, j), [0 2 4 6])) || ...
(~ismember(B_(i,j), [0 2 4 6]) && ismember(B_(i-1, j), [0 2 4 6]))
line([i i], [j j+1], 'color', [0 0.4470 0.7410], 'LineWidth', 1.5);
end
if (ismember(B_(i,j), [0 1 4 5]) && ~ismember(B_(i-1, j), [0 1 4 5])) || ...
(~ismember(B_(i,j), [0 1 4 5]) && ismember(B_(i-1, j), [0 1 4 5]))
line([i i], [j j+1], 'color', [0.8500 0.3250 0.0980], 'LineWidth', 1.5);
end
if (ismember(B_(i,j), [0 1 2 3]) && ~ismember(B_(i-1, j), [0 1 2 3])) || ...
(~ismember(B_(i,j), [0 1 2 3]) && ismember(B_(i-1, j), [0 1 2 3]))
line([i i], [j j+1], 'color',[0.9290 0.6940 0.1250], 'LineWidth', 1.5);
end
end
end
end
for i = 1:20
for j = 2:20
if (B_(i,j) - B_(i, j-1) ~=0 )
if (ismember(B_(i,j), [0 2 4 6]) && ~ismember(B_(i, j-1), [0 2 4 6])) || ...
(~ismember(B_(i,j), [0 2 4 6]) && ismember(B_(i, j-1), [0 2 4 6]))
line([i i+1], [j j], 'color',[0 0.4470 0.7410], 'LineWidth', 1.5);
end
if (ismember(B_(i,j), [0 1 4 5]) && ~ismember(B_(i, j-1), [0 1 4 5])) || ...
(~ismember(B_(i,j), [0 1 4 5]) && ismember(B_(i, j-1), [0 1 4 5]))
line([i i+1], [j j], 'color', [0.8500 0.3250 0.0980], 'LineWidth', 1.5);
end
if (ismember(B_(i,j), [0 1 2 3]) && ~ismember(B_(i, j-1), [0 1 2 3])) || ...
(~ismember(B_(i,j), [0 1 2 3]) && ismember(B_(i, j-1), [0 1 2 3]))
line([i i+1], [j j], 'color',[0.9290 0.6940 0.1250], 'LineWidth', 1.5);
end
end
end
end