Example #1
0
    def update_current_path(self,space, new_center):
        
        if not isinstance(space, tuple) and new_center is not None:
            node_nc = space.key2node(new_center)
            absolute_direction = Funct.node2direction(node_nc)
            relative_direction = Funct.absolute2relative(direction=absolute_direction, last_layer=self.last_mutated_layer,
                                                            max_layers=self.max_layers_condition)
            self.current_path.path.append(relative_direction)
            self.current_path.absolute_path.append(absolute_direction)

            if len(self.current_path.path)>self.max_path_size:
                self.current_path.path.pop(0)
                self.current_path.absolute_path.pop(0)
Example #2
0
    def register_observations(self,space,new_center=None):
        
        creator=self.observation_creator
        if type(space) is tuple:
            num_conv_layers = len([0 for layer in space if
                layer[0] == 0])
            self.current_num_layer=num_conv_layers
            if new_center:
                self.center_key=new_center
            else:
                self.center_key=space
        else:
            if new_center:
                self.center_key=new_center
            else:
                self.center_key=space.center
            center=space.center
            self.current_num_layer=len([0 for layer in new_center if
                layer[0] == 0])
            node_c=space.key2node(center)
            
            self.observations = []
            
            weight_array = []
            i = 0
            for node in node_c.kids:

                if Funct.node2energy(node) > 0:
                    weight_array.append(Funct.node2energy(node)*10)

            weight_array = Funct.normalize(dataset=weight_array)
            for node in node_c.kids:

                if Funct.node2energy(node) > 0:

                    observation_path = []
                    for direction in self.current_path.path:
                        observation_path.append(direction)

                    absolute_direction = Funct.node2direction(node)
                    relative_direction = Funct.absolute2relative(direction=absolute_direction, last_layer=self.last_mutated_layer, 
                                                                    max_layers=self.max_layers_condition)
                    observation_path.append(relative_direction)

                    if len(observation_path) > self.max_observation_size:
                        observation_path.pop(0)
                    
                    observation = self.observation_creator(path=observation_path, weight=weight_array[i])
                    self.observations.append(observation)

                    i += 1