Skip to content

Commit a10ce64

Browse files
committed
bug fix
1 parent a35bda2 commit a10ce64

File tree

2 files changed

+184
-3
lines changed

2 files changed

+184
-3
lines changed

results/demo/demo_gui.asv

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
function demo_gui(set,user_path,varargin)
2+
%DEMO_GUI executes the processes: segmentation, labelling, classification
3+
%and produces the results
4+
5+
%%Global Options
6+
seg_overlap = [0.7,0.9];
7+
seg_length = 250;
8+
if ~isempty(varargin)
9+
if varargin{1} == -1
10+
seg_overlap = 0.7;
11+
end
12+
end
13+
14+
15+
user_path = char_project_path(user_path);
16+
h = waitbar(0,'Initializing...');
17+
18+
%% Create project folder tree (set_folder.m)
19+
if set == 1
20+
error = build_folder_tree(user_path, 'demo_original_set_1');
21+
elseif set == 2
22+
error = build_folder_tree(user_path, 'demo_original_set_2');
23+
end
24+
if error
25+
return
26+
end
27+
project_path = fullfile(user_path,'demo_original_set_1');
28+
waitbar(1/2);
29+
30+
%% Copy the settings mat files (skip gui_project.m)
31+
if isdeployed
32+
if set == 1
33+
datapath = fullfile(ctfroot,'import','original_data_1_settings');
34+
elseif set == 2
35+
datapath = fullfile(ctfroot,'import','original_data_2_settings');
36+
end
37+
else
38+
if set == 1
39+
datapath = fullfile(pwd,'import','original_data_1_settings');
40+
elseif set == 2
41+
datapath = fullfile(pwd,'import','original_data_2_settings');
42+
end
43+
end
44+
files = dir(fullfile(datapath,'*.mat'));
45+
for i = 1:length(files)
46+
copyfile(fullfile(datapath,files(i).name),fullfile(project_path,'settings'));
47+
end
48+
ptags = fullfile(datapath,'tags.txt');
49+
copyfile(ptags,fullfile(project_path,'settings'));
50+
waitbar(2/2);
51+
delete(h);
52+
53+
%% Segmentation
54+
try
55+
load(fullfile(project_path,'settings','new_properties.mat'));
56+
load(fullfile(project_path,'settings','animal_groups.mat'));
57+
load(fullfile(project_path,'settings','my_trajectories.mat'));
58+
catch
59+
errordlg('Cannot load project settings','Error');
60+
return
61+
end
62+
63+
for i = 1:length(seg_overlap)
64+
seg_properties = [seg_length,seg_overlap(i)];
65+
segmentation_configs = config_segments(new_properties, seg_properties, trajectory_groups, my_trajectories);
66+
save_segmentation(segmentation_configs, project_path);
67+
end
68+
69+
%% Labelling
70+
files = {'labels_1301_250_07-tiago.csv','labels_1657_250_09-tiago.csv'};
71+
seg_name = {'segmentation_configs_10388_250_07.mat','segmentation_configs_29476_250_09.mat'};
72+
for i = 1:length(seg_overlap)
73+
%check if everything is ok
74+
if ~exist(fullfile(datapath,files{i}),'file') || ~exist(fullfile(project_path,'segmentation',seg_name{i}),'file')
75+
errordlg('Cannot create labels files','Error');
76+
return
77+
end
78+
%copy the csv files from the datapath
79+
labels_path = fullfile(datapath,files{i});
80+
copyfile(labels_path,fullfile(project_path,'labels'));
81+
%the labels are now inside the project path
82+
labels_path = fullfile(project_path,'labels',files{i});
83+
%load the segmentation and generate the labels mat file
84+
load(fullfile(project_path,'segmentation',seg_name{i}));
85+
generate_mat_from_labels(labels_path,segmentation_configs);
86+
clear segmentation_configs
87+
end
88+
89+
%% Classification
90+
lab_name = {'labels_1301_250_07-tiago.mat','labels_1657_250_09-tiago.mat'};
91+
for i = 1:length(seg_overlap)
92+
%check if everything is ok
93+
if ~exist(fullfile(project_path,'labels',lab_name{i}),'file')
94+
errordlg('Cannot create classifiers','Error');
95+
return
96+
end
97+
default_classification(project_path,seg_name{i},lab_name{i});
98+
end
99+
100+
%% Results
101+
groups = [1,2];
102+
load(fullfile(project_path,'segmentation',seg_name{1}));
103+
[exit, animals_trajectories_map] = trajectories_map(segmentation_configs,groups,'Friedman',set);
104+
105+
% METRICS
106+
str = num2str(groups);
107+
str = regexprep(str,'[^\w'']',''); %remove gaps
108+
str = strcat('group',str);
109+
output_dir = fullfile(project_path,'results','metrics',str);
110+
if ~exist(output_dir,'dir')
111+
mkdir(output_dir);
112+
end
113+
try
114+
results_latency_speed_length(segmentation_configs,animals_trajectories_map,1,output_dir);
115+
catch
116+
errordlg('Error: metrics generation','Error');
117+
end
118+
119+
% STRATEGIES - TRANSITIONS - PROBABILITIES - STATISTICS
120+
b_pressed = {'Strategies','Transitions','Probabilities'};
121+
class = {'class_1301_10388_250_07_10_10_mr0-tiago','class_1657_29476_250_09_10_10_mr0-tiago'};
122+
123+
for j = 1:length(seg_overlap)
124+
125+
% Check if everything is ok
126+
if ~exist(fullfile(project_path,'Mclassification',class{j}),'file')
127+
errordlg('Check fail for results: strategies, transitions and probabilities','Error');
128+
return
129+
end
130+
131+
% Statistics
132+
[error,~,~] = class_statistics(project_path, class{j});
133+
if error
134+
errordlg('Error: statistics generation','Error');
135+
end
136+
137+
% Check the classification
138+
[error,name,classifications] = check_classification(project_path,segmentation_configs,class{j});
139+
if error
140+
errordlg('Classification check failed','Error');
141+
return
142+
end
143+
144+
% Generate the results
145+
for i = 1:length(b_pressed)
146+
error = generate_results(project_path, name, segmentation_configs, classifications, animals_trajectories_map, b_pressed{i}, groups);
147+
if error
148+
errordlg('Cannot create results for strategies, transitions and probabilities','Error');
149+
return
150+
end
151+
end
152+
end
153+
154+
%% Labelling Quality
155+
files = {'labels_1301_250_07-tiago.mat','labels_1657_250_09-tiago.mat'};
156+
for i = 1:length(seg_name)
157+
load(fullfile(project_path,'segmentation',seg_name{i}));
158+
load(fullfile(project_path,'labels',files{i}));
159+
160+
p = strsplit(files{i},'.mat');
161+
p = p{1};
162+
output_path = char(fullfile(project_path,'labels',strcat(p,'_check')));
163+
if ~exist(output_path,'dir')
164+
mkdir(output_path);
165+
end
166+
[nc,res1bare,res2bare,res1,res2,res3,covering] = results_clustering_parameters(segmentation_configs,labels,0,output_path,10,100,1);
167+
output_path = char(fullfile(project_path,'results',strcat(p,'_cross_validation')));
168+
if exist(output_path,'dir');
169+
rmdir(output_path,'s');
170+
end
171+
mkdir(output_path);
172+
[nc,per_errors1,per_undefined1,coverage] = algorithm_statistics(1,1,nc,res1bare,res2bare,res1,res2,res3,covering);
173+
data = [nc', per_errors1', per_undefined1', coverage'];
174+
% export results to CSV file
175+
export_num_of_clusters(output_path,data);
176+
% generate graphs
177+
results_clustering_parameters_graphs(output_path,nc,res1bare,res2bare,res1,res2,res3,covering);
178+
end
179+
end
180+

