コード例 #1
0
def update_from_select_nm(self):
    phase_space = self.phase_space
    creator = self.Creator
    selector = self.Selector
    version = self.version
    phase_space.time = phase_space.time + 1
    list_particles = [
        phase_space.node2particles(node) for node in phase_space.objects
    ]
    print("particles: ", list_particles)
    node_max = node_max_particles(phase_space)
    p_m = Funct.node2num_particles(node_max)
    node_c = phase_space.key2node(phase_space.DNA_graph.center)
    p_c = Funct.node2num_particles(node_c)
    print(f'The value of p_m is : {p_m} and pc is : {p_c} ')
    if (p_m > p_c * 2):
        phase_space.time = 0
        num_particles = phase_space.num_particles
        old_graph = phase_space.DNA_graph
        old_center = old_graph.center
        condition = old_graph.condition
        typos = old_graph.typos
        #node_max = phase_space.node_max_particles
        node_max = node_max_particles(phase_space)
        print("node_max particles:", Funct.node2num_particles(node_max))
        center = phase_space.node2key(node_max)
        status = phase_space.status
        Alai = status.Alai
        stream = phase_space.stream
        delta = stream.key2len_hist(center)
        Alai.update(delta)
        stream.signals_off()
        stream.key2signal_on(center)
        stream.clear()
        selector.update(center)
        actions = selector.get_predicted_actions()
        x = old_graph.x_dim
        y = old_graph.y_dim
        space = DNA_Graph(center,
                          1, (x, y),
                          condition,
                          actions,
                          version,
                          creator,
                          selector=selector,
                          num_morphisms=5)
        phase_space.DNA_graph = space
        phase_space.objects = space.objects
        phase_space.support = []
        phase_space.create_particles(num_particles + 1)
        phase_space.attach_balls()
        phase_space.max_changed = False
        phase_space.node_max_particles = None
        self.space = space
        self.phase_space = phase_space
        self.objects = phase_space.objects
        self.support = phase_space.support
        self.Graph = phase_space.DNA_graph
コード例 #2
0
def update_from_select_Alai(self):
    phase_space = self.phase_space
    creator = self.Creator
    selector = self.Selector
    version = self.version
    phase_space.time = phase_space.time + 1
    node_max = node_max_particles(phase_space)
    node_c = phase_space.key2node(phase_space.DNA_graph.center)
    p_c = Funct.node2num_particles(node_c)
    p_m = Funct.node2num_particles(node_max)
    print(f'The value of p_m is : {p_m} and p_c is : {p_c} ')
    if (p_m > p_c * 2) or (phase_space.time > 4000):
        phase_space.time = 0
        num_particles = phase_space.num_particles
        old_graph = phase_space.DNA_graph
        old_center = old_graph.center
        condition = old_graph.condition
        typos = old_graph.typos
        node_max = phase_space.node_max_particles
        center = phase_space.node2key(node_max)
        selector.update(old_graph, new_center=center)
        actions = selector.get_predicted_actions()
        x = old_graph.x_dim
        y = old_graph.y_dim
        space = DNA_Graph(center, 1, (x, y), condition, actions, version,
                          creator)
        phase_space.DNA_graph = space
        phase_space.objects = space.objects
        phase_space.support = []
        phase_space.create_particles(num_particles + 1)
        phase_space.stream.signals_off()
        phase_space.attach_balls()
        phase_space.max_changed = False
        phase_space.node_max_particles = None
        self.space = space
        self.phase_space = phase_space
        self.objects = phase_space.objects
        self.support = phase_space.support
        self.Graph = phase_space.DNA_graph
    elif False:
        #elif phase_space.time>self.clear_period:
        phase_space.time = 0
        node2remove = phase_space2node2remove(phase_space)
        node_c = phase_space.key2node(phase_space.DNA_graph.center)
        if node2remove and not (node2remove == node_c):
            remove_node(phase_space, node2remove)
            new_DNA = add_node(phase_space, selector)
コード例 #3
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)
コード例 #4
0
def update_from_select_stochastic(self):
    phase_space = self.phase_space
    creator = self.Creator
    selector = self.Selector
    version = self.version
    phase_space.time = phase_space.time + 1
    p = randint(0, 300)
    if phase_space.node_max_particles:
        node_max = phase_space.node_max_particles
        node_c = phase_space.key2node(phase_space.DNA_graph.center)
        p_c = Funct.node2num_particles(node_c)
        p_m = Funct.node2num_particles(node_max)
    if (phase_space.max_changed
            and p_m * 0.9 > p_c) or (phase_space.time > 4000):
        phase_space.time = 0
        num_particles = phase_space.num_particles
        old_graph = phase_space.DNA_graph
        old_center = old_graph.center
        condition = old_graph.condition
        typos = old_graph.typos
        node_max = phase_space.node_max_particles
        center = phase_space.node2key(node_max)
        selector.update(old_graph, new_center=center)
        actions = selector.get_predicted_actions()
        x = old_graph.x_dim
        y = old_graph.y_dim
        space = DNA_Graph(center, 1, (x, y), condition, actions, version,
                          creator)
        phase_space.DNA_graph = space
        phase_space.objects = space.objects
        phase_space.support = []
        phase_space.create_particles(num_particles + 1)
        phase_space.stream.signals_off()
        phase_space.attach_balls()
        phase_space.max_changed = False
        phase_space.node_max_particles = None
        self.space = space
        self.phase_space = phase_space
        self.objects = phase_space.objects
        self.support = phase_space.support
        self.Graph = phase_space.DNA_graph
コード例 #5
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 = (self.observations + [
             self.node2obs(space, node)
             for node in node_c.kids if Funct.node2num_particles(node) > 0
         ])