@@ -2,20 +2,31 @@ function demo(set,user_path,varargin)
22% DEMO executes the processes: segmentation, labelling, classification
33% and produces the results
44
5+ % How to run standalone (everything, no UI, no display):
6+ % demo(1,'C:\','WAITBAR',0,'DISPLAY',0,'SEGMENTATION',1,...
7+ % 'CLASSIFICATION',1,'MCLASSIFICATION',1,'LABELLING_QUALITY',1,'STATISTICS',1,'PROBABILITIES',1);
8+
9+
10+ if isempty(varargin )
11+ initialization ;
12+ else
13+ if ~isequal(varargin{1 },' NO_INIT' )
14+ initialization ;
15+ end
16+ end
17+
518 % Functionalities
619 SEGMENTATION = 1 ;
720 CLASSIFICATION = 1 ;
821 MCLASSIFICATION = 1 ;
9- % Clusters
10- UCLUSTERS = 1 ;
1122 % Results
1223 LABELLING_QUALITY = 0 ;
1324 STATISTICS = 1 ;
1425 PROBABILITIES = 1 ;
1526 % Extra
1627 WAITBAR = 0 ;
1728 DISPLAY = 0 ;
18-
29+
1930 for i = 1 : length(varargin )
2031 if isequal(varargin{i },' WAITBAR' )
2132 WAITBAR = varargin{i + 1 };
@@ -39,16 +50,8 @@ function demo(set,user_path,varargin)
3950 % Set Options
4051 if set == 1
4152 seg_overlap = [0.7 ,0.7 ,0.9 ,0.7 ];
42- seg_length = [300 ,250 ,250 ,200 ];
53+ seg_length = [300 ,250 ,250 ,200 ];
4354 groups = [1 ,2 ];
44- if UCLUSTERS
45- num_clusters = {300 ,0.7 ,[10 : 49 ,53 ], 250 ,0.7 ,[10 : 68 ,70 ,74 ,75 ,82 ,83 ,84 ], 250 ,0.9 ,10 : 100 , 200 ,0.7 ,[10 : 54 ,56 : 60 ]}; % 41,65,91,50 classifiers
46- else
47- num_clusters = 10 : 58 ; % 49 classifiers
48- end
49- sample = [41 ,65 ,91 ,50 ];
50- iterations = 1 ;
51- % Mclusters = num_clusters;
5255 elseif set == 2
5356 return
5457 end
@@ -108,21 +111,23 @@ function demo(set,user_path,varargin)
108111 delete(h );
109112 end
110113
114+ %% Load the settings
115+ try
116+ load(fullfile(project_path ,' settings' ,' new_properties.mat' ));
117+ load(fullfile(project_path ,' settings' ,' animal_groups.mat' ));
118+ load(fullfile(project_path ,' settings' ,' my_trajectories.mat' ));
119+ full_trajectory_features(project_path ,' WAITBAR' ,WAITBAR ,' DISPLAY' ,DISPLAY ); % Trajectories
120+ load(fullfile(project_path ,' settings' ,' my_trajectories_features.mat' ));
121+ catch
122+ errordlg(' Cannot load project settings' ,' Error' );
123+ return
124+ end
125+
111126 %% Segmentation
112127 if SEGMENTATION
113- try
114- load(fullfile(project_path ,' settings' ,' new_properties.mat' ));
115- load(fullfile(project_path ,' settings' ,' animal_groups.mat' ));
116- load(fullfile(project_path ,' settings' ,' my_trajectories.mat' ));
117- catch
118- errordlg(' Cannot load project settings' ,' Error' );
119- return
120- end
121- full_trajectory_features(project_path ); % Trajectories
122- load(fullfile(project_path ,' settings' ,' my_trajectories_features.mat' ));
123128 for i = 1 : length(seg_overlap )
124129 seg_properties = [seg_length(i ),seg_overlap(i )];
125- segmentation_configs = config_segments(new_properties , seg_properties , trajectory_groups , my_trajectories , my_trajectories_features , ' ' );
130+ segmentation_configs = config_segments(new_properties , seg_properties , trajectory_groups , my_trajectories , my_trajectories_features , ' ' , ' WAITBAR ' , WAITBAR , ' DISPLAY ' , DISPLAY );
126131 save_segmentation(segmentation_configs , project_path );
127132 end
128133 end
@@ -145,7 +150,7 @@ function demo(set,user_path,varargin)
145150 end
146151 end
147152 end
148-
153+
149154 %% Animal Trajectories Map
150155 [~ , animals_trajectories_map , animals_ids ] = trajectories_map(my_trajectories ,my_trajectories_features ,groups ,' Friedman' ,set );
151156
@@ -166,15 +171,13 @@ function demo(set,user_path,varargin)
166171 results_strategies_distributions_manual_full(project_path ,tmp1 ,tmp2 ,animals_trajectories_map ,1 );
167172 break ;
168173 end
169- if iscell(num_clusters )
170- for k = 1 : 3 : length(num_clusters )
171- if num_clusters{k } == str2num(seg_length ) && num_clusters{k + 1 } == str2num(seg_overlap )/10
172- error = execute_classification(project_path ,sfiles(j ).name,lfiles(i ).name,num_clusters{k + 2 },varargin );
173- end
174- end
175- else
176- error = execute_classification(project_path ,sfiles(j ).name,lfiles(i ).name,num_clusters ,varargin );
177- end
174+ % read the cv file
175+ cv_file = fullfile(datapath ,' cv' ,strcat(' cv_' ,seg_length ,' _' ,seg_overlap ,' .csv' ));
176+ data = read_cv_file(cv_file );
177+ data = data(: ,[1 ,2 ,5 ]);
178+ cvErr = find(data(: ,3 ) < 25 );
179+ num_clusters = data(cvErr ,1 );
180+ error = execute_classification(project_path ,sfiles(j ).name,lfiles(i ).name,num_clusters ,varargin );
178181 end
179182 end
180183 end
@@ -186,7 +189,7 @@ function demo(set,user_path,varargin)
186189 for i = 3 : length(classifs )
187190 % execute_Mclassification(project_path, {classifs(i).name}, sample, iterations, 0, 'CLUSTERS', Mclusters)
188191 tmp = dir(fullfile(project_path ,' classification' ,classifs(i ).name,' *.mat' ));
189- execute_Mclassification(project_path , {classifs(i ).name}, length(tmp ), iterations , 0 , varargin{: });
192+ execute_Mclassification(project_path , {classifs(i ).name}, length(tmp ), 1 , 0 , varargin{: });
190193 end
191194 end
192195
@@ -205,7 +208,7 @@ function demo(set,user_path,varargin)
205208 errordlg(' Error: metrics generation' ,' Error' );
206209 end
207210
208- % STRATEGIES - TRANSITIONS - PROBABILITIES - STATISTICS
211+ % STRATEGIES - TRANSITIONS - PROBABILITIES - STATISTICS (Ensemble)
209212 if PROBABILITIES
210213 b_pressed = {' Strategies' ,' Transitions' ,' Probabilities' };
211214 else
@@ -259,6 +262,60 @@ function demo(set,user_path,varargin)
259262 end
260263 end
261264
265+ % STRATEGIES - TRANSITIONS - PROBABILITIES - STATISTICS (Classifiers)
266+ if PROBABILITIES
267+ b_pressed = {' Strategies' ,' Transitions' ,' Probabilities' };
268+ else
269+ b_pressed = {' Strategies' ,' Transitions' };
270+ end
271+ segs = dir(fullfile(project_path ,' segmentation' ,' *.mat' ));
272+ cclasses = dir(fullfile(project_path ,' classification' ));
273+ for i = 1 : length(segs )
274+ seg = fullfile(project_path ,' segmentation' ,segs(i ).name);
275+ [~ ,~ ,sl ,so ] = split_segmentation_name(seg );
276+ if isequal(sl ,' 0' ) || isequal(so ,' 0' )
277+ continue ;
278+ end
279+ for j = 3 : length(cclasses )
280+ mclass = fullfile(project_path ,' classification' ,cclasses(j ).name);
281+ [~ ,~ ,~ ,seg_length ,seg_overlap ,~ ,~ ,~ ] = split_mclassification_name(mclass );
282+ if isequal(sl ,seg_length ) && isequal(so ,seg_overlap )
283+ load(fullfile(project_path ,' segmentation' ,segs(i ).name));
284+ % Check the classification
285+ [error ,name ,classifications ] = check_classification(project_path ,segmentation_configs ,cclasses(j ).name, ' WAITBAR' ,WAITBAR , ' DISPLAY' , DISPLAY );
286+ if error
287+ errordlg(' Classification check failed' ,' Error' );
288+ return
289+ end
290+ % Generate the results
291+ for b = 1 : length(b_pressed )
292+ error = generate_results(project_path , name , my_trajectories , segmentation_configs , classifications , animals_trajectories_map , animals_ids , b_pressed{b }, groups , ' WAITBAR' ,WAITBAR , ' DISPLAY' , DISPLAY );
293+ if error
294+ errordlg(' Cannot create results for strategies, transitions and probabilities' ,' Error' );
295+ return
296+ end
297+ error = generate_results(project_path , name , my_trajectories , segmentation_configs , classifications , animals_trajectories_map , animals_ids , b_pressed{b }, groups , ' DISTRIBUTION' ,2 , ' EXTRA_NAME' ,' _nosmooth' , ' WAITBAR' ,WAITBAR , ' DISPLAY' , DISPLAY );
298+ if error
299+ errordlg(' Cannot create results for strategies, transitions and probabilities (smooth)' ,' Error' );
300+ return
301+ end
302+ end
303+ % Statistics
304+ if STATISTICS
305+ [error ,~ ,~ ] = class_statistics(project_path , cclasses(j ).name, ' WAITBAR' , WAITBAR );
306+ if error
307+ errordlg(' Error: statistics generation' ,' Error' );
308+ end
309+ [error ,~ ,~ ] = class_statistics(project_path , cclasses(j ).name, ' SEGMENTATION' , segmentation_configs , ' WAITBAR' , WAITBAR , ' DISPLAY' , DISPLAY );
310+ if error
311+ errordlg(' Error: statistics generation (smooth)' ,' Error' );
312+ end
313+ end
314+ break ;
315+ end
316+ end
317+ end
318+
262319 %% Labelling Quality
263320 if LABELLING_QUALITY
264321 for i = 1 : length(seg_overlap )
0 commit comments