コード例 #1
0
ファイル: uni_algo.py プロジェクト: FourquetDavid/evo
def main():
    arguments = sys.argv
    network_name = arguments[1]
    is_directed = arguments[2]
    network_number = arguments[3]
    data_path = arguments[4] #data_path = "../work/files/" + network_number + "-" + network['name'] + "/" + network['name']
    results_path = data_path+"_results.xml"
    stats_path = data_path+'_stats.txt'
    dot_path = data_path+'_trees.jpeg'
    nb_generations = arguments[5]
    freq_stats = arguments[6]


    #evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    extension = ".gexf"
    multiprocessing = False
    dynamic = False



    print network_name
    if is_directed == "True" :
        network_type = "directed_unweighted"
        evaluation_method = "degrees_distances_clustering_importance"
    else :
        network_type = "undirected_unweighted"
        evaluation_method = "communities_degrees_distances_clustering_importance"

    ne.get_datas_from_real_network(data_path,
                           results_path,
                           name=network_name,
                           evaluation_method=evaluation_method,
                           dynamic=dynamic)



    genome = ga.new_genome(
        results_path,
        name=network_name,
        data_path=data_path,
        evaluation_method=evaluation_method,
        dynamic=dynamic,
        tree_type=tree_type,
        network_type=network_type,
        extension=extension
    )

                # optional arguments for evolve :
                # *nb_generations : number of generations of the evolution
                #                   possible values : int > 0 : default : 100
                # *freq_stats : number of generations between two prints of statistics
                #                   possible values : int > 0 : default : 5
                # *stats_path : path to the file where the stats will be printed
                # *multiprocessing : will use or not multiprocessing
                #                possible values : True False


    ga.evolve(genome, stats_path=stats_path, dot_path=dot_path, nb_generations=nb_generations, freq_stats=freq_stats,
        multiprocessing=multiprocessing)
コード例 #2
0
def main():
    arguments = sys.argv
    network_name = "dwt_weighted_network_1977_C"
    is_directed = True
    network_number = "0"
    data_path = "../work/files/" + network_number + "-" + network_name + "/" + network_name
    results_path = data_path + "_results.xml"
    stats_path = data_path + '_stats.txt'
    dot_path = data_path + '_trees.jpeg'
    nb_generations = 40
    freq_stats = 5

    #evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    extension = ".gexf"
    multiprocessing = False
    dynamic = False

    print network_name
    if is_directed == "True":
        network_type = "directed_unweighted"
        evaluation_method = "degrees_distances_clustering_importance"
    else:
        network_type = "undirected_unweighted"
        evaluation_method = "communities_degrees_distances_clustering_importance"

    ne.get_datas_from_real_network(data_path,
                                   results_path,
                                   name=network_name,
                                   evaluation_method=evaluation_method,
                                   dynamic=dynamic)

    genome = ga.new_genome(results_path,
                           name=network_name,
                           data_path=data_path,
                           evaluation_method=evaluation_method,
                           dynamic=dynamic,
                           tree_type=tree_type,
                           network_type=network_type,
                           extension=extension,
                           number_of_nodes=10)

    # optional arguments for evolve :
    # *nb_generations : number of generations of the evolution
    #                   possible values : int > 0 : default : 100
    # *freq_stats : number of generations between two prints of statistics
    #                   possible values : int > 0 : default : 5
    # *stats_path : path to the file where the stats will be printed
    # *multiprocessing : will use or not multiprocessing
    #                possible values : True False

    ga.evolve(genome,
              stats_path=stats_path,
              dot_path=dot_path,
              nb_generations=nb_generations,
              freq_stats=freq_stats,
              multiprocessing=multiprocessing)
コード例 #3
0
ファイル: lgb_training.py プロジェクト: ChristoGH/nb_pl
]

lower_bounds = [.001, 1, 20, 7, 1, .4, .4, 0, 0, 5, 1, 0]
upper_bounds = [.5, 100, 511, 2047, 20, 1, 1, 100, 5, 120, 5, 50]

#%%
pop_size = 75
generations = 8
#%% Genetic Search for Parameters

