Code Duplication    Length = 32-38 lines in 3 locations

pyclustering/nnet/sync.py 2 locations

@@ 414-449 (lines=36) @@
411
412
    def __get_start_stop_iterations(self, start_iteration, stop_iteration):
413
        """!
414
        @brief Aplly rules for start_iteration and stop_iteration parameters.
415
416
        @param[in] start_iteration (uint): The first iteration that is used for calculation.
417
        @param[in] stop_iteration (uint): The last iteration that is used for calculation.
418
        
419
        @return (tuple) New the first iteration and the last.
420
        
421
        """
422
        if (start_iteration is None):
423
            start_iteration = len(self) - 1;
424
        
425
        if (stop_iteration is None):
426
            stop_iteration = start_iteration + 1;
427
        
428
        return (start_iteration, stop_iteration);
429
430
431
432
class sync_visualizer:
433
    """!
434
    @brief Visualizer of output dynamic of sync network (Sync).
435
    
436
    """
437
438
    @staticmethod
439
    def show_output_dynamic(sync_output_dynamic):
440
        """!
441
        @brief Shows output dynamic (output of each oscillator) during simulation.
442
        
443
        @param[in] sync_output_dynamic (sync_dynamic): Output dynamic of the Sync network.
444
        
445
        @see show_output_dynamics
446
        
447
        """
448
        
449
        draw_dynamics(sync_output_dynamic.time, sync_output_dynamic.output, x_title = "t", y_title = "phase", y_lim = [0, 2 * 3.14]);
450
    
451
    
452
    @staticmethod
@@ 380-411 (lines=32) @@
377
        return sequence_order;
378
379
380
    def calculate_local_order_parameter(self, oscillatory_network, start_iteration = None, stop_iteration = None):
381
        """!
382
        @brief Calculates local order parameter.
383
        @details Local order parameter or so-called level of local or partial synchronization is calculated by following expression:
384
        
385
        \f[
386
        r_{c}=\left | \sum_{i=0}^{N} \frac{1}{N_{i}} \sum_{j=0}e^{ \theta_{j} - \theta_{i} } \right |;
387
        \f]
388
        
389
        where N - total amount of oscillators in the network and \f$N_{i}\f$ - amount of neighbors of oscillator with index \f$i\f$.
390
        
391
        @param[in] oscillatory_network (sync): Sync oscillatory network whose structure of connections is required for calculation.
392
        @param[in] start_iteration (uint): The first iteration that is used for calculation, if 'None' then the last iteration is used.
393
        @param[in] stop_iteration (uint): The last iteration that is used for calculation, if 'None' then 'start_iteration' + 1 is used.
394
        
395
        @return (list) List of levels of local (partial) synchronization (local order parameter evolution).
396
        
397
        """
398
399
        (start_iteration, stop_iteration) = self.__get_start_stop_iterations(start_iteration, stop_iteration);
400
        
401
        if (self._ccore_sync_dynamic_pointer is not None):
402
            network_pointer = oscillatory_network._ccore_network_pointer;
403
            return wrapper.sync_dynamic_calculate_local_order(self._ccore_sync_dynamic_pointer, network_pointer, start_iteration, stop_iteration);
404
        
405
        sequence_local_order = [];
406
        for index in range(start_iteration, stop_iteration):
407
            sequence_local_order.append(order_estimator.calculate_local_sync_order(self.output[index], oscillatory_network));
408
        
409
        return sequence_local_order;
410
411
412
    def __get_start_stop_iterations(self, start_iteration, stop_iteration):
413
        """!
414
        @brief Aplly rules for start_iteration and stop_iteration parameters.

pyclustering/cluster/kmeans.py 1 location

@@ 230-267 (lines=38) @@
227
        return default_value;
228
229
230
    @staticmethod
231
    def animate_cluster_allocation(data, observer, animation_velocity = 500, movie_fps = 1, save_movie = None):
232
        """!
233
        @brief Animates clustering process that is performed by K-Means algorithm.
234
235
        @param[in] data (list): Dataset that is used for clustering.
236
        @param[in] observer (kmeans_observer): EM observer that was used for collection information about clustering process.
237
        @param[in] animation_velocity (uint): Interval between frames in milliseconds (for run-time animation only).
238
        @param[in] movie_fps (uint): Defines frames per second (for rendering movie only).
239
        @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
240
241
        """
242
        figure = plt.figure();
243
244
        def init_frame():
245
            return frame_generation(0);
246
247
        def frame_generation(index_iteration):
248
            figure.clf();
249
250
            figure.suptitle("K-Means algorithm (iteration: " + str(index_iteration) + ")", fontsize=18, fontweight='bold');
251
252
            clusters = observer.get_clusters(index_iteration);
253
            centers = observer.get_centers(index_iteration);
254
            kmeans_visualizer.show_clusters(data, clusters, centers, None, figure=figure, display=False);
255
256
            figure.subplots_adjust(top=0.85);
257
258
            return [figure.gca()];
259
260
        iterations = len(observer);
261
        cluster_animation = animation.FuncAnimation(figure, frame_generation, iterations, interval=animation_velocity,
262
                                                    init_func=init_frame, repeat_delay=5000);
263
264
        if (save_movie is not None):
265
            cluster_animation.save(save_movie, writer='ffmpeg', fps=movie_fps, bitrate=3000);
266
        else:
267
            plt.show();
268
269
270