results/demo/demo_gui.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function demo_gui(set,user_path,varargin)
8888

8989
%% Classification
9090
lab_name = {'labels_1301_250_07-tiago.mat','labels_1657_250_09-tiago.mat'};
91-
for i = 1:length(seg_name)
91+
for i = 1:length(seg_overlap)
9292
%check if everything is ok
9393
if ~exist(fullfile(project_path,'labels',lab_name{i}),'file')
9494
errordlg('Cannot create classifiers','Error');
@@ -119,7 +119,8 @@ function demo_gui(set,user_path,varargin)
119119
% STRATEGIES - TRANSITIONS - PROBABILITIES - STATISTICS
120120
b_pressed = {'Strategies','Transitions','Probabilities'};
121121
class = {'class_1301_10388_250_07_10_10_mr0-tiago','class_1657_29476_250_09_10_10_mr0-tiago'};
122-
for j = 1:length(seg_name)
122+
123+
for j = 1:length(seg_overlap)
123124

124125
% Check if everything is ok
125126
if ~exist(fullfile(project_path,'Mclassification',class{j}),'file')
@@ -152,7 +153,7 @@ function demo_gui(set,user_path,varargin)
152153

153154
%% Labelling Quality
154155
files = {'labels_1301_250_07-tiago.mat','labels_1657_250_09-tiago.mat'};
155-
for i = 1:length(seg_name)
156+
for i = 1:length(seg_overlap)
156157
load(fullfile(project_path,'segmentation',seg_name{i}));
157158
load(fullfile(project_path,'labels',files{i}));
158159

0 commit comments

Comments
 (0)