Skip to content

Commit d042143

Browse files
committed
Export results
p-values, confusion matrix and transition probabilities are now exported to txt files.
1 parent 4ce690d commit d042143

File tree

6 files changed

+91
-8
lines changed

6 files changed

+91
-8
lines changed

gui.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function confusion_matrix_Callback(hObject, eventdata, handles)
772772
segmentation_configs = res{1};
773773
set(handles.seg_path,'String',res{2});
774774
end
775-
% see if we have the path for the segmentation_config file
775+
% see if we have the path for the classification_config file
776776
rpath = get(handles.class_path,'String');
777777
[error, classification_configs] = select_files_default(3,rpath);
778778
if error

results/results_confusion_matrix.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function results_confusion_matrix(segmentation_configs,classification_configs,fo
44
% cross-validation of the clustering algorithm
55

66
fn = fullfile(strcat(segmentation_configs.OUTPUT_DIR,'/'), 'confusion_matrix.mat');
7+
fn2 = fullfile(strcat(segmentation_configs.OUTPUT_DIR,'/'), 'Confusion_matrix.txt');
78

89
% get classifier object
910
classif = classification_configs.SEMISUPERVISED_CLUSTERING;
@@ -41,15 +42,35 @@ function results_confusion_matrix(segmentation_configs,classification_configs,fo
4142
cm = cm + res.results(i).confusion_matrix;
4243
end
4344
tags = res.results(1).classes;
45+
46+
% NaN values
47+
for i = 1:size(cm,1)
48+
for j = 1:size(cm,2)
49+
if isnan(cm)
50+
cm(i,j) = 0;
51+
end
52+
end
53+
end
4454

4555
% save data
4656
save(fn, 'tags', 'cm');
47-
4857
disp('Tags:');
4958
for i = 1:length(tags)
5059
fprintf('%s\n', tags{1,i}{1,2});
51-
end
52-
60+
end
5361
fprintf('\nConfusion matrix:\n');
5462
cm
63+
64+
% save to file
65+
fileID = fopen(fn2,'wt');
66+
for i = 1:length(tags)
67+
fprintf(fileID,'%d. %s\n', i, tags{1,i}{1,2});
68+
end
69+
fprintf(fileID, '\n');
70+
for i=1:size(cm,1)
71+
fprintf(fileID, '%d ', cm(i,:));
72+
fprintf(fileID, '\n');
73+
end
74+
fclose(fileID);
75+
5576
end

results/results_latency_speed_length.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ function results_latency_speed_length(segmentation_configs,varargin)
55
% 2. The average movement speed.
66
% 3. The average path length.
77

8+
fn = strcat(segmentation_configs.OUTPUT_DIR,'/','metrics_p.txt');
9+
fileID = fopen(fn,'wt');
10+
811
% get the configurations from the configs file
912
[FontName, FontSize, LineWidth, Export, ExportStyle] = parse_configs;
1013

@@ -152,14 +155,16 @@ function results_latency_speed_length(segmentation_configs,varargin)
152155
set(f,'papersize',[8,8], 'paperposition',[0,0,8,8]);
153156
export_figure(f, strcat(segmentation_configs.OUTPUT_DIR,'/'), sprintf('animals_%s', names{i}),Export, ExportStyle);
154157

155-
% run friedman test
158+
% run friedman test
156159
try
157160
p = friedman(fried, n);
158161
str = sprintf('Friedman p-value (%s): %g', ylabels{i}, p);
162+
fprintf(fileID,'%s\n',str);
159163
disp(str);
160164
catch
161165
disp('Error on Friedman test. Friedman test is skipped');
162-
end
166+
end
163167
end
168+
fclose(fileID);
164169
end
165170

results/results_strategies_distributions_length.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ function results_strategies_distributions_length(segmentation_configs,classifica
44
% show the average length in meters that the animals spent in one strategy
55
% during each trial (for S total strategies, were S is defined by the user)
66

7+
fn = strcat(segmentation_configs.OUTPUT_DIR,'/','strategies_p.txt');
8+
fileID = fopen(fn,'wt');
9+
710
% get the configurations from the configs file
811
[FontName, FontSize, LineWidth, Export, ExportStyle] = parse_configs;
912

@@ -113,6 +116,7 @@ function results_strategies_distributions_length(segmentation_configs,classifica
113116
try
114117
p = friedman(mfried, nanimals);
115118
str = sprintf('Class: %s\tp_frdm: %g', segments_classification.classes{1,c}{1,2}, p);
119+
fprintf(fileID,'%s\n',str);
116120
disp(str);
117121
catch
118122
disp('Error on Friedman test. Friedman test is skipped');
@@ -165,6 +169,6 @@ function results_strategies_distributions_length(segmentation_configs,classifica
165169
export_figure(gcf, strcat(segmentation_configs.OUTPUT_DIR,'/'), sprintf('segment_length_strategy_%d', c), Export, ExportStyle);
166170

167171
end
168-
172+
fclose(fileID);
169173
end
170174

results/results_strategies_transition_prob.m

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,27 @@ function results_strategies_transition_prob(segmentation_configs,classification_
9191
if length(groups) ~= 1
9292
trans_prob1 = trans_prob1 ./ repmat(sum(trans_prob1, 2), 1, nc);
9393
trans_prob2 = trans_prob2 ./ repmat(sum(trans_prob2, 2), 1, nc);
94+
% NaN values
95+
for i = 1:size(trans_prob1,1)
96+
for j = 1:size(trans_prob1,2)
97+
if isnan(trans_prob1)
98+
trans_prob1(i,j) = 0;
99+
end
100+
if isnan(trans_prob2)
101+
trans_prob2(i,j) = 0;
102+
end
103+
end
104+
end
94105
else
95106
trans_prob1 = trans_prob1 ./ repmat(sum(trans_prob1, 2), 1, nc);
107+
% NaN values
108+
for i = 1:size(trans_prob1,1)
109+
for j = 1:size(trans_prob1,2)
110+
if isnan(trans_prob1)
111+
trans_prob1(i,j) = 0;
112+
end
113+
end
114+
end
96115
end
97116

98117
for i = 1:segments_classification.nclasses
@@ -108,5 +127,32 @@ function results_strategies_transition_prob(segmentation_configs,classification_
108127
save(fn, 'trans_prob1');
109128
trans_prob1
110129
end
130+
131+
% save to txt
132+
fn2 = fullfile(strcat(segmentation_configs.OUTPUT_DIR,'/'), 'transition_probabilities.txt');
133+
fileID = fopen(fn2,'wt');
134+
for i = 1:segments_classification.nclasses
135+
fprintf(fileID,'%d. %s\n', i, segments_classification.classes{1,i}{1,2});
136+
end
137+
138+
fprintf(fileID, '\n');
139+
if length(groups) ~= 1
140+
for i=1:size(trans_prob1,1)
141+
fprintf(fileID, '%6.4f ', trans_prob1(i,:));
142+
fprintf(fileID, '\n');
143+
end
144+
fprintf(fileID, '\n');
145+
for i=1:size(trans_prob2,1)
146+
fprintf(fileID, '%6.4f ', trans_prob2(i,:));
147+
fprintf(fileID, '\n');
148+
end
149+
else
150+
for i=1:size(trans_prob1,1)
151+
fprintf(fileID, '%6.4f ', trans_prob1(i,:));
152+
fprintf(fileID, '\n');
153+
end
154+
end
155+
fclose(fileID);
156+
111157
end
112158

results/results_transition_counts.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ function results_transition_counts(segmentation_configs,classification_configs,v
22
% Computes and presents the number of transitions between strategies
33
% for two groups of N animals.
44

5+
fn = strcat(segmentation_configs.OUTPUT_DIR,'/','transitions_p.txt');
6+
fileID = fopen(fn,'wt');
7+
58
% get the configurations from the configs file
69
[FontName, FontSize, LineWidth, Export, ExportStyle] = parse_configs;
710

@@ -160,8 +163,12 @@ function results_transition_counts(segmentation_configs,classification_configs,v
160163

161164
try
162165
p = friedman(mfried, nanimals, 'off');
163-
str = sprintf('p_frdm: %g', p);
166+
str = sprintf('p_frdm: %g', p);
167+
fprintf(fileID,'%s\n',str);
164168
disp(str);
165169
catch
166170
disp('Error on Friedman test. Friedman test is skipped');
167171
end
172+
173+
fclose(fileID);
174+

0 commit comments

Comments
 (0)