Beispiel #1
0
 def __upload_dump_to_ccore(self, state_dump):
     self.__upload_common_part(state_dump)
     self.__ccore_som_pointer = wrapper.som_create(self._rows, self._cols,
                                                   self._conn_type,
                                                   self._params)
     wrapper.som_load(self.__ccore_som_pointer, state_dump['weights'],
                      state_dump['award'], state_dump['capture_objects'])
Beispiel #2
0
    def __init__(self, rows, cols, conn_type=type_conn.grid_eight, parameters=None, ccore=True):
        """!
        @brief Constructor of self-organized map.
        
        @param[in] rows (uint): Number of neurons in the column (number of rows).
        @param[in] cols (uint): Number of neurons in the row (number of columns).
        @param[in] conn_type (type_conn): Type of connection between oscillators in the network (grid four, grid eight, honeycomb, function neighbour).
        @param[in] parameters (som_parameters): Other specific parameters.
        @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).

        """

        # some of these parameters are required despite core implementation, for example, for network visualization.
        self._cols = cols

        self._rows = rows

        self._size = cols * rows

        self._conn_type = conn_type

        self._data = None

        self._neighbors = None

        self._local_radius = 0.0

        self._learn_rate = 0.0

        self.__ccore_som_pointer = None

        self._params = parameters or som_parameters()

        if self._params.init_radius is None:
            self._params.init_radius = self.__initialize_initial_radius(rows, cols)

        if (ccore is True) and ccore_library.workable():
            self.__ccore_som_pointer = wrapper.som_create(rows, cols, conn_type, self._params)

        else:
            # location
            self._location = self.__initialize_locations(rows, cols)

            # default weights
            self._weights = [[0.0]] * self._size

            # awards
            self._award = [0] * self._size

            # captured objects
            self._capture_objects = [[] for i in range(self._size)]

            # distances - calculate and store them only during training
            self._sqrt_distances = None

            # connections
            if conn_type != type_conn.func_neighbor:
                self._create_connections(conn_type)
Beispiel #3
0
 def __init__(self, rows, cols, conn_type = type_conn.grid_eight, parameters = None, ccore = False):
     """!
     @brief Constructor of self-organized map.
     
     @param[in] rows (uint): Number of neurons in the column (number of rows).
     @param[in] cols (uint): Number of neurons in the row (number of columns).
     @param[in] conn_type (type_conn): Type of connection between oscillators in the network (grid four, grid eight, honeycomb, function neighbour).
     @param[in] parameters (som_parameters): Other specific parameters.
     @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).
     
     """
     
     # some of these parameters are required despite core implementation, for example, for network demonstration.
     self._cols = cols;
     self._rows = rows;        
     self._size = cols * rows;
     self._conn_type = conn_type;
     
     if (parameters is not None):
         self._params = parameters;
     else:
         self._params = som_parameters();
         
     if (self._params.init_radius is None):
         if ((cols + rows) / 4.0 > 1.0): 
             self._params.init_radius = 2.0;
         elif ( (cols > 1) and (rows > 1) ): 
             self._params.init_radius = 1.5;
         else: 
             self._params.init_radius = 1.0;
     
     if (ccore is True):
         self.__ccore_som_pointer = wrapper.som_create(rows, cols, conn_type, self._params);
         
     else:
         # location
         self._location = list();
         for i in range(self._rows):
             for j in range(self._cols):
                 self._location.append([float(i), float(j)]);
         
         # awards
         self._award = [0] * self._size;
         self._capture_objects = [ [] for i in range(self._size) ];
         
         # distances
         self._sqrt_distances = [ [ [] for i in range(self._size) ] for j in range(self._size) ];
         for i in range(self._size):
             for j in range(i, self._size, 1):
                 dist = euclidean_distance_sqrt(self._location[i], self._location[j]);
                 self._sqrt_distances[i][j] = dist;
                 self._sqrt_distances[j][i] = dist;
     
         # connections
         if (conn_type != type_conn.func_neighbor):
             self._create_connections(conn_type);
Beispiel #4
0
    def __init__(self,
                 rows,
                 cols,
                 conn_type=type_conn.grid_eight,
                 parameters=None,
                 ccore=False):
        """!
        @brief Constructor of self-organized map.
        
        @param[in] rows (uint): Number of neurons in the column (number of rows).
        @param[in] cols (uint): Number of neurons in the row (number of columns).
        @param[in] conn_type (type_conn): Type of connection between oscillators in the network (grid four, grid eight, honeycomb, function neighbour).
        @param[in] parameters (som_parameters): Other specific parameters.
        @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).
        
        """

        # some of these parameters are required despite core implementation, for example, for network demonstration.
        self._cols = cols
        self._rows = rows
        self._size = cols * rows
        self._conn_type = conn_type

        if (parameters is not None):
            self._params = parameters
        else:
            self._params = som_parameters()

        if (self._params.init_radius is None):
            if ((cols + rows) / 4.0 > 1.0):
                self._params.init_radius = 2.0
            elif ((cols > 1) and (rows > 1)):
                self._params.init_radius = 1.5
            else:
                self._params.init_radius = 1.0

        if (ccore is True):
            self.__ccore_som_pointer = wrapper.som_create(
                rows, cols, conn_type, self._params)

        else:
            # location
            self._location = list()
            for i in range(self._rows):
                for j in range(self._cols):
                    self._location.append([float(i), float(j)])

            # awards
            self._award = [0] * self._size
            self._capture_objects = [[] for i in range(self._size)]

            # distances
            self._sqrt_distances = [[[] for i in range(self._size)]
                                    for j in range(self._size)]
            for i in range(self._size):
                for j in range(i, self._size, 1):
                    dist = euclidean_distance_sqrt(self._location[i],
                                                   self._location[j])
                    self._sqrt_distances[i][j] = dist
                    self._sqrt_distances[j][i] = dist

            # connections
            if (conn_type != type_conn.func_neighbor):
                self._create_connections(conn_type)
