-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvd_and_corrMatrices.m
144 lines (86 loc) · 2.51 KB
/
svd_and_corrMatrices.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
meanSubData = permute(filtSig35, [2, 3, 1]);
%%
concatTrials = [];
%allChan = [1:64];
%allChan(info.noiseChannels) = [];
allChan = info.lowLat;
timeEP = [1030:1500];
useEP = permute(meanSubData(allChan,:,timeEP), [1,3,2]);
concatTrials = reshape(useEP, [size(useEP,2), size(useEP,1)*size(useEP,3)])';
figure
imagesc(concatTrials)
corrMatrix = corr(concatTrials');
covarianceMatrix = concatTrials * concatTrials';
stdTrials = sqrt(sum(concatTrials.^2,2));
corrMatrix = covarianceMatrix ./ (stdTrials * stdTrials');
figure
imagesc(corrMatrix)
%%
distances = 1 - corrMatrix;
distances = (distances + distances') / 2;
distances(logical(eye(size(distances)))) = 0;
% distances = 1 - kron(eye(4), ones(10));
% randOrder = randsample(size(distances,1), size(distances,1));
% distances = distances(randOrder, randOrder);
tree = linkage(squareform(distances));
indexOrder = optimalleaforder(tree, distances);
figure
imagesc(1 - distances(indexOrder,indexOrder))
%% Baseline
concatTrials = [];
allChan = [1:64];
allChan(info.noiseChannels) = [];
%allChan = info.lowLat;
timeEP = [1:300];
useEP = permute(meanSubData(allChan,:,timeEP), [1,3,2]);
concatTrials = reshape(useEP, [size(useEP,1), size(useEP,2)*size(useEP,3)]);
figure
imagesc(concatTrials)
[U, S, V] = svd(concatTrials);
figure(2);
clf;
plot(cumsum(diag(S)/sum(S(:))*100))
inputData = zeros(1,64);
inputData(allChan) = U(:,4);
[currentFig, colorMatrix, gridData] = PlotOnECoG(inputData, info, 1)
%% flash
concatTrials = [];
allChan = [1:64];
allChan(info.noiseChannels) = [];
%allChan = info.lowLat;
timeEP = [1030:1300];
useEP = permute(meanSubData(allChan,:,timeEP), [1,3,2]);
concatTrials = reshape(useEP, [size(useEP,1), size(useEP,2)*size(useEP,3)]);
figure
imagesc(concatTrials)
colrs = lines(8)
[U2, S2, V2] = svd(concatTrials);
figure(1);
clf;
plot(cumsum(diag(S2)/sum(S2(:))*100))
inputData = zeros(1,64);
inputData(allChan) = U2(:,4);
[currentFig, colorMatrix, gridData] = PlotOnECoG(inputData, info, 1)
% corrMatrix = corr(concatTrials');
% covarianceMatrix = concatTrials * concatTrials';
% stdTrials = sqrt(sum(concatTrials.^2,2));
% corrMatrix = covarianceMatrix ./ (stdTrials * stdTrials');
%
% figure
% imagesc(corrMatrix)
%%
[X, Y] = meshgrid([1:10]);
mode = sin(X/10*2*pi);
figure
subplot(2,2,1)
imagesc(mode)
vectoizedMode = mode(:);
time = 1:200;
amplitude = sin(time/100*4*2*pi);
timeSeries = vectoizedMode * amplitude;
subplot(2,2,1)
imagesc(timeSeries)
[U2, S2, V2] = svd(timeSeries);
imagesc(reshape(U2(:,1), [10 10]));
clf
plot(V2(:,1))