コード例 #1
0
    def update_current_center(self, space=None, new_center=None):

        if not (type(space)) is tuple:
            node_nc = space.key2node(new_center)
            if not (new_center == space.center):
                direction = Funct.node2direction(node_nc)
                if direction[1] == (1, 0, 0, 0):
                    self.center = self.center + 1
                elif direction[1] == (-1, 0, 0, 0):
                    self.center = self.center - 1

        if self.observations:
            node_new_c = space.graph.node2key
            lef_weight = sum([
                observation.weight for observation in self.observations
                if observation.path[0] < 0
            ])
            right_weight = sum([
                observation.weight for observation in self.observations
                if observation.path[0] > 0
            ])
            center_weight = sum([
                observation.weight for observation in self.observations
                if observation.path[0] == 0
            ])
            if center_weight > max(lef_weight, center_weight):
                pass
            elif right_weight > lef_weight:
                self.center = self.center + 1
            elif right_weight < lef_weight:
                self.center = self.center - 1
コード例 #2
0
 def node2obs(self, space, node):
     creator = self.observation_creator
     weight = Funct.node2num_particles(node)
     path = list(Funct.node2direction(node))
     path[0] = path[0] - self.center
     num_conv_layers = len(
         [0 for layer in space.node2key(node) if layer[0] == 0])
     return creator(num_layer=num_conv_layers, path=path, weight=weight)
コード例 #3
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)
コード例 #4
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