Beispiel #5
0
    def __init__(self, rows, cols, conn_type = type_conn.grid_eight, parameters = None, ccore = True):
        """!
        @brief Constructor of self-organized map.
        
        @param[in] rows (uint): Number of neurons in the column (number of rows).
        @param[in] cols (uint): Number of neurons in the row (number of columns).
        @param[in] conn_type (type_conn): Type of connection between oscillators in the network (grid four, grid eight, honeycomb, function neighbour).
        @param[in] parameters (som_parameters): Other specific parameters.
        @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).
        
        """
        
        # some of these parameters are required despite core implementation, for example, for network demonstration.
        self._cols = cols
        
        self._rows = rows
        
        self._size = cols * rows
        
        self._conn_type = conn_type
        
        self._data = None
        
        self._neighbors = None
        
        self._local_radius = 0.0
        
        self._learn_rate = 0.0
        
        self.__ccore_som_pointer = None

        if parameters is not None:
            self._params = parameters
        else:
            self._params = som_parameters()
            
        if self._params.init_radius is None:
            self._params.init_radius = self.__initialize_initial_radius(rows, cols)
        
        if (ccore is True) and ccore_library.workable():
            self.__ccore_som_pointer = wrapper.som_create(rows, cols, conn_type, self._params)
            
        else:
            # location
            self._location = self.__initialize_locations(rows, cols)
            
            # default weights
            self._weights = [ [0.0] ] * self._size
            
            # awards
            self._award = [0] * self._size
            
            # captured objects
            self._capture_objects = [ [] for i in range(self._size) ]
            
            # distances - calculate and store them only during training
            self._sqrt_distances = None
        
            # connections
            if conn_type != type_conn.func_neighbor:
                self._create_connections(conn_type)
Beispiel #6
0
 def __upload_dump_to_ccore(self, state_dump):
     self.__upload_common_part(state_dump)
     self.__ccore_som_pointer = wrapper.som_create(self._rows, self._cols, self._conn_type, self._params)
     wrapper.som_load(self.__ccore_som_pointer, state_dump['weights'], state_dump['award'], state_dump['capture_objects'])
Beispiel #7
0
 def __init__(self, rows, cols, data, epochs, conn_type = type_conn.grid_eight, parameters = None, ccore = False):
     """!
     @brief Constructor of self-organized map.
     
     @param[in] rows (uint): Number of neurons in the column (number of rows).
     @param[in] cols (uint): Number of neurons in the row (number of columns).
     @param[in] data (list): Input data - list of points where each point is represented by list of features, for example coordinates.
     @param[in] epochs (uint): Number of epochs for training.
     @param[in] conn_type (type_conn): Type of connection between oscillators in the network (grid four, grid eight, honeycomb, function neighbour).
     @param[in] parameters (som_parameters): Other specific parameters.
     @param[in] ccore (bool): If True simulation is performed by CCORE library (C++ implementation of pyclustering).
     
     """
     
     # some of these parameters are required despite core implementation, for example, for network demonstration.
     self._cols = cols;
     self._rows = rows;        
     self._data = data;
     self._size = cols * rows;
     self._epochs = epochs;
     self._conn_type = conn_type;
     
     if (parameters is not None):
         self._params = parameters;
     else:
         self._params = som_parameters();
         
     if (self._params.init_radius is None):
         if ((cols + rows) / 4.0 > 1.0): 
             self._params.init_radius = 2.0;
         elif ( (cols > 1) and (rows > 1) ): 
             self._params.init_radius = 1.5;
         else: 
             self._params.init_radius = 1.0;
     
     if (ccore is True):
         self.__ccore_som_pointer = wrapper.som_create(data, rows, cols, epochs, conn_type, self._params);
         
     else:
         # location
         self._location = list();
         for i in range(self._rows):
             for j in range(self._cols):
                 self._location.append([float(i), float(j)]);
         
         # awards
         self._award = [0] * self._size;
         self._capture_objects = [ [] for i in range(self._size) ];
         
         # distances
         self._sqrt_distances = [ [ [] for i in range(self._size) ] for j in range(self._size) ];
         for i in range(self._size):
             for j in range(i, self._size, 1):
                 dist = euclidean_distance_sqrt(self._location[i], self._location[j]);
                 self._sqrt_distances[i][j] = dist;
                 self._sqrt_distances[j][i] = dist;
     
         # connections
         if (conn_type != type_conn.func_neighbor):
             self._create_connections(conn_type);
         
         # weights
         self._create_initial_weights(self._params.init_type);