@@ 123-145 (lines=23) @@ | ||
120 | ||
121 | ax.set_xlabel("Iteration"); |
|
122 | ax.set_ylabel("Fitness function"); |
|
123 | ax.legend([line_best, line_current, line_mean], ["The best pop.", "Cur. best pop.", "Average"], prop={'size': 10}); |
|
124 | ax.grid(); |
|
125 | ||
126 | print(start_iteration, stop_iteration); |
|
127 | if (display is True): |
|
128 | plt.show(); |
|
129 | ||
130 | ||
131 | @staticmethod |
|
132 | def show_clusters(data, observer, marker = '.', markersize = None): |
|
133 | figure = plt.figure(); |
|
134 | ax1 = figure.add_subplot(121); |
|
135 | ||
136 | clusters = ga_math.get_clusters_representation(observer.get_global_best()['chromosome'][-1]); |
|
137 | ||
138 | visualizer = cluster_visualizer(1, 2); |
|
139 | visualizer.append_clusters(clusters, data, 0, marker, markersize); |
|
140 | visualizer.show(figure, display = False); |
|
141 | ||
142 | ga_visualizer.show_evolution(observer, 0, None, ax1, True); |
|
143 | ||
144 | ||
145 | @staticmethod |
|
146 | def animate_cluster_allocation(data, observer, animation_velocity = 75, save_movie = None): |
|
147 | figure = plt.figure(); |
|
148 | ||
@@ 147-168 (lines=22) @@ | ||
144 | ||
145 | @staticmethod |
|
146 | def animate_cluster_allocation(data, observer, animation_velocity = 75, save_movie = None): |
|
147 | figure = plt.figure(); |
|
148 | ||
149 | def init_frame(): |
|
150 | return frame_generation(0); |
|
151 | ||
152 | def frame_generation(index_iteration): |
|
153 | figure.clf(); |
|
154 | ||
155 | figure.suptitle("Clustering genetic algorithm (iteration: " + str(index_iteration) +")", fontsize = 20, fontweight = 'bold'); |
|
156 | ||
157 | visualizer = cluster_visualizer(4, 2, ["Population #" + str(index_iteration), "The best population"]); |
|
158 | ||
159 | local_minimum_clusters = ga_math.get_clusters_representation(observer.get_population_best()['chromosome'][index_iteration]); |
|
160 | visualizer.append_clusters(local_minimum_clusters, data, 0); |
|
161 | ||
162 | global_minimum_clusters = ga_math.get_clusters_representation(observer.get_global_best()['chromosome'][index_iteration]); |
|
163 | visualizer.append_clusters(global_minimum_clusters, data, 1); |
|
164 | ||
165 | ax1 = plt.subplot2grid((2, 2), (1, 0), colspan = 2); |
|
166 | ga_visualizer.show_evolution(observer, 0, index_iteration + 1, ax1, False); |
|
167 | ||
168 | visualizer.show(figure, shift = 0, display = False); |
|
169 | figure.subplots_adjust(top = 0.85); |
|
170 | ||
171 | return [ figure.gca() ]; |