def __generate_structure(self): # Grafo de objetos Node graph = Graphs.Graph(True) # Proceso para contar la cantidad de objetos Node que tendrá el grafo dependiendo de la cantidad y tipos de tuplas. for i in range(len(self.dna)): layer_tuple = self.dna[i] # Todas las tuplas que no sean conexiones entre capas. if layer_tuple[0] != 3: self.__len_nodes += 1 # Se construye el arreglo de objetos Node. for i in range(self.__len_nodes): self.nodes.append(nd.Node()) # Se realiza la conexión entre los objetos Node adyacentes. for i in range(self.__len_nodes): if i < (self.__len_nodes - 1): graph.add_node(i, self.nodes[i]) graph.add_node(i + 1, self.nodes[i + 1]) graph.add_edges(i, [i + 1]) self.nodes = list(graph.key2node.values()) # Método para asignar las capas (objetos de Pytorch) respectivas a cada objeto Node. self.__assign_layers()
def create(self, center, size, g=None): condition = self.condition if size > 0: if isinstance(center, tuple): g = gr.Graph() self.add_node(g, center) center = g.key2node.get(center) self.create(center, size, g) else: q = center.objects[0] DNA_o = q.shape node_o = center for direction in self.directions: if DNA_o: for k in range(len(DNA_o) - 2): # print('The value of k is') # print(k) # print('The value of DNA_o is:') # print(DNA_o) DNA_f = condition(direction(k, DNA_o)) if DNA_f: self.add_node(g, DNA_f) node_f = g.key2node.get(DNA_f) g.add_edges(DNA_o, [DNA_f]) if self.type_add_layer: label = self.directions_labels.get( direction) node = g.key2node.get(DNA_f) p = self.node2plane(node) if not (p.direction): p.direction = (k, label) if center.kids: for kid in center.kids: self.create(kid, size - 1, g) return g
def create(self, center, size, g=None): selector = self.Selector condition = self.condition num_actions = selector.num_actions if size > 0: if isinstance(center, tuple): g = gr.Graph() self.add_node(g, center) center = g.key2node.get(center) self.create(center, size, g) else: q = center.objects[0] DNA_o = q.shape node_o = center for l in range(num_actions): if DNA_o: DNA_f = DNA_o label = [] path = [] mutations_to_do = self.get_random_nm() print("morphisms: ", mutations_to_do) time.sleep(2) for m in range(mutations_to_do): selector.update(DNA_f) stop = False while stop == False: selector.update_predicted_actions() actions = selector.get_predicted_actions() typo = actions[0] direction = self.directions.get(typo[1]) num_layer = typo[0] temp = condition(direction(num_layer, DNA_f)) if isinstance(temp, tuple) == True: DNA_f = temp stop = True label.append(typo) path.append(DNA_f) #print(f'The label is {label}') if DNA_f: self.add_node(g, DNA_f) node_f = g.key2node.get(DNA_f) g.add_edges(DNA_o, [DNA_f]) if self.type_add_layer: node = g.key2node.get(DNA_f) p = self.node2plane(node) p.direction = label p.path = path #print(f'The label is{label}') #print(f'The label is{len(p.path)}') if center.kids: for kid in center.kids: self.create(kid, size - 1, g) return g
def add_edgest_test(): g=gr.Graph() g.add_node(0,nd.Node()) g.add_node(1,nd.Node()) g.add_node(2,nd.Node()) g.add_edges(1,[0]) g.add_edges(2,[1]) print('The kids are') print(len(g.key2node[0].kids)) print(len(g.key2node[1].kids)) print(len(g.key2node[2].kids))
def DNA2graph(DNA): layers = DNA2layers(DNA) synapses = DNA2synapses(DNA) g = gr.Graph(True) k = -1 for layer in layers: node = nd.Node() node.objects.append(layer) g.add_node(k, node) k = k + 1 for synapse in synapses: g.add_edges(synapse[1], [synapse[2]]) return g
def create_objects(status): status.Transfer = tran.TransferLocal(status, 'local2remote.txt', 'remote2local.txt') status.Transfer.un_load() status.Transfer.write() #status.Data_gen=dgen.Data_gen() #status.Data_gen.gen_data() def add_node(g, i): node = nd.Node() q = qu.Quadrant(i) p = tplane.tangent_plane() node.objects.append(q) q.objects.append(p) g.add_node(i, node) #status.objects.append(node) #Initializes graph g = gr.Graph() add_node(g, 0) k = 0 while k < status.dx: add_node(g, k + 1) g.add_edges(k, [k + 1]) k = k + 1 k = 0 status.objects = list(g.key2node.values()) node = status.objects[0] p = node_plane(node) #Initializes particles while k < status.n: par = particle() par.position.append(node) par.velocity.append(node) #print(status.Data_gen.size) # par.objects.append(nw.Network([status.Data_gen.size[0], # status.Data_gen.size[1],2])) p.particles.append(par) p.num_particles += 1 k = k + 1 #Initializes conectivity radius attach_balls(status, status.r)
def create_objects(status): status.Data_gen=dgen.Data_gen() status.Data_gen.S=status.S status.Data_gen.Comp=status.Comp status.Data_gen.gen_data() def add_node(g,i): node=nd.Node() q=qu.Quadrant(i) p=tplane.tangent_plane() node.objects.append(q) q.objects.append(p) g.add_node(i,node) #status.objects.append(node) #Initializes graph g=gr.Graph() add_node(g,0) k=0 while k<status.dx: add_node(g,k+1) g.add_edges(k,[k+1]) k=k+1 k=0 status.objects=list(g.key2node.values()) node=status.objects[0] sf.safe_update(status.nets,0, nw.Network([status.Data_gen.size[0], status.Data_gen.size[1],2])) p=node_plane(node) #Initializes particles while k<status.n: par=particle() par.position.append(node) par.velocity.append(node) #print(status.Data_gen.size) par.objects.append(status.nets[0]) p.particles.append(par) p.num_particles+=1 k=k+1 #Initializes conectivity radius attach_balls(status,status.r)
def attach_balls(self): for node in self.objects: p = self.node2plane(node) p.ball = gr.spanning_tree(node, n=self.radius) p.distance = tr.tree_distances(p.ball)
def attach_balls(status, n_r): for node in status.objects: q = node.objects[0] p = q.objects[0] p.ball = gr.spanning_tree(node, n=n_r) p.distance = tr.tree_distances(p.ball)
def __init__(self, log_creator: Charge_log): self.Graph = gr.Graph() self.log_creator = log_creator