Example #1
0
def store_best_network(chromosome, nb_tests):
    #bugged and unused, unknown use
    score_max = 0
    for _ in range(nb_tests):
        print chromosome.getParam("results_path")
        number_of_nodes, number_of_edges = ne.get_number_of_nodes_and_edges(
            chromosome.getParam("results_path"))
        net = nd.grow_network(chromosome, number_of_nodes, number_of_edges)
        scores = ne.eval_network(
            net,
            chromosome.getParam("results_path"),
            evaluation_method=chromosome.getParam("evaluation_method"),
            network_type=chromosome.getParam("network_type"),
            name=chromosome.getParam("name"))
        if scores['proximity_aggregated'] > score_max:
            score_max = scores['proximity_aggregated']
            nx.draw(net)
            plt.savefig(
                chromosome.getParam('results_path').replace(".xml", ".png"))
            plt.close()

            print scores
            f = open(chromosome.getParam('results_path'), 'a')
            f.write(str(scores))
            f.close()
Example #2
0
def eval_func_dynamic(chromosome):
    results_path = chromosome.getParam("results_path")
    evaluation_method = chromosome.getParam("evaluation_method")
    data_path = chromosome.getParam("data_path")
    network_type = chromosome.getParam("network_type")
    extension = chromosome.getParam("extension")
    name = chromosome.getParam("name")
    number_of_networks = len([namefile for namefile in os.listdir(data_path) if extension in namefile])

    scores = {}
    # we create a graph that is similar to the initial graph

    initial_network = ne.read_typed_file(data_path + name + "0" + extension)
    net = nd.createGraph(network_type, initial_network)

    for numero in range(number_of_networks - 1):
        nodes_next, edges_next = ne.get_number_of_nodes_and_edges(results_path, numero + 1)
        nodes_now, edges_now = ne.get_number_of_nodes_and_edges(results_path, numero)
        difference_of_size = nodes_next - nodes_now
        difference_of_edge_number = edges_next - edges_now

        # at each step we add nodes and edges to match with graph at next step
        net = nd.grow_network(chromosome, difference_of_size, difference_of_edge_number, net)

        # comparison with the network at next step : returns a dict  : observable-proximity related to the observable
        scores[str(numero + 1)] = ne.eval_network(net,
                                                  results_path, numero + 1,
                                                  evaluation_method=evaluation_method,
                                                  network_type=network_type,
                                                  name=name)

        # we compute a list that contains aggregated proximity at each time step
    scores_aggregated = [scores[str(score)]['proximity_aggregated'] for score in range(1, number_of_networks)]
    return min(scores_aggregated)
Example #3
0
def eval_func_dynamic(chromosome):
    results_path = chromosome.getParam("results_path")
    evaluation_method = chromosome.getParam("evaluation_method")
    data_path = chromosome.getParam("data_path")
    network_type = chromosome.getParam("network_type")
    extension = chromosome.getParam("extension")
    name = chromosome.getParam("name")
    number_of_networks = len([namefile for namefile in os.listdir(data_path) if extension in namefile])

    scores = {}
    # we create a graph that is similar to the initial graph

    initial_network = ne.read_typed_file(data_path + name + "0" + extension)
    net = nd.createGraph(network_type, initial_network)

    for numero in range(number_of_networks - 1):
        nodes_next, edges_next = ne.get_number_of_nodes_and_edges(results_path, numero + 1)
        nodes_now, edges_now = ne.get_number_of_nodes_and_edges(results_path, numero)
        difference_of_size = nodes_next - nodes_now
        difference_of_edge_number = edges_next - edges_now

        # at each step we add nodes and edges to match with graph at next step
        net = nd.grow_network(chromosome, difference_of_size, difference_of_edge_number, net)

        # comparison with the network at next step : returns a dict  : observable-proximity related to the observable
        scores[str(numero + 1)] = ne.eval_network(net,
                                                  results_path, numero + 1,
                                                  evaluation_method=evaluation_method,
                                                  network_type=network_type,
                                                  name=name)

        # we compute a list that contains aggregated proximity at each time step
    scores_aggregated = [scores[str(score)]['proximity_aggregated'] for score in range(1, number_of_networks)]
    return min(scores_aggregated)
def eval_func(chromosome): 
    number_of_nodes,number_of_edges = ne.get_number_of_nodes_and_edges(chromosome.getParam("results_path"))
    net = nd.grow_network(chromosome,number_of_nodes,number_of_edges )
    score = ne.eval_network(net,chromosome.getParam("results_path"),
                            evaluation_method=chromosome.getParam("evaluation_method"),
                            network_type = chromosome.getParam("network_type"),
                            name = chromosome.getParam("name"))
    return score['proximity_aggregated']
Example #5
0
def eval_func(chromosome):
    number_of_nodes, number_of_edges = ne.get_number_of_nodes_and_edges(
        chromosome.getParam("results_path"))
    net = nd.grow_network(chromosome, number_of_nodes, number_of_edges)
    score = ne.eval_network(
        net,
        chromosome.getParam("results_path"),
        evaluation_method=chromosome.getParam("evaluation_method"),
        network_type=chromosome.getParam("network_type"),
        name=chromosome.getParam("name"))
    return score['proximity_aggregated']
Example #6
0
def eval_func(chromosome):
    number_of_nodes, number_of_edges = ne.get_number_of_nodes_and_edges(chromosome.getParam("results_path"),
                                                                        chromosome.getParam('name'))
    static_number = min(number_of_nodes,chromosome.getParam("number_of_nodes"))
    number_of_edges = static_number * number_of_edges / number_of_nodes
    number_of_nodes =static_number

    net = nd.grow_network(chromosome, number_of_nodes, number_of_edges)
    raw_score,details,more_details = ne.eval_network(net, chromosome.getParam("results_path"),
                            evaluation_method=chromosome.getParam("evaluation_method"),
                            network_type=chromosome.getParam("network_type"),
                            name=chromosome.getParam("name"))
    chromosome.scoref = lambda: None
    setattr(chromosome.scoref, 'score', details)
    setattr(chromosome.scoref, 'distributions', more_details)
    return raw_score
def store_best_network(chromosome,nb_tests) :
    #bugged and unused, unknown use
    score_max = 0
    for _ in range(nb_tests) :
        print chromosome.getParam("results_path")
        number_of_nodes,number_of_edges = ne.get_number_of_nodes_and_edges(chromosome.getParam("results_path"))
        net = nd.grow_network(chromosome,number_of_nodes,number_of_edges )
        scores = ne.eval_network(net,chromosome.getParam("results_path"),evaluation_method=chromosome.getParam("evaluation_method"),network_type = chromosome.getParam("network_type"), name = chromosome.getParam("name"))                          
        if scores['proximity_aggregated'] > score_max :
            score_max = scores['proximity_aggregated'] 
            nx.draw(net)
            plt.savefig(chromosome.getParam('results_path').replace(".xml",".png"))
            plt.close()
            
            print scores
            f = open(chromosome.getParam('results_path'), 'a')
            f.write(str(scores))
            f.close()