コード例 #1
0
    def __addLayer_convex(self, mutation):
        
        graph_dna = Funct.DNA2graph(self.center_key)

        parent_layers = []

        acum_parents = 0
        acum_history = []

        for layer_index in range(self.current_num_layer):
            
            node = graph_dna.key2node.get(layer_index)
            parents = len(node.parents)
            parent_layers.append(parents)
            acum_parents += parents
            acum_history.append(acum_parents)

        factor = random.randint(0, sum(parent_layers))
        selected_index = -1

        for i in range(len(acum_history)):

            if factor <= acum_history[i]:
                selected_index = i
                break
        
        
        direction_accepted = self.verify_direction(layer=selected_index, mutation=self.mutations[mutation])

        if direction_accepted == True:
            self.predicted_actions.append( (selected_index, self.mutations[mutation]) )
コード例 #2
0
def no_con_last_layer(DNA, max=None):
    if DNA:
        g = Fun.DNA2graph(DNA)
        node = g.key2node.get(Fun.num_layers(DNA) - 1)
        if len(node.parents) == 1:
            return DNA
        else:
            return False
コード例 #3
0
def no_con_image(DNA, max=None):
    if DNA:
        g = Fun.DNA2graph(DNA)
        node = g.key2node.get(-1)
        if len(node.kids) == 1:
            return DNA
        else:
            return False
コード例 #4
0
def con_image(DNA, max=None):
    if DNA:
        g = Fun.DNA2graph(DNA)
        condition = all(
            [node_con_image(g, node) for node in list(g.key2node.values())])
        if condition:
            return DNA
        else:
            return None
コード例 #5
0
def max_parents(DNA, max):
    if DNA:
        g = Fun.DNA2graph(DNA)
        if all([
                len(node.parents) < max + 1
                for node in list(g.key2node.values())
        ]):
            return DNA
        else:
            return False
コード例 #6
0
def is_convex(DNA, index):
    g = Fun.DNA2graph(DNA)
    node = g.key2node.get(index)
    output = node.objects[0][1] == max(
        [node.objects[0][2] for node in node.parents])
    return output