best_gen_params, best_gen_scores = gen.evolve(
    list_of_types,
    lower_bounds,
    upper_bounds,
    pop_size,
    first_guess,
    generations,
    lgb_x_val_auc,
    mutation_prob=.05,
    mutation_str=.2,
    perc_strangers=.05,
    perc_elites=.1)  #,old_scores=first_guess_scores, save_gens=True)

#%% results

lr, spw, mb, nl, mcw, ss, csbt, alpha, mgts, mdil, rl, bfreq = [
    0.005211914716464551, 11.361502350421855, 126.0, 599.0, 3.6,
    0.9958838042643324, 0.17736474556883752, 71.29010978089583,
    1.4253313277376938, 50.0, 2.7400436617955988, 19.0
]
n_trees = 3390
# 0.7654321225396418
コード例 #4
0
ファイル: net_d.py プロジェクト: paulrt/evo
def main():

    number_of_nodes = int(sys.argv[1])
    name = sys.argv[2]
    resdir = sys.argv[3]
    #network_name = name.replace(".gexf","")
    network_name = name
    data_path = name
    #data_path = "data/"+network_name
    #res_path = "data/"+network_name+"_"+str(number_of_nodes)+"_u"
    
    #if not os.path.isfile(res_path+'_stats.txt'):
    if not os.path.exists(resdir):
        os.mkdir(resdir)
    results_path = resdir + "/result.xml" #sys.argv[3] #res_path+"_results.xml"
    stats_path = resdir + "/stats.txt" #res_path+'_stats.txt'
    dot_path = resdir + "/trees.jpeg"
    nb_generations = 40
    freq_stats = 5


    evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    extension = ".gexf"
    multiprocessing = False
    dynamic = False



    print network_name
    network_type = "directed_unweighted"
    evaluation_method = "degrees_communities_distances_clustering_importance"

    ne.get_datas_from_real_network(data_path,
                              results_path,
                               name=network_name,
                               evaluation_method=evaluation_method,
                               dynamic=dynamic)



    genome = ga.new_genome(
            results_path,
            name=network_name,
            data_path=data_path,
            evaluation_method=evaluation_method,
            dynamic=dynamic,
            tree_type=tree_type,
            network_type=network_type,
            extension=extension,
            number_of_nodes = number_of_nodes
        )

                    # optional arguments for evolve :
                    # *nb_generations : number of generations of the evolution
                    #                   possible values : int > 0 : default : 100
                    # *freq_stats : number of generations between two prints of statistics
                    #                   possible values : int > 0 : default : 5
                    # *stats_path : path to the file where the stats will be printed
                    # *multiprocessing : will use or not multiprocessing
                    #                possible values : True False


    ga.evolve(genome, stats_path=stats_path, dot_path=dot_path, nb_generations=nb_generations, freq_stats=freq_stats,
            multiprocessing=multiprocessing)
コード例 #5
0
def main():

    evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    network_type = "undirected_unweighted"
    network = "karate"
    multiprocessing = False
    dynamic = False
    data_path = '../../data/{}/'.format(network)
    results_path = '../../results/{}/{}.xml'.format(network, evaluation_method)
    stats_path = '../../results/{}/{}_stats.txt'.format(
        network, evaluation_method)
    nb_generations = 11
    freq_stats = 5
    #do not display numpy warnings
    np.seterr('ignore')

    #arguments : path to the real network, path to print datas
    #possible arguments :
    #*evaluation_method : the method used to evaluate the proximity between real network and generated network
    #                        possible values : "(nodes)_(vertices)_(clustering)_(importance)_(communities)_(distances)_(degrees)"
    ne.get_datas_from_real_network(data_path,
                                   results_path,
                                   name=network,
                                   evaluation_method=evaluation_method,
                                   network_type=network_type,
                                   dynamic=dynamic,
                                   extension=".gexf")

    #arguments : path to datas about the real network
    #optional arguments for genome :
    #*max_depth : maximal depth of the decision tree that defines a genome
    #             possible values : int > 0
    #evaluation_method : the method used to evaluate the proximity between real network and generated network
    #                        possible values : "(nodes)_(vertices)_(clustering)_(importance)_(communities)_(distances)_(degrees)"
    #tree_type : the type of the trees used to stores genomes : with or without constants in leaves
    #                        possible values : "with_constants" "simple"
    #network_type : the type of the networks studied and generated : directed or not
    #                possible values : "(un)weighted_(un)directed"
    #dynamic : if the network is dynamic or not

    genome = ga.new_genome(results_path,
                           name=network,
                           data_path=data_path,
                           evaluation_method=evaluation_method,
                           dynamic=dynamic,
                           tree_type=tree_type,
                           network_type=network_type,
                           extension=".gexf")

    #optional arguments for evolve :
    #*nb_generations : number of generations of the evolution
    #                   possible values : int > 0 : default : 100
    #*freq_stats : number of generations between two prints of statistics
    #                   possible values : int > 0 : default : 5
    #*stats_path : path to the file where the stats will be printed
    #*multiprocessing : will use or not multiprocessing
    #                possible values : True False

    ga.evolve(genome,
              stats_path=stats_path,
              nb_generations=nb_generations,
              freq_stats=freq_stats,
              multiprocessing=multiprocessing)
