| Conditions | 9 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 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 | """! |
||
| 97 | def process(self, order = 0.998, solution = solve_type.FAST, collect_dynamic = False): |
||
| 98 | """! |
||
| 99 | @brief Performs clustering of input data set in line with input parameters. |
||
| 100 | |||
| 101 | @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1]. |
||
| 102 | @param[in] solution (solve_type) Type of solving differential equation. |
||
| 103 | @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over). |
||
| 104 | |||
| 105 | @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. |
||
| 106 | |||
| 107 | @see get_clusters() |
||
| 108 | |||
| 109 | """ |
||
| 110 | |||
| 111 | if (self.__ccore_network_pointer is not None): |
||
| 112 | analyser = wrapper.hsyncnet_process(self.__ccore_network_pointer, order, solution, collect_dynamic); |
||
| 113 | return syncnet_analyser(None, None, analyser); |
||
| 114 | |||
| 115 | number_neighbors = self.__initial_neighbors; |
||
| 116 | current_number_clusters = float('inf');
|
||
| 117 | |||
| 118 | dyn_phase = []; |
||
| 119 | dyn_time = []; |
||
| 120 | |||
| 121 | radius = average_neighbor_distance(self._osc_loc, number_neighbors); |
||
| 122 | |||
| 123 | increase_step = int(len(self._osc_loc) * self.__increase_persent); |
||
| 124 | if (increase_step < 1): |
||
| 125 | increase_step = 1; |
||
| 126 | |||
| 127 | |||
| 128 | analyser = None; |
||
| 129 | while(current_number_clusters > self._number_clusters): |
||
| 130 | self._create_connections(radius); |
||
| 131 | |||
| 132 | analyser = self.simulate_dynamic(order, solution, collect_dynamic); |
||
| 133 | if (collect_dynamic == True): |
||
| 134 | dyn_phase += analyser.output; |
||
| 135 | |||
| 136 | if (len(dyn_time) > 0): |
||
| 137 | point_time_last = dyn_time[len(dyn_time) - 1]; |
||
| 138 | dyn_time += [time_point + point_time_last for time_point in analyser.time]; |
||
| 139 | else: |
||
| 140 | dyn_time += analyser.time; |
||
| 141 | |||
| 142 | clusters = analyser.allocate_sync_ensembles(0.05); |
||
| 143 | |||
| 144 | # Get current number of allocated clusters |
||
| 145 | current_number_clusters = len(clusters); |
||
| 146 | |||
| 147 | # Increase number of neighbors that should be used |
||
| 148 | number_neighbors += increase_step; |
||
| 149 | |||
| 150 | # Update connectivity radius and check if average function can be used anymore |
||
| 151 | if (number_neighbors >= len(self._osc_loc)): |
||
| 152 | radius = radius * self.__increase_persent + radius; |
||
| 153 | else: |
||
| 154 | radius = average_neighbor_distance(self._osc_loc, number_neighbors); |
||
| 155 | |||
| 156 | if (collect_dynamic != True): |
||
| 157 | dyn_phase = analyser.output; |
||
| 158 | dyn_time = analyser.time; |
||
| 159 | |||
| 160 | return syncnet_analyser(dyn_phase, dyn_time, None); |
||
| 161 |