def update_from_select(self): phase_space = self.phase_space creator = self.Creator selector = self.Selector version = self.version phase_space.time = phase_space.time + 1 if phase_space.max_changed or phase_space.time > 2000: 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
def update_space_default(self): phase_space = self.phase_space if phase_space.max_changed: num_particles = phase_space.num_particles old_graph = phase_space.DNA_graph condition = old_graph.condition typos = old_graph.typos node_max = phase_space.node_max_particles center = phase_space.node2key(node_max) x = old_graph.x_dim y = old_graph.y_dim space = DNA_Graph(center, self.dx, (x, y), condition, typos, 'inclusion') #Phase_space = DNA_Phase_space(space) 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
def generateSpace(x, y): max_layers = 10 max_filters = 60 max_dense = 100 def condition_b(z): return max_filter_dense( max_filter(max_layer(z, max_layers), max_filters), max_dense) center = ((-1, 1, 3, 32, 32), (0, 3, 5, 3, 3), (0, 5, 6, 3, 3), (0, 6, 7, 3, 3, 2), (0, 7, 8, 16, 16), (1, 8, 10), (2, ), (3, -1, 0), (3, 0, 1), (3, 1, 2), (3, 2, 3), (3, 3, 4), (3, 4, 5)) version = 'h' mutations = ((4, 0, 0, 0), (1, 0, 0, 0), (0, 0, 1)) #mutations=((4,0,0,0),(1,0,0,0),(0,1,0,0),(0,1,0,0),(0,0,1)) sel = Selector_creator(condition=condition_b, directions=version, mutations=mutations, num_actions=5) print('The selector is') print(sel) sel.update(center) actions = sel.get_predicted_actions() creator = Creator_nm space = DNA_Graph(center, 1, (x, y), condition_b, actions, version, creator=creator, num_morphisms=5, selector=sel) return space
def __generate_new_space(self, firstTime=False): oldSpace = self.__space newCenter = self.__best_network.dna if firstTime == True: self.__selector.update(newCenter) else: self.__selector.update(oldSpace, newCenter) predicted_actions = self.__selector.get_predicted_actions() self.__actions = [] self.__actions = predicted_actions stop = False while stop == False: newSpace = DNA_Graph(center=newCenter, size=oldSpace.size, dim=(oldSpace.x_dim, oldSpace.y_dim), condition=oldSpace.condition, typos=predicted_actions, type_add_layer=oldSpace.version, creator=Creator_s) nodeCenter = self.__get_center_node(newSpace) if len(nodeCenter.kids) >= 0: print("kids: ", len(nodeCenter.kids)) stop = True self.__space = None self.__space = newSpace
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
def create_objects(status): status.Data_gen = GeneratorFromImage.GeneratorFromImage(status.Comp, status.S, cuda=status.cuda) status.Data_gen.dataConv2d() dataGen = status.Data_gen x = dataGen.size[1] y = dataGen.size[2] max_layers = status.max_layer max_filters = status.max_filter def condition(DNA): return max_filter(max_layer(DNA, max_layers), max_filters) version = status.typos_version """ center=((-1,1,3,x,y), (0,3, 4, x, y), (1, 4, 2), (2,),(3,-1,0),(3,0,1), (3,1,2))""" center = ((-1, 1, 3, x, y), (0, 3, 15, 3, 3), (0, 18, 15, 3, 3), (0, 33, 15, x, y), (1, 15, 2), (2, ), (3, -1, 0), (3, 0, 1), (3, -1, 1), (3, 1, 2), (3, 0, 2), (3, -1, 2), (3, 2, 3), (3, 3, 4)) selector = status.Selector_creator(condition=condition, directions=version) status.Selector = selector creator = status.Creator selector.update(center) actions = selector.get_predicted_actions() space = DNA_Graph(center, 1, (x, y), condition, actions, version, creator) if status.Alai: stream = TorchStream(status.Data_gen, status.log_size, min_size=status.min_log_size, Alai=status.Alai) else: stream = TorchStream(status.Data_gen, status.log_size, min_size=status.min_log_size) Phase_space = DNA_Phase_space(space, stream=stream) Dynamics = Dynamic_DNA(space, Phase_space, status.dx, Creator=creator, Selector=selector, update_velocity=velocity_updater, update_space=space_updater, version=version, mutation_coefficient=status.mutation_coefficient, clear_period=status.clear_period) Phase_space.create_particles(status.n) Phase_space.beta = status.beta Phase_space.alpha = status.alpha Phase_space.influence = status.influence status.Dynamics = Dynamics status.objects = Dynamics.objects
def create_objects(status): status.Data_gen = GeneratorFromImage.GeneratorFromImage(status.Comp, status.S, cuda=False) status.Data_gen.dataConv2d() dataGen = status.Data_gen x = dataGen.size[1] y = dataGen.size[2] def condition(DNA): output = True if DNA: for num_layer in range(0, len(DNA) - 3): layer = DNA[num_layer] x_l = layer[3] y_l = layer[4] output = output and (x_l < x) and (y_l < y) if output: return max_filter(max_layer(DNA, 3), 40) typos = [] print('The value of typos is') print(status.typos) #for element in status.typos: # if type(element) == list: # typos.append(tuple(element)) # else: # typos.append(element) #status.typos=tuple(typos) #Number of filters #center=((0, 3, 2, x, y), (1, 2, 2), (2,)) #space=DNA_Graph(center,status.dx,(x,y),condition,(0,(1,1,0,0))) #Dimension of kernel center = ((0, 3, 5, 3, 3), (0, 8, 8, 3, 3), (0, 11, 5, x, y), (1, 5, 2), (2, )) #center=((0, 3, 2, x, y), (1, 2, 2), (2,)) version = 'inclusion' space = space = DNA_Graph(center, status.dx, (x, y), condition, (0, (1, 0, 0, 0), (0, 0, 1, 1), (0, 1, 0, 0)), version) #space=space=DNA_Graph(center,1,(x,y),condition,(0,(1,0,0,0)),version) Phase_space = DNA_Phase_space(space) Dynamics = Dynamic_DNA(space, Phase_space, status.dx) Phase_space.create_particles(status.n) Phase_space.beta = status.beta Phase_space.alpha = status.alpha Phase_space.influence = status.influence status.Dynamics = Dynamics status.objects = Dynamics.objects
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)
def DNA_Creator_s(x, y, dna, version): def condition(DNA): return DNA_conditions.dict2condition(DNA, list_conditions) selector = None selector = LSTMSelector(condition=condition, directions=version, num_actions=num_actions, mutations=((1, 0, 0, 0), (1, 0, 0, 0), (0, 1, 0, 0), (0, 1, 0, 0), (4, 0, 0, 0), (0, 0, 1), (0, 0, -1), (0, 0, 1, 1), (0, 0, -1, -1), (0, 0, 2))) selector.update(dna) actions = selector.get_predicted_actions() space = DNA_Graph(dna, 1, (x, y), condition, actions, version, Creator_s) return [space, selector]
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
def create_objects(status, loaded_network): settings = status.settings status.Alai = Alai(min=status.dt_min, max=status.dt_Max, max_time=status.restart_period) if loaded_network == True: status.Alai.time = 14077 - 14076 status.Alai.reset_count = 1 status.Data_gen = GeneratorFromCIFAR.GeneratorFromCIFAR( status.Comp, status.S, cuda=status.cuda, threads=status.threads, dataAugmentation=settings.enable_augmentation, transforms_mode=settings.transformations_compose) status.Data_gen.dataConv2d() dataGen = status.Data_gen x = dataGen.size[1] y = dataGen.size[2] condition = status.condition mutations = status.mutations version = status.version center = status.Center num_actions = status.num_actions selector = status.Selector_creator(condition=condition, directions=version, num_actions=num_actions, mutations=mutations) status.Selector = selector creator = status.Creator selector.update(center) actions = selector.get_predicted_actions() space = DNA_Graph(center, 1, (x, y), condition, actions, version, creator, selector=status.Selector, num_morphisms=5) if status.Alai: stream = TorchStream(status.Data_gen, status.log_size, min_size=status.min_log_size, Alai=status.Alai, status=status) else: stream = TorchStream(status.Data_gen, status.log_size, min_size=status.min_log_size, status=status) status.stream = stream Phase_space = DNA_Phase_space(space, stream=stream, status=status) Dynamics = Dynamic_DNA( space, Phase_space, status.dx, Creator=creator, Selector=selector, update_velocity=velocity_updater, update_space=space_updater, version=version, mutation_coefficient=status.mutation_coefficient, clear_period=status.clear_period, update_force_field=status.update_force_field, ) Phase_space.create_particles(status.n) Phase_space.beta = status.beta Phase_space.alpha = status.alpha Phase_space.influence = status.influence status.Dynamics = Dynamics status.objects = Dynamics.objects