| Conditions | 8 |
| Total Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """! |
||
| 100 | def process(self, order = 0.998, solution = solve_type.FAST, collect_dynamic = False): |
||
| 101 | """! |
||
| 102 | @brief Performs clustering of input data set in line with input parameters. |
||
| 103 | |||
| 104 | @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1]. |
||
| 105 | @param[in] solution (solve_type) Type of solving differential equation. |
||
| 106 | @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over). |
||
| 107 | |||
| 108 | @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. |
||
| 109 | |||
| 110 | @see get_clusters() |
||
| 111 | |||
| 112 | """ |
||
| 113 | |||
| 114 | if (self.__ccore_network_pointer is not None): |
||
| 115 | analyser = wrapper.hsyncnet_process(self.__ccore_network_pointer, order, solution, collect_dynamic); |
||
| 116 | return syncnet_analyser(None, None, analyser); |
||
| 117 | |||
| 118 | number_neighbors = self.__initial_neighbors; |
||
| 119 | current_number_clusters = float('inf');
|
||
| 120 | |||
| 121 | dyn_phase = []; |
||
| 122 | dyn_time = []; |
||
| 123 | |||
| 124 | radius = average_neighbor_distance(self._osc_loc, number_neighbors); |
||
| 125 | |||
| 126 | increase_step = int(len(self._osc_loc) * self.__increase_persent); |
||
| 127 | if (increase_step < 1): |
||
| 128 | increase_step = 1; |
||
| 129 | |||
| 130 | |||
| 131 | analyser = None; |
||
| 132 | while(current_number_clusters > self._number_clusters): |
||
| 133 | self._create_connections(radius); |
||
| 134 | |||
| 135 | analyser = self.simulate_dynamic(order, solution, collect_dynamic); |
||
| 136 | if (collect_dynamic == True): |
||
| 137 | if (len(dyn_phase) == 0): |
||
| 138 | dyn_time.append(0); |
||
| 139 | dyn_phase.append(analyser.output[0]); |
||
| 140 | |||
| 141 | dyn_phase.append(analyser.output[len(analyser.output) - 1]); |
||
| 142 | dyn_time.append(len(dyn_time)); |
||
| 143 | |||
| 144 | clusters = analyser.allocate_sync_ensembles(0.05); |
||
| 145 | |||
| 146 | # Get current number of allocated clusters |
||
| 147 | current_number_clusters = len(clusters); |
||
| 148 | |||
| 149 | # Increase number of neighbors that should be used |
||
| 150 | number_neighbors += increase_step; |
||
| 151 | |||
| 152 | # Update connectivity radius and check if average function can be used anymore |
||
| 153 | if (number_neighbors >= len(self._osc_loc)): |
||
| 154 | radius = radius * self.__increase_persent + radius; |
||
| 155 | else: |
||
| 156 | radius = average_neighbor_distance(self._osc_loc, number_neighbors); |
||
| 157 | |||
| 158 | if (collect_dynamic != True): |
||
| 159 | dyn_phase = analyser.output; |
||
| 160 | dyn_time = analyser.time; |
||
| 161 | |||
| 162 | return syncnet_analyser(dyn_phase, dyn_time, None); |
||
| 163 |