-
Notifications
You must be signed in to change notification settings - Fork 2
/
T_sweep_sps.m
198 lines (158 loc) · 7.89 KB
/
T_sweep_sps.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
190
191
192
193
194
195
196
197
198
%% find optimum T for LSD and PL (may be the same)
% if you are not getting any strong correlations then you may have
% reordered your centroids since calculating the transition probabilities
% or subcentroids and need to re-do one of those so that they are in the
% same order
clear all; close all;
basedir = '/Users/sps253/Documents/energy_landscape';
cd(basedir);
%% set inputs
numClusters = 4;
split='main'
load(fullfile(['data/',split,'.mat']))
savedir = fullfile(basedir,'results','example');mkdir(savedir); % set save directory
load(fullfile(savedir,['TransProbsData_bp',num2str(split),'_k',num2str(numClusters),'.mat']))
load(fullfile(savedir,['subjcentroids_split',num2str(split),'_k',num2str(numClusters),'.mat']),'centroids')
LSD_centroids = squeeze(mean(centroids(1:nsubjs,:,:)));
PL_centroids = squeeze(mean(centroids(nsubjs+1:nsubjs*2,:,:)));
load(fullfile(savedir,['Partition_bp',num2str(split),'_k',num2str(numClusters),'.mat']),'centroids')
% c = 0;
C_rng = 0 %[0:1:5];
nC = length(C_rng);
for k=1:nC
Anorm = NORMALIZE(sc,C_rng(k)); % normalize A by maximum eigenvalue - eye(N) to make marginally stable
%% Compare group average E_full with Transprobs
T_rng = [0.001:0.5:10]; nT = length(T_rng);
Xf_ind = repmat(1:numClusters,[1 numClusters]); % final state order
Xo_ind = repelem(1:numClusters,numClusters); % paired with different initial states, use reshape(x,[numClusters numClusters])' to get matrix
onDiag = (1:numClusters) + (numClusters*(0:(numClusters-1)));
offDiag = 1:(numClusters^2); offDiag(onDiag) = []; % isolate off diagonal from linearized transition probabilities
x0 = centroids(:,Xo_ind);
xf = centroids(:,Xf_ind);
x0_L = LSD_centroids(:,Xo_ind);
xf_L = LSD_centroids(:,Xf_ind);
x0_P = PL_centroids(:,Xo_ind);
xf_P = PL_centroids(:,Xf_ind);
% now each column of x0 and xf represent state transitions
E_full_grpavg_T = NaN(nT,numClusters^2);
E_full_LSD_T = NaN(nT,numClusters^2);
E_full_PL_T = NaN(nT,numClusters^2);
E_w_grpavg_T = NaN(nT,numClusters^2);
E_w_LSD_T = NaN(nT,numClusters^2);
E_w_PL_T = NaN(nT,numClusters^2);
for i=1:nT
T=T_rng(i);
WcI = GRAMIAN_FAST(Anorm, T); % compute gramian inverse for control horizon T
E_full_grpavg_T(i,:) = MIN_CONTROL_ENERGY(Anorm, WcI, x0, xf, T,false); % compute minimum control energy for each state transition
E_full_LSD_T(i,:) = MIN_CONTROL_ENERGY(Anorm, WcI, x0_L, xf_L, T,false);
E_full_PL_T(i,:) = MIN_CONTROL_ENERGY(Anorm, WcI, x0_P, xf_P, T,false);
% for transition = 1:numClusters^2
% [x, u] = MIN_ENG_CONT(Anorm, T, B, x0(:,transition), xf(:,transition), 0);
% E_weighted(transition) = sum(sum(u.^2))*T/1001; % integrate over inputs
% end
end
%% corrs Persist
for i=1:nT
[Rgrp_LTP(i),Pgrp_LTP(i)] = corr(E_full_grpavg_T(i,:)',mean(LSDTransitionProbability2D)','type','Spearman');
[Rgrp_PTP(i),Pgrp_PTP(i)] = corr(E_full_grpavg_T(i,:)',mean(PLTransitionProbability2D)','type','Spearman');
[R_L(i),P_L(i)] = corr(E_full_LSD_T(i,:)',mean(LSDTransitionProbability2D)','type','Spearman');
[R_P(i),P_P(i)] = corr(E_full_PL_T(i,:)',mean(PLTransitionProbability2D)','type','Spearman');
end
%% corrs NoPersist
% for i=1:nT
%
% [Rgrp_LTP(i),Pgrp_LTP(i)] = corr(E_full_grpavg_T(i,offDiag)',mean(LSDTransitionProbability2D(:,offDiag))');%,'type','Spearman');
% [Rgrp_PTP(i),Pgrp_PTP(i)] = corr(E_full_grpavg_T(i,offDiag)',mean(PLTransitionProbability2D(:,offDiag))');%,'type','Spearman');
%
% [R_L(i),P_L(i)] = corr(E_full_LSD_T(i,offDiag)',mean(LSDTransitionProbability2D(:,offDiag))');%,'type','Spearman');
%
% [R_P(i),P_P(i)] = corr(E_full_PL_T(i,offDiag)',mean(PLTransitionProbability2D(:,offDiag))');%,'type','Spearman');
% end
%% plot TP vs TE
%
% rank2=tiedrank(mean(LSDTransitionProbability2D));
% rank3=tiedrank(mean(PLTransitionProbability2D));
%
% for i=1:nT
% rank1=tiedrank(E_full_grpavg_T(i,:));
% rank4=tiedrank(E_full_LSD_T(i,:));
% rank5=tiedrank(E_full_PL_T(i,:));
%
% figure;
% subplot(2,2,1)
% scatter(rank1,rank2); lsline; title(['C=',num2str(C_rng(k)),' E\_full grp avg T=',num2str(T_rng(i)),' vs LSD Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(Rgrp_LTP(i))]); text(12,13,['p = ',num2str(Pgrp_LTP(i))]);
%
% subplot(2,2,2)
% scatter(rank1,rank3); lsline; title(['E\_full grp avg T=',num2str(T_rng(i)),' vs PL Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(Rgrp_PTP(i))]); text(12,13,['p = ',num2str(Pgrp_PTP(i))]);
%
% subplot(2,2,3)
% scatter(rank4,rank2); lsline; title(['E\_full LSD avg T=',num2str(T_rng(i)),' vs LSD Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(R_L(i))]); text(12,13,['p = ',num2str(P_L(i))]);
%
% subplot(2,2,4)
% scatter(rank5,rank3); lsline; title(['E\_full PL avg T=',num2str(T_rng(i)),' vs PL Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(R_P(i))]); text(12,13,['p = ',num2str(P_P(i))]);
%
% end
%% plot TP vs TE noPersist
%
% rank2=tiedrank(mean(LSDTransitionProbabilityNoPersist2D(:,offDiag)));
% rank3=tiedrank(mean(PLTransitionProbabilityNoPersist2D(:,offDiag)));
%
% for i=1:nT
% rank1=tiedrank(E_full_grpavg_T(i,offDiag));
% rank4=tiedrank(E_full_LSD_T(i,offDiag));
% rank5=tiedrank(E_full_PL_T(i,offDiag));
%
% figure;
% subplot(2,2,1)
% scatter(rank1,rank2); lsline; title(['C=',num2str(C_rng(k)),' E\_full grp avg T=',num2str(T_rng(i)),' vs LSD Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(Rgrp_LTP(i))]); text(12,13,['p = ',num2str(Pgrp_LTP(i))]);
%
% subplot(2,2,2)
% scatter(rank1,rank3); lsline; title(['E\_full grp avg T=',num2str(T_rng(i)),' vs PL Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(Rgrp_PTP(i))]); text(12,13,['p = ',num2str(Pgrp_PTP(i))]);
%
% subplot(2,2,3)
% scatter(rank4,rank2); lsline; title(['E\_full LSD avg T=',num2str(T_rng(i)),' vs LSD Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(R_L(i))]); text(12,13,['p = ',num2str(P_L(i))]);
%
% subplot(2,2,4)
% scatter(rank5,rank3); lsline; title(['E\_full PL avg T=',num2str(T_rng(i)),' vs PL Transition Probability']);
% xlabel('Energy (rank)'); ylabel('Transition Probability (rank)');
% text(12,14,['r = ',num2str(R_P(i))]); text(12,13,['p = ',num2str(P_P(i))]);
%
% end
%% plot R vs T
%
% figure;
% subplot(2,2,1)
% plot(T_rng,abs(Rgrp_LTP)); title(['C=',num2str(C_rng(k)),' E\_full grp avg vs LSD Transition Probability']);
% subplot(2,2,2)
% plot(T_rng,abs(Rgrp_PTP)); title(['C=',num2str(C_rng(k)),' E\_full grp avg vs PL Transition Probability']);
% subplot(2,2,3)
% plot(T_rng,abs(R_L)); title(['C=',num2str(C_rng(k)),' E\_full LSD avg vs LSD Transition Probability']);
% subplot(2,2,4)
% plot(T_rng,abs(R_P)); title(['C=',num2str(C_rng(k)),' E\_full PL avg vs PL Transition Probability']);
%% plot R vs T (no abs)
figure;
subplot(2,2,1)
plot(T_rng,Rgrp_LTP); title(['C=',num2str(C_rng(k)),' E\_full grp avg vs LSD Transition Probability']);
subplot(2,2,2)
plot(T_rng,Rgrp_PTP); title(['C=',num2str(C_rng(k)),' E\_full grp avg vs PL Transition Probability']);
subplot(2,2,3)
plot(T_rng,R_L); title(['C=',num2str(C_rng(k)),' E\_full LSD avg vs LSD Transition Probability']);
subplot(2,2,4)
plot(T_rng,R_P); title(['C=',num2str(C_rng(k)),' E\_full PL avg vs PL Transition Probability']);
end
%%
% save(fullfile(savedir,['T_sweep_bp',num2str(split),'_k',num2str(numClusters),'.mat']), 'E_full_grpavg_T','E_full_LSD_T','E_full_PL_T');