コード例 #6
0
def main():
    #evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    extension = ".gexf"
    multiprocessing = True
    dynamic = False

    nb_generations = 40
    freq_stats = 10
    while (True):
        try:
            with open("../work/done.csv") as csvfile:
                network_dict = csv.DictReader(csvfile, delimiter=";")
                for network in network_dict:
                    if random.random() < 0.05 and int(
                            network['nb_nodes']) < 1000 and not_done(network):
                        network_name = network['name']
                        print network_name
                        if network['is_directed'] == "True":
                            network_type = "directed_unweighted"
                            evaluation_method = "degrees_distances_clustering_importance"
                        else:
                            network_type = "undirected_unweighted"
                            evaluation_method = "communities_degrees_distances_clustering_importance"

                        data_path = "../work/files/" + network[
                            'number'] + "-" + network['name'] + "/" + network[
                                'name']
                        results_path = data_path + "_results.xml"
                        stats_path = data_path + '_stats.txt'
                        dot_path = data_path + '_trees.jpeg'

                        ne.get_datas_from_real_network(
                            data_path,
                            results_path,
                            name=network_name,
                            evaluation_method=evaluation_method,
                            dynamic=dynamic)

                        genome = ga.new_genome(
                            results_path,
                            name=network_name,
                            data_path=data_path,
                            evaluation_method=evaluation_method,
                            dynamic=dynamic,
                            tree_type=tree_type,
                            network_type=network_type,
                            extension=extension)

                        # optional arguments for evolve :
                        # *nb_generations : number of generations of the evolution
                        #                   possible values : int > 0 : default : 100
                        # *freq_stats : number of generations between two prints of statistics
                        #                   possible values : int > 0 : default : 5
                        # *stats_path : path to the file where the stats will be printed
                        # *multiprocessing : will use or not multiprocessing
                        #                possible values : True False

                        ga.evolve(genome,
                                  stats_path=stats_path,
                                  dot_path=dot_path,
                                  nb_generations=nb_generations,
                                  freq_stats=freq_stats,
                                  multiprocessing=multiprocessing)
        except Exception, e:
            print e
