3 @brief Neural and oscillatory network module. Consists of models of bio-inspired networks. 5 @authors Andrei Novikov (pyclustering@yandex.ru) 7 @copyright GNU Public License 9 @cond GNU_PUBLIC_LICENSE 10 PyClustering is free software: you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 15 PyClustering is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. 28 from enum
import IntEnum;
32 @brief Enumerator of types of oscillator output initialization. 45 @brief Enumerator of solver types that are used for network simulation. 61 @brief Enumerator of connection types between oscillators. 86 @brief Enumerator of internal network connection representation between oscillators. 99 @brief Common network description that consists of information about oscillators and connection between them. 106 _conn_represent =
None;
116 @brief Height of the network grid (that is defined by amout of oscillators in each column), this value is zero in case of non-grid structure. 118 @note This property returns valid value only for network with grid structure. 127 @brief Width of the network grid, this value is zero in case of non-grid structure. 129 @note This property returns valid value only for network with grid structure. 138 @brief Type of network structure that is used for connecting oscillators. 144 def __init__(self, num_osc, type_conn = conn_type.ALL_TO_ALL, conn_repr = conn_represent.MATRIX, height = None, width = None):
146 @brief Constructor of the network. 148 @param[in] num_osc (uint): Number of oscillators in the network that defines size of the network. 149 @param[in] type_conn (conn_type): Type of connections that are used in the network between oscillators. 150 @param[in] conn_repr (conn_represent): Type of representation of connections. 151 @param[in] height (uint): Number of oscillators in column of the network, this argument is used 152 only for network with grid structure (GRID_FOUR, GRID_EIGHT), for other types this argument is ignored. 153 @param[in] width (uint): Number of oscillotors in row of the network, this argument is used only 154 for network with grid structure (GRID_FOUR, GRID_EIGHT), for other types this argument is ignored. 162 if (conn_repr
is None):
165 if ( (type_conn == conn_type.GRID_EIGHT)
or (type_conn == conn_type.GRID_FOUR) ):
166 if ( (height
is not None)
and (width
is not None) ):
171 if (side_size - math.floor(side_size) > 0):
172 raise NameError(
"Invalid number of oscillators '" + str(num_osc) +
"' in the network in case of grid structure (root square should be extractable for the number of oscillators).");
178 raise NameError(
'Width (' + str(self.
__width) +
') x Height (' + str(self.
__height) +
') must be equal to Size (' + str(self.
_num_osc) +
') in case of grid structure');
185 @brief Returns size of the network that is defined by amount of oscillators. 191 def __create_connection(self, index1, index2):
198 def __create_all_to_all_connections(self):
200 @brief Creates connections between all oscillators. 205 for index
in range(0, self.
_num_osc, 1):
210 for index
in range(0, self.
_num_osc, 1):
211 self.
_osc_conn.append([neigh
for neigh
in range(0, self.
_num_osc, 1)
if index != neigh]);
214 def __create_grid_four_connections(self):
216 @brief Creates network with connections that make up four grid structure. 217 @details Each oscillator may be connected with four neighbors in line with 'grid' structure: right, upper, left, lower. 227 raise NameError(
"Unknown type of representation of connections");
229 for index
in range(0, self.
_num_osc, 1):
230 upper_index = index - side_size;
231 lower_index = index + side_size;
232 left_index = index - 1;
233 right_index = index + 1;
235 node_row_index = math.ceil(index / side_size);
236 if (upper_index >= 0):
242 if ( (left_index >= 0)
and (math.ceil(left_index / side_size) == node_row_index) ):
245 if ( (right_index < self.
_num_osc)
and (math.ceil(right_index / side_size) == node_row_index) ):
249 def __create_grid_eight_connections(self):
251 @brief Creates network with connections that make up eight grid structure. 252 @details Each oscillator may be connected with eight neighbors in line with grid structure: right, right-upper, upper, upper-left, left, left-lower, lower, lower-right. 259 for index
in range(0, self.
_num_osc, 1):
260 upper_left_index = index - side_size - 1;
261 upper_right_index = index - side_size + 1;
263 lower_left_index = index + side_size - 1;
264 lower_right_index = index + side_size + 1;
266 node_row_index = math.floor(index / side_size);
267 upper_row_index = node_row_index - 1;
268 lower_row_index = node_row_index + 1;
270 if ( (upper_left_index >= 0)
and (math.floor(upper_left_index / side_size) == upper_row_index) ):
273 if ( (upper_right_index >= 0)
and (math.floor(upper_right_index / side_size) == upper_row_index) ):
276 if ( (lower_left_index < self.
_num_osc)
and (math.floor(lower_left_index / side_size) == lower_row_index) ):
279 if ( (lower_right_index < self.
_num_osc)
and (math.floor(lower_right_index / side_size) == lower_row_index) ):
283 def __create_list_bidir_connections(self):
285 @brief Creates network as bidirectional list. 286 @details Each oscillator may be conneted with two neighbors in line with classical list structure: right, left. 291 for index
in range(0, self.
_num_osc, 1):
310 def __create_none_connections(self):
312 @brief Creates network without connections. 316 for _
in range(0, self.
_num_osc, 1):
322 def __create_dynamic_connection(self):
324 @brief Prepare storage for dynamic connections. 328 for _
in range(0, self.
_num_osc, 1):
334 def _create_structure(self, type_conn = conn_type.ALL_TO_ALL):
336 @brief Creates connection in line with representation of matrix connections [NunOsc x NumOsc]. 338 @param[in] type_conn (conn_type): Connection type (all-to-all, bidirectional list, grid structure, etc.) that is used by the network. 344 if (type_conn == conn_type.NONE):
347 elif (type_conn == conn_type.ALL_TO_ALL):
350 elif (type_conn == conn_type.GRID_FOUR):
353 elif (type_conn == conn_type.GRID_EIGHT):
356 elif (type_conn == conn_type.LIST_BIDIR):
359 elif (type_conn == conn_type.DYNAMIC):
363 raise NameError(
'The unknown type of connections');
368 @brief Returns True if there is connection between i and j oscillators and False - if connection doesn't exist. 370 @param[in] i (uint): index of an oscillator in the network. 371 @param[in] j (uint): index of an oscillator in the network. 378 for neigh_index
in range(0, len(self.
_osc_conn[i]), 1):
379 if (self.
_osc_conn[i][neigh_index] == j):
384 raise NameError(
"Unknown type of representation of coupling");
389 @brief Couples two specified oscillators in the network with dynamic connections. 391 @param[in] i (uint): index of an oscillator that should be coupled with oscillator 'j' in the network. 392 @param[in] j (uint): index of an oscillator that should be coupled with oscillator 'i' in the network. 394 @note This method can be used only in case of DYNAMIC connections, otherwise it throws expection. 398 if (self.
structure != conn_type.DYNAMIC):
399 raise NameError(
"Connection between oscillators can be changed only in case of dynamic type.");
411 @brief Finds neighbors of the oscillator with specified index. 413 @param[in] index (uint): index of oscillator for which neighbors should be found in the network. 415 @return (list) Indexes of neighbors of the specified oscillator. 422 return [neigh_index
for neigh_index
in range(self.
_num_osc)
if self.
_osc_conn[index][neigh_index] ==
True];
424 raise NameError(
"Unknown type of representation of connections");
def __create_list_bidir_connections(self)
Creates network as bidirectional list.
def __create_all_to_all_connections(self)
Creates connections between all oscillators.
Enumerator of internal network connection representation between oscillators.
def __len__(self)
Returns size of the network that is defined by amount of oscillators.
def __create_none_connections(self)
Creates network without connections.
def __init__(self, num_osc, type_conn=conn_type.ALL_TO_ALL, conn_repr=conn_represent.MATRIX, height=None, width=None)
Constructor of the network.
Enumerator of solver types that are used for network simulation.
def set_connection(self, i, j)
Couples two specified oscillators in the network with dynamic connections.
def width(self)
Width of the network grid, this value is zero in case of non-grid structure.
Enumerator of connection types between oscillators.
def __create_grid_eight_connections(self)
Creates network with connections that make up eight grid structure.
def has_connection(self, i, j)
Returns True if there is connection between i and j oscillators and False - if connection doesn't exi...
def get_neighbors(self, index)
Finds neighbors of the oscillator with specified index.
Enumerator of types of oscillator output initialization.
def _create_structure(self, type_conn=conn_type.ALL_TO_ALL)
Creates connection in line with representation of matrix connections [NunOsc x NumOsc].
def structure(self)
Type of network structure that is used for connecting oscillators.
Common network description that consists of information about oscillators and connection between them...
def height(self)
Height of the network grid (that is defined by amout of oscillators in each column), this value is zero in case of non-grid structure.
def __create_grid_four_connections(self)
Creates network with connections that make up four grid structure.
def __create_dynamic_connection(self)
Prepare storage for dynamic connections.
def __create_connection(self, index1, index2)