Code Duplication    Length = 26-30 lines in 2 locations

pyclustering/nnet/pcnn.py 2 locations

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