Ejemplo n.º 1
0
    def testAverageNeighborFourDistanceNegativeValues(self):
        points = [[0.0, 0.0], [0.0, -1.0], [-1.0, -1.0], [-1.0, 0.0]]

        assert average_neighbor_distance(points, 1) == 1.0
        assert average_neighbor_distance(points, 2) == 1.0
        assert self.float_comparasion(average_neighbor_distance(points, 3),
                                      1.1381)
Ejemplo n.º 2
0
 def process(self, order = 0.998, solution = solve_type.FAST, collect_dynamic = False):
     """!
     @brief Performs clustering of input data set in line with input parameters.
     
     @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1].
     @param[in] solution (solve_type) Type of solving differential equation.
     @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over).
     
     @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. 
     
     @see get_clusters()
     
     """
     
     if (self.__ccore_network_pointer is not None):
         analyser = wrapper.hsyncnet_process(self.__ccore_network_pointer, order, solution, collect_dynamic);
         return syncnet_analyser(None, None, analyser);
     
     number_neighbors = self.__initial_neighbors;
     current_number_clusters = float('inf');
     
     dyn_phase = [];
     dyn_time = [];
     
     radius = average_neighbor_distance(self._osc_loc, number_neighbors);
     
     increase_step = int(len(self._osc_loc) * self.__increase_persent);
     if (increase_step < 1):
         increase_step = 1;
     
     
     analyser = None;
     while(current_number_clusters > self._number_clusters):
         self._create_connections(radius);
     
         analyser = self.simulate_dynamic(order, solution, collect_dynamic);
         if (collect_dynamic == True):
             if (len(dyn_phase) == 0):
                 self.__store_dynamic(dyn_phase, dyn_time, analyser, True);
             
             self.__store_dynamic(dyn_phase, dyn_time, analyser, False);
         
         clusters = analyser.allocate_sync_ensembles(0.05);
         
         # Get current number of allocated clusters
         current_number_clusters = len(clusters);
         
         # Increase number of neighbors that should be used
         number_neighbors += increase_step;
         
         # Update connectivity radius and check if average function can be used anymore
         radius = self.__calculate_radius(number_neighbors, radius);
     
     if (collect_dynamic != True):
         self.__store_dynamic(dyn_phase, dyn_time, analyser, False);
     
     return syncnet_analyser(dyn_phase, dyn_time, None);
Ejemplo n.º 3
0
 def process(self, order = 0.998, solution = solve_type.FAST, collect_dynamic = False):
     """!
     @brief Performs clustering of input data set in line with input parameters.
     
     @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1].
     @param[in] solution (solve_type) Type of solving differential equation.
     @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over).
     
     @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. 
     
     @see get_clusters()
     
     """
     
     if (self.__ccore_network_pointer is not None):
         analyser = wrapper.hsyncnet_process(self.__ccore_network_pointer, order, solution, collect_dynamic);
         return syncnet_analyser(None, None, analyser);
     
     number_neighbors = 0;
     current_number_clusters = float('inf');
     
     dyn_phase = [];
     dyn_time = [];
     
     radius = 0.0;
     
     while(current_number_clusters > self._number_clusters):                
         self._create_connections(radius);
     
         analyser = self.simulate_dynamic(order, solution, collect_dynamic);
         if (collect_dynamic == True):
             dyn_phase += analyser.output;
             
             if (len(dyn_time) > 0):
                 point_time_last = dyn_time[len(dyn_time) - 1];
                 dyn_time += [time_point + point_time_last for time_point in analyser.time];
             else:
                 dyn_time += analyser.time;
         
         clusters = analyser.allocate_sync_ensembles(0.05);
         
         # Get current number of allocated clusters
         current_number_clusters = len(clusters);
         
         # Increase number of neighbors that should be used
         number_neighbors += 1;
         
         # Update connectivity radius and check if average function can be used anymore
         if (number_neighbors >= len(self._osc_loc)):
             radius = radius * 0.1 + radius;
         else:
             radius = average_neighbor_distance(self._osc_loc, number_neighbors);
     
     return syncnet_analyser(dyn_phase, dyn_time, None);
