Code Duplication    Length = 26-30 lines in 2 locations

pyclustering/nnet/pcnn.py 2 locations

@@ 149-178 (lines=30) @@
146
        return len(self.__dynamic);
147
    
148
    
149
    def allocate_sync_ensembles(self):
150
        """!
151
        @brief Allocate clusters in line with ensembles of synchronous oscillators where each
152
               synchronous ensemble corresponds to only one cluster.
153
        
154
        @return (list) Grours (lists) of indexes of synchronous oscillators. 
155
                For example, [ [index_osc1, index_osc3], [index_osc2], [index_osc4, index_osc5] ].
156
                
157
        """
158
        
159
        if (self.__ccore_pcnn_dynamic_pointer is not None):
160
            return wrapper.pcnn_dynamic_allocate_sync_ensembles(self.__ccore_pcnn_dynamic_pointer);
161
        
162
        sync_ensembles = [];
163
        traverse_oscillators = set();
164
        
165
        number_oscillators = len(self.__dynamic[0]);
166
        
167
        for t in range(len(self.__dynamic) - 1, 0, -1):
168
            sync_ensemble = [];
169
            for i in range(number_oscillators):
170
                if (self.__dynamic[t][i] == self.__OUTPUT_TRUE):
171
                    if (i not in traverse_oscillators):
172
                        sync_ensemble.append(i);
173
                        traverse_oscillators.add(i);
174
            
175
            if (sync_ensemble != []):
176
                sync_ensembles.append(sync_ensemble);
177
        
178
        return sync_ensembles;
179
180
181
    def allocate_spike_ensembles(self):
@@ 181-206 (lines=26) @@
178
        return sync_ensembles;
179
180
181
    def allocate_spike_ensembles(self):
182
        """!
183
        @brief Analyses output dynamic of network and allocates spikes on each iteration as a list of indexes of oscillators.
184
        @details Each allocated spike ensemble represents list of indexes of oscillators whose output is active.
185
        
186
        @return (list) Spike ensembles of oscillators.
187
        
188
        """
189
        
190
        if (self.__ccore_pcnn_dynamic_pointer is not None):
191
            return wrapper.pcnn_dynamic_allocate_spike_ensembles(self.__ccore_pcnn_dynamic_pointer);
192
        
193
        spike_ensembles = [];
194
        number_oscillators = len(self.__dynamic[0]);
195
        
196
        for t in range(len(self.__dynamic)):
197
            spike_ensemble = [];
198
            
199
            for index in range(number_oscillators):
200
                if (self.__dynamic[t][index] == self.__OUTPUT_TRUE):
201
                    spike_ensemble.append(index);
202
            
203
            if (len(spike_ensemble) > 0):
204
                spike_ensembles.append(spike_ensemble);
205
        
206
        return spike_ensembles;
207
    
208
    
209
    def allocate_time_signal(self):