コード例 #7
0
ファイル: seastems2.py プロジェクト: paulrt/seastems
def main():
    # arg1 : le nombre de noeuds voulus, permet de raccourcir l'execution lors de tests
    # arg2: data file ".gexf"
    # arg3 : le res directory
    # arg4 : liste des distances ".csv" ou ".gexf"
    # arg 5 : liste des donnees des noeuds ".txt"
    number_of_nodes = int(sys.argv[1])
    name = sys.argv[2]
    network_name = name
    data_path = name
    resdir = sys.argv[3]
    edge_data = None if sys.argv[4] == 'None' else sys.argv[4]
    node_data = None if sys.argv[5] == 'None' else sys.argv[5]
    if not os.path.exists(resdir):
        os.mkdir(resdir)
    results_path = resdir + "/result.xml"
    stats_path = resdir + "/stats.txt"
    dot_path = resdir + "/trees.jpeg"
    nb_generations = 40
    freq_stats = 5

    tree_type = "with_constants"
    extension = ""
    multiprocessing = False
    dynamic = False

    print network_name
    network_type = "undirected_unweighted"
    evaluation_method = "degrees_communities_distances_clustering_importance"

    ne.get_datas_from_real_network(data_path,
                                   results_path,
                                   name=network_name,
                                   evaluation_method=evaluation_method,
                                   dynamic=dynamic)

    genome = ga.new_genome(results_path,
                           name=network_name,
                           data_path=data_path,
                           evaluation_method=evaluation_method,
                           dynamic=dynamic,
                           tree_type=tree_type,
                           network_type=network_type,
                           extension=extension,
                           number_of_nodes=number_of_nodes,
                           edge_data=edge_data,
                           node_data=node_data)

    # optional arguments for evolve :
    # *nb_generations : number of generations of the evolution
    #                   possible values : int > 0 : default : 100
    # *freq_stats : number of generations between two prints of statistics
    #                   possible values : int > 0 : default : 5
    # *stats_path : path to the file where the stats will be printed
    # *multiprocessing : will use or not multiprocessing
    #                possible values : True False

    ga.evolve(genome,
              stats_path=stats_path,
              dot_path=dot_path,
              nb_generations=nb_generations,
              freq_stats=freq_stats,
              multiprocessing=multiprocessing)
コード例 #8
0
def main() :

    evaluation_method ="communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    network_type = "undirected_unweighted"
    network = "karate"
    multiprocessing = False
    dynamic = False
    data_path = '../../data/{}/'.format(network)
    results_path ='../../results/{}/{}.xml'.format(network,evaluation_method)
    stats_path = '../../results/{}/{}_stats.txt'.format(network,evaluation_method)
    nb_generations =11 
    freq_stats =5
    #do not display numpy warnings     
    np.seterr('ignore') 
 
    
#arguments : path to the real network, path to print datas
    #possible arguments : 
#*evaluation_method : the method used to evaluate the proximity between real network and generated network
#                        possible values : "(nodes)_(vertices)_(clustering)_(importance)_(communities)_(distances)_(degrees)"
    ne.get_datas_from_real_network(data_path,
                               results_path,
                               name= network,
                               evaluation_method= evaluation_method,
                               network_type = network_type,
                               dynamic = dynamic,
                               extension = ".gexf")
    
    
#arguments : path to datas about the real network
#optional arguments for genome : 
#*max_depth : maximal depth of the decision tree that defines a genome 
#             possible values : int > 0
#evaluation_method : the method used to evaluate the proximity between real network and generated network
#                        possible values : "(nodes)_(vertices)_(clustering)_(importance)_(communities)_(distances)_(degrees)"
#tree_type : the type of the trees used to stores genomes : with or without constants in leaves
#                        possible values : "with_constants" "simple"
#network_type : the type of the networks studied and generated : directed or not
#                possible values : "(un)weighted_(un)directed"
#dynamic : if the network is dynamic or not
    
    genome = ga.new_genome(
                       results_path,
                       name= network,
                       data_path = data_path,
                       evaluation_method= evaluation_method,
                       dynamic = dynamic,
                       tree_type = tree_type,
                       network_type = network_type,
                       extension = ".gexf"
                       )
    
#optional arguments for evolve :
#*nb_generations : number of generations of the evolution 
#                   possible values : int > 0 : default : 100
#*freq_stats : number of generations between two prints of statistics 
#                   possible values : int > 0 : default : 5
#*stats_path : path to the file where the stats will be printed 
#*multiprocessing : will use or not multiprocessing 
#                possible values : True False
    

    ga.evolve(genome,stats_path = stats_path , nb_generations =nb_generations,freq_stats = freq_stats, multiprocessing = multiprocessing)
コード例 #9
0
    plt.show()


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-np',
                        '--size',
                        type=int,
                        default=100000,
                        help='Size of the initial population.')
    parser.add_argument('-ng', '--generations', type=int, default=20)
    args = parser.parse_args()

    genotypes = generate_population(args.size)
    for i in range(args.generations):
        genotypes = evolve(genotypes, 25, 0.2)
    fitness_dist(genotypes)

    #max_fitness = []
    #generation = []
    #pop_size = []
    #for i in range(6):
    #if(i==0):
    #	size=1000
    #if(i==1):
    #	size=5000
    #if(i==2):
    #	size=10000
    #if(i==3):
    #	size=100000
    #if(i==4):