Ejemplo n.º 4
0
    def __calculate_radius(self, number_neighbors, radius):
        """!
        @brief Calculate new connectivity radius.
        
        @param[in] number_neighbors (uint): Average amount of neighbors that should be connected by new radius.
        @param[in] radius (double): Current connectivity radius.
        
        @return New connectivity radius.
        
        """

        if (number_neighbors >= len(self._osc_loc)):
            return radius * self.__increase_persent + radius

        return average_neighbor_distance(self._osc_loc, number_neighbors)
Ejemplo n.º 5
0
 def __calculate_radius(self, number_neighbors, radius):
     """!
     @brief Calculate new connectivity radius.
     
     @param[in] number_neighbors (uint): Average amount of neighbors that should be connected by new radius.
     @param[in] radius (double): Current connectivity radius.
     
     @return New connectivity radius.
     
     """
     
     if (number_neighbors >= len(self._osc_loc)):
         return radius * self.__increase_persent + radius;
     
     return average_neighbor_distance(self._osc_loc, number_neighbors);
Ejemplo n.º 6
0
    def process(self, number_neighbours, collect_dynamic=False, order=0.999):
        """!
        @brief Performs simulation of the oscillatory network.
        
        @param[in] number_neighbours (uint): Number of neighbours that should be used for calculation average distance and creation connections between oscillators.
        @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics.
        @param[in] order (double): Order of process synchronization that should be considered as end of clustering, destributed 0..1.
        
        @return (tuple) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time,
                otherwise returns only last values (last step of simulation) of dynamic.
        
        @see get_som_clusters()
        @see get_clusters()
        """

        # train self-organization map.
        self._som.train(self._data, 100)

        # prepare to build list.
        weights = list()
        self._som_osc_table.clear()
        # must be cleared, if it's used before.
        for i in range(self._som.size):
            if self._som.awards[i] > 0:
                weights.append(self._som.weights[i])
                self._som_osc_table.append(i)

        # calculate trusted distance between objects.
        radius = 0
        if len(weights) >= number_neighbours:
            radius = average_neighbor_distance(weights, number_neighbours)
        else:
            radius = 0

        # create oscillatory neural network.
        self._sync = syncnet(weights, radius, initial_phases=initial_type.EQUIPARTITION)
        self._analyser = self._sync.process(order, collect_dynamic=collect_dynamic)

        # Draw SOM clusters.
        # clusters = self._sync.get_clusters();
        # draw_clusters(weights, clusters);
        # self._som.show_network(awards = False, belongs = True);

        # return dynamic if it was requested.
        return (self._analyser.time, self._analyser.output)
Ejemplo n.º 7
0
 def __create_weights(self, stimulus):
     """!
     @brief Create weights between neurons in line with stimulus.
     
     @param[in] stimulus (list): External stimulus for the chaotic neural network.
     
     """
     
     self.__average_distance = average_neighbor_distance(stimulus, self.__amount_neighbors)
     
     self.__weights = [ [ 0.0 for _ in range(len(stimulus)) ] for _ in range(len(stimulus)) ]
     self.__weights_summary = [ 0.0 for _ in range(self.__num_osc) ]
     
     if self.__conn_type == type_conn.ALL_TO_ALL:
         self.__create_weights_all_to_all(stimulus)
     
     elif self.__conn_type == type_conn.TRIANGULATION_DELAUNAY:
         self.__create_weights_delaunay_triangulation(stimulus)
