Code Duplication    Length = 22-23 lines in 2 locations

pyclustering/cluster/ga.py 2 locations

@@ 123-145 (lines=23) @@
120
121
        return best_chromosome, best_ff
122
123
124
    def get_clusters(self):
125
        """!
126
        @brief Returns list of allocated clusters, each cluster contains indexes of objects from the data.
127
        
128
        @return (list) List of allocated clusters.
129
        
130
        @see process()
131
        
132
        """
133
        
134
        raise NameError("Implementation is require.");
135
136
137
    @staticmethod
138
    def _select(chromosomes, data, count_clusters, select_coeff):
139
        """!
140
        @brief Performs selection procedure where new chromosomes are calculated.
141
        
142
        @param[in] chromosomes (numpy.array): Chromosomes 
143
        
144
        """
145
146
        # Calc centers
147
        centres = ga_math.get_centres(chromosomes, data, count_clusters)
148
@@ 147-168 (lines=22) @@
144
        """
145
146
        # Calc centers
147
        centres = ga_math.get_centres(chromosomes, data, count_clusters)
148
149
        # Calc fitness functions
150
        fitness = genetic_algorithm._calc_fitness_function(centres, data, chromosomes)
151
152
        for _idx in range(len(fitness)):
153
            fitness[_idx] = math.exp(1 + fitness[_idx] * select_coeff)
154
155
        # Calc probability vector
156
        probabilities = ga_math.calc_probability_vector(fitness)
157
158
        # Select P chromosomes with probabilities
159
        new_chromosomes = np.zeros(chromosomes.shape, dtype=np.int)
160
161
        # Selecting
162
        for _idx in range(len(chromosomes)):
163
            new_chromosomes[_idx] = chromosomes[ga_math.get_uniform(probabilities)]
164
165
        return new_chromosomes
166
167
168
    @staticmethod
169
    def _crossover(chromosomes):
170
        """!
171
        @brief Crossover procedure.