-
Notifications
You must be signed in to change notification settings - Fork 42
/
runExample_noSubsampling.m
174 lines (114 loc) · 4.15 KB
/
runExample_noSubsampling.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
%%example script that will run the code for a single .avi file (moviePath)
%%This version does not perform subsampling to find a training set
%Place path to folder containing example .avi files here
moviePath = '';
%add utilities folder to path
addpath(genpath('./utilities/'));
addpath(genpath('./PCA/'));
addpath(genpath('./segmentation_alignment/'));
addpath(genpath('./t_sne/'));
addpath(genpath('./wavelet/'));
%set file path
[filePath,fileName,~] = fileparts(moviePath);
filePath = [filePath '/' fileName '/'];
imageFiles = {moviePath};
L = length(imageFiles);
numZeros = ceil(log10(L+1e-10));
[status,~]=unix(['ls ' filePath]);
if status ~= 0
unix(['mkdir ' filePath]);
end
%define any desired parameter changes here
parameters.samplingFreq = 100;
parameters.trainingSetSize = 5000;
%initialize parameters
parameters = setRunParameters(parameters);
firstFrame = 1;
lastFrame = [];
%% Run Alignment
%creating alignment directory
alignmentDirectory = [filePath '/alignment_files/'];
if ~exist(alignmentDirectory,'dir')
mkdir(alignmentDirectory);
end
%run alignment for all files in the directory
fprintf(1,'Aligning Files\n');
alignmentFolders = cell(L,1);
ii=1;
fileNum = [repmat('0',1,numZeros-length(num2str(ii))) num2str(ii)];
tempDirectory = [alignmentDirectory 'alignment_' fileNum '/'];
alignmentFolders{ii} = tempDirectory;
outputStruct = runAlignment(imageFiles{ii},tempDirectory,firstFrame,lastFrame,parameters);
save([tempDirectory 'outputStruct.mat'],'outputStruct');
%% Find image subset statistics (a gui will pop-up here)
fprintf(1,'Finding Subset Statistics\n');
numToTest = parameters.pca_batchSize;
[pixels,thetas,means,stDevs,vidObjs] = findRadonPixels(alignmentDirectory,numToTest,parameters);
%% Find postural eigenmodes
fprintf(1,'Finding Postural Eigenmodes\n');
[vecs,vals,meanValues] = findPosturalEigenmodes(vidObjs,pixels,parameters);
vecs = vecs(:,1:parameters.numProjections);
figure
makeMultiComponentPlot_radon_fromVecs(vecs(:,1:25),25,thetas,pixels,[201 90]);
caxis([-3e-3 3e-3])
colorbar
title('First 25 Postural Eigenmodes','fontsize',14,'fontweight','bold');
drawnow;
%% Find projections
projectionsDirectory = [filePath './projections/'];
if ~exist(projectionsDirectory,'dir')
mkdir(projectionsDirectory);
end
fprintf(1,'Finding Projections\n');
ii=1;
projections = findProjections(alignmentFolders{ii},vecs,meanValues,pixels,parameters);
fileNum = [repmat('0',1,numZeros-length(num2str(ii))) num2str(ii)];
fileName = imageFiles{ii};
save([projectionsDirectory 'projections_' fileNum '.mat'],'projections','fileName');
%% Embed training set
fprintf(1,'Calculating Wavelet Transform\n');
[data,f] = findWavelets(projections,parameters.pcaModes,parameters);
amps = sum(data,2);
data(:) = bsxfun(@rdivide,data,amps);
skipLength = round(length(data(:,1))/parameters.trainingSetSize);
trainingSetData = data(skipLength:skipLength:end,:);
trainingAmps = amps(skipLength:skipLength:end);
parameters.signalLabels = log10(trainingAmps);
fprintf(1,'Finding t-SNE Embedding for Training Set\n');
[trainingEmbedding,betas,P,errors] = run_tSne(trainingSetData,parameters);
%% Find All Embeddings
fprintf(1,'Finding t-SNE Embedding for all Data\n');
embeddingValues = cell(L,1);
i=1;
[embeddingValues{ii},~] = findEmbeddings(data,trainingSetData,trainingEmbedding,parameters);
%% Make density plots
maxVal = max(max(abs(combineCells(embeddingValues))));
maxVal = round(maxVal * 1.1);
sigma = maxVal / 40;
numPoints = 501;
rangeVals = [-maxVal maxVal];
[xx,density] = findPointDensity(combineCells(embeddingValues),sigma,numPoints,rangeVals);
densities = zeros(numPoints,numPoints,L);
for i=1:L
[~,densities(:,:,ii)] = findPointDensity(embeddingValues{ii},sigma,numPoints,rangeVals);
end
figure
maxDensity = max(density(:));
imagesc(xx,xx,density)
axis equal tight off xy
caxis([0 maxDensity * .8])
colormap(jet)
colorbar
figure
N = ceil(sqrt(L));
M = ceil(L/N);
maxDensity = max(densities(:));
for i=1:L
subplot(M,N,ii)
imagesc(xx,xx,densities(:,:,ii))
axis equal tight off xy
caxis([0 maxDensity * .8])
colormap(jet)
title(['Data Set #' num2str(ii)],'fontsize',12,'fontweight','bold');
end
close_parpool