From ef97f7c4a1efd77e32a12e359d16648bd9aea19b Mon Sep 17 00:00:00 2001
From: StaY <stephane.yang@ensea.fr>
Date: Thu, 19 Oct 2023 15:44:34 +0200
Subject: [PATCH] additional script to plot more view cells

---
 .../view_cell/test/plot/plot_thirty_test.m    | 108 ++++++++++++++++++
 1 file changed, 108 insertions(+)
 create mode 100644 Promethe_scripts/examples/view_cell/test/plot/plot_thirty_test.m

diff --git a/Promethe_scripts/examples/view_cell/test/plot/plot_thirty_test.m b/Promethe_scripts/examples/view_cell/test/plot/plot_thirty_test.m
new file mode 100644
index 0000000..8471699
--- /dev/null
+++ b/Promethe_scripts/examples/view_cell/test/plot/plot_thirty_test.m
@@ -0,0 +1,108 @@
+clear all;
+fclose all;
+
+#        R        G        B
+#        0   0.4470   0.7410   blue
+#   0.8500   0.3250   0.0980   orange
+#   0.9290   0.6940   0.1250   yellow
+#   0.4940   0.1840   0.5560   purple
+#   0.4660   0.6740   0.1880   green
+#   0.3010   0.7450   0.9330   light blue
+#   0.6350   0.0780   0.1840   dark red
+#   0.1840   0.3350   0.0780   dark green
+#   0.9290   0.7530   0.7960   pink
+#   0.6670   0.2000   0.4160   dark pink
+
+R = [0     0.85  0.929 0.494 0.466 0.301 0.635 0.184 0.929 0.667 0     0.85  0.929 0.494 0.466 0.301 0.635 0.184 0.929 0.667 0     0.85  0.929 0.494 0.466 0.301 0.635 0.184 0.929 0.667]';
+G = [0.447 0.325 0.694 0.184 0.674 0.745 0.078 0.335 0.753 0.2   0.447 0.325 0.694 0.184 0.674 0.745 0.078 0.335 0.753 0.2   0.447 0.325 0.694 0.184 0.674 0.745 0.078 0.335 0.753 0.2  ]';
+B = [0.741 0.098 0.125 0.556 0.188 0.933 0.184 0.078 0.796 0.416 0.741 0.098 0.125 0.556 0.188 0.933 0.184 0.078 0.796 0.416 0.741 0.098 0.125 0.556 0.188 0.933 0.184 0.078 0.796 0.416]';
+RGB = [R G B];
+%RGB(1,:) % first color
+%RGB(2,:) % second color
+
+% Files open
+view_cells_fid = fopen('PC.SAVE','r');
+
+% Init
+view_cells = [];
+
+% Read until end of file
+while ~feof(view_cells_fid)
+    lineData = fscanf(view_cells_fid, '%f', [31, 1]);
+    
+    if ~isempty(lineData)
+        view_cells = [view_cells, lineData];
+    end
+end
+
+fclose(view_cells_fid);
+
+view_cells = view_cells';
+timestamp = view_cells(:,1); % first column is just le number of the image
+view_cells = view_cells(:,2:end); % remove 1st column
+
+screenSize = get(0, "screensize");
+x_ecran = screenSize(1);
+y_ecran = screenSize(2);
+largeur = screenSize(3);
+hauteur = screenSize(4);
+figure(1, "position", [x_ecran, y_ecran-50, largeur-100, hauteur-100]);
+
+clf;
+subplot (3, 1, 1);
+for i = 1:30
+	plot(view_cells(:,i), "color", RGB(i,:))
+	hold on;
+endfor
+ylim([0, 1.2]);
+legend('cell 1', 'cell 2', 'cell 3', 'cell 4', 'cell 5', 'cell 6', 'cell 7', 'cell 8', 'cell 9', 'cell 10', 'cell 11', 'cell 12', 'cell 13', 'cell 14', 'cell 15', 'cell 16', 'cell 17', 'cell 18', 'cell 19', 'cell 20', 'cell 21', 'cell 22', 'cell 23', 'cell 24', 'cell 25', 'cell 26', 'cell 27', 'cell 28', 'cell 29', 'cell 30');
+xlabel('Number of iterations (image by image)');
+ylabel('Cell''s activity');
+title('Activities of 30 view cells');
+hold off;
+
+x_lim_auto = xlim; % axis of the previous plot
+[vc_len, ~] = size(view_cells);
+subplot (3, 1, 2);
+for i = 1:vc_len
+	temp = view_cells(i,:);
+	[_, max_idx] = max(temp);
+	rectangle('Position', [i, 0, 1, 1], 'FaceColor', RGB(max_idx,:), 'EdgeColor', 'none');
+	hold on;
+end
+xlim(x_lim_auto); % align with previous plot
+xlabel('Number of iterations (image by image)');
+title('Winner cell');
+hold off;
+
+winner = [];
+wanted_winner = [];
+current_wanted = 1;
+dist_step = int32(50); % distance between each images (in number of images)
+offset = idivide(dist_step, int32(2), "ceil");
+subplot (3, 1, 3);
+for i = 1:vc_len
+	next_learnt_cell = dist_step*current_wanted + offset;
+	if (i > next_learnt_cell) && (current_wanted < 30)
+		current_wanted = current_wanted + 1;
+	endif
+	wanted_winner = [wanted_winner; current_wanted];
+	
+	rectangle('Position', [i, 0, 1, 1], 'FaceColor', RGB(current_wanted,:), 'EdgeColor', 'none');
+	hold on;
+	
+	temp = view_cells(i,:);
+	[_, max_idx] = max(temp);
+	winner = [winner; max_idx];
+endfor
+xlim(x_lim_auto); % align with previous plot
+xlabel('Number of iterations (image by image)');
+title('Theoretical winner');
+hold off;
+
+% Save image
+print view_cells_plot_30.png
+
+accuracy = 100 * sum(winner == wanted_winner) / vc_len;
+disp(strcat("The accuracy is: ", num2str(accuracy), " %"))
+pause;
-- 
GitLab