コード例 #10
0
from random import randint

from mutator import Mutator
from crossover import UniformCrossover
from population import Population
from genetic_algorithm import evolve

mutator = Mutator(2)
reproducer = UniformCrossover()

def replace(population):
    parent_0 = population.select_by_tournament()
    parent_1 = population.select_by_tournament()
    result_of_crossover = reproducer.sexually_reproduce(parent_0, parent_1)
    child = mutator.reproduce_asexually(result_of_crossover)
    population.replace_by_tournament(child)

evolve("Methinks it is like a weasel", replace)
コード例 #11
0
ファイル: many_algo.py プロジェクト: FourquetDavid/evo
def main():
    #evaluation_method = "communities_degrees_distances_clustering_importance"
    tree_type = "with_constants"
    extension = ".gexf"
    multiprocessing = True
    dynamic = False

    nb_generations = 40
    freq_stats = 10
    while(True) :
        try :
            with open("../work/done.csv") as csvfile:
                network_dict = csv.DictReader(csvfile, delimiter=";")
                for network in network_dict:
                    if random.random() < 0.05 and int(network['nb_nodes']) < 1000 and not_done(network)  :
                        network_name = network['name']
                        print network_name
                        if network['is_directed'] == "True" :
                            network_type = "directed_unweighted"
                            evaluation_method = "degrees_distances_clustering_importance"
                        else :
                            network_type = "undirected_unweighted"
                            evaluation_method = "communities_degrees_distances_clustering_importance"

                        data_path = "../work/files/" + network['number'] + "-" + network['name'] + "/" + network['name']
                        results_path = data_path+"_results.xml"
                        stats_path = data_path+'_stats.txt'
                        dot_path = data_path+'_trees.jpeg'





                        ne.get_datas_from_real_network(data_path,
                                               results_path,
                                               name=network_name,
                                               evaluation_method=evaluation_method,
                                               dynamic=dynamic)



                        genome = ga.new_genome(
                            results_path,
                            name=network_name,
                            data_path=data_path,
                            evaluation_method=evaluation_method,
                            dynamic=dynamic,
                            tree_type=tree_type,
                            network_type=network_type,
                            extension=extension
                        )

                # optional arguments for evolve :
                # *nb_generations : number of generations of the evolution
                #                   possible values : int > 0 : default : 100
                # *freq_stats : number of generations between two prints of statistics
                #                   possible values : int > 0 : default : 5
                # *stats_path : path to the file where the stats will be printed
                # *multiprocessing : will use or not multiprocessing
                #                possible values : True False


                        ga.evolve(genome, stats_path=stats_path, dot_path=dot_path, nb_generations=nb_generations, freq_stats=freq_stats,
                            multiprocessing=multiprocessing)
        except Exception, e:
            print e
コード例 #12
0
import recombination
import genetic_algorithm
import objective_function

# Parameters that can be tuned to your liking
input_dir = 'inputs'
output_dir = 'outputs'
desired_chord = 'C_MAJOR'
desired_scale = 'C_MAJOR'
desired_generations = 1
desired_crossover_points = 5
desired_mutations = 10
desired_prob = 50

if __name__ == '__main__':
    file_list = listdir(input_dir)
    init_pop = []
    rand_idxs = random.sample(range(len(file_list)), int(len(file_list) / 2))
    for i in rand_idxs:
        dat = (wavfile.read(input_dir + '/' + file_list[i]))[1]
        if (dat.ndim == 1):
            dat_mono = dat
        else:
            dat_mono = dat.T[0]
        loudest = np.amax(np.abs(dat_mono))
        init_pop.append(np.float32(dat_mono / loudest))
    pop = genetic_algorithm.evolve(init_pop, desired_generations,
                                   desired_chord, desired_scale)
    for i in range(len(pop)):
        wavfile.write(output_dir + '/result_' + str(i) + '.wav', 44100, pop[i])