Code Duplication    Length = 22-23 lines in 2 locations

pyclustering/cluster/ga.py 2 locations

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