Ejemplo n.º 8
0
 def process(self, number_neighbours, collect_dynamic = False, order = 0.999):
     """!
     @brief Performs simulation of the oscillatory network.
     
     @param[in] number_neighbours (uint): Number of neighbours that should be used for calculation average distance and creation connections between oscillators.
     @param[in] collect_dynamic (bool): If True - returns whole dynamic of oscillatory network, otherwise returns only last values of dynamics.
     @param[in] order (double): Order of process synchronization that should be considered as end of clustering, destributed 0..1.
     
     @return (tuple) Dynamic of oscillatory network. If argument 'collect_dynamic' = True, than return dynamic for the whole simulation time,
             otherwise returns only last values (last step of simulation) of dynamic.
     
     @see get_som_clusters()
     @see get_clusters()
     """
     
     # train self-organization map.
     self._som.train(self._data, 100);
     
     # prepare to build list.
     weights = list();
     self._som_osc_table.clear();        # must be cleared, if it's used before.
     for i in range(self._som.size):
         if (self._som.awards[i] > 0):
             weights.append(self._som.weights[i]);
             self._som_osc_table.append(i);
     
     # calculate trusted distance between objects.
     radius = 0;
     if (len(weights) >= number_neighbours):
         radius = average_neighbor_distance(weights, number_neighbours);
     else:
         radius = 0;
     
     # create oscillatory neural network.
     self._sync = syncnet(weights, radius, initial_phases = initial_type.EQUIPARTITION);
     self._analyser = self._sync.process(order, collect_dynamic = collect_dynamic);
     
     # Draw SOM clusters.
     #clusters = self._sync.get_clusters();
     #draw_clusters(weights, clusters);
     #self._som.show_network(awards = False, belongs = True);
     
     # return dynamic if it was requested.
     return (self._analyser.time, self._analyser.output);   
Ejemplo n.º 9
0
    def process(self,
                order=0.998,
                solution=solve_type.FAST,
                collect_dynamic=False):
        """!
        @brief Performs clustering of input data set in line with input parameters.
        
        @param[in] order (double): Level of local synchronization between oscillator that defines end of synchronization process, range [0..1].
        @param[in] solution (solve_type) Type of solving differential equation.
        @param[in] collect_dynamic (bool): If True - returns whole history of process synchronization otherwise - only final state (when process of clustering is over).
        
        @return (tuple) Returns dynamic of the network as tuple of lists on each iteration (time, oscillator_phases) that depends on collect_dynamic parameter. 
        
        @see get_clusters()
        
        """

        if (self.__ccore_network_pointer is not None):
            analyser = wrapper.hsyncnet_process(self.__ccore_network_pointer,
                                                order, solution,
                                                collect_dynamic)
            return syncnet_analyser(None, None, analyser)

        number_neighbors = self.__initial_neighbors
        current_number_clusters = float('inf')

        dyn_phase = []
        dyn_time = []

        radius = average_neighbor_distance(self._osc_loc, number_neighbors)

        increase_step = int(len(self._osc_loc) * self.__increase_persent)
        if (increase_step < 1):
            increase_step = 1

        analyser = None
        while (current_number_clusters > self._number_clusters):
            self._create_connections(radius)

            analyser = self.simulate_dynamic(order, solution, collect_dynamic)
            if (collect_dynamic == True):
                if (len(dyn_phase) == 0):
                    self.__store_dynamic(dyn_phase, dyn_time, analyser, True)

                self.__store_dynamic(dyn_phase, dyn_time, analyser, False)

            clusters = analyser.allocate_sync_ensembles(0.05)

            # Get current number of allocated clusters
            current_number_clusters = len(clusters)

            # Increase number of neighbors that should be used
            number_neighbors += increase_step

            # Update connectivity radius and check if average function can be used anymore
            radius = self.__calculate_radius(number_neighbors, radius)

        if (collect_dynamic != True):
            self.__store_dynamic(dyn_phase, dyn_time, analyser, False)

        return syncnet_analyser(dyn_phase, dyn_time, None)
Ejemplo n.º 10
0
 def testAverageNeighborFourDistance(self):
     points = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
     
     assert average_neighbor_distance(points, 1) == 1.0;
     assert average_neighbor_distance(points, 2) == 1.0;
     assert self.float_comparasion(average_neighbor_distance(points, 3), 1.1381);
Ejemplo n.º 11
0
 def testAverageNeighborFourDistanceNegativeValues(self):
     points = [[0.0, 0.0], [0.0, -1.0], [-1.0, -1.0], [-1.0, 0.0]];
     
     assert average_neighbor_distance(points, 1) == 1.0;
     assert average_neighbor_distance(points, 2) == 1.0;
     assert self.float_comparasion(average_neighbor_distance(points, 3), 1.1381);
Ejemplo n.º 12
0
 def testAverageNeighborDistance(self):
     points = [[0, 0], [0, 1], [1, 1], [1, 0]];
     
     assert average_neighbor_distance(points, 1) == 1.0;
     assert average_neighbor_distance(points, 2) == 1.0;
     assert self.float_comparasion(average_neighbor_distance(points, 3), 1.1381);