def plot(matriz,
         legends,
         benchmark=None,
         titulo='',
         titulo_x='',
         titulo_y='',
         salvar=False,
         limites=(0, 0),
         dir=''):
    x = [i for i in range(1, len(matriz[0]) + 1)]
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plt.plot(x, matriz[0], '-.o', label=legends[0])
    plt.plot(x, matriz[1], ':x', label=legends[1])
    plt.plot(x, matriz[2], '--', label=legends[2])

    lgd = plt.legend(loc=2, borderaxespad=0., bbox_to_anchor=(1.05, 1))
    plt.title(titulo)
    plt.xlabel(titulo_x)
    plt.ylabel(titulo_y)

    ax.set_ylim(
        Benchmark.info(benchmark)[3][0] + limites[0],
        Benchmark.info(benchmark)[3][0] + limites[1])
    if salvar:
        plt.savefig(dir + titulo + '.pdf')
        plt.savefig(dir + titulo + '.pdf',
                    bbox_extra_artists=(lgd, ),
                    bbox_inches='tight')
    plt.show()
Ejemplo n.º 2
0
 def run_benchmarks(self):
     print "Executing Benchmarks for " + self.target_path
     for bench_name in self.benchmarks:
         bench = Benchmark(self.target_path, self.target_path+"/"+bench_name,
                 self.no_iterations)
         bench.run()
         self.csv.append(bench.get_csv())
 def run_benchmarks(self):
     print "Executing Benchmarks for " + self.target_path
     for bench_name in self.benchmarks:
         bench = Benchmark(self.target_path,
                           self.target_path + "/" + bench_name,
                           self.no_iterations)
         bench.run()
         self.csv.append(bench.get_csv())
def FluidGA(benchmark=Benchmark.rastrigin,
            tam_entradas=24,
            num_entradas=2,
            max_geracoes=250,
            populacao_inicial=100,
            prob_mut=0.2,
            prob_p_flip_bit=0.05,
            prob_p_cruz=0.5,
            tam_torneio=3):

    lim_min, lim_max, pesos, solucoes, str_benchmark = Benchmark.info(
        benchmark)

    creator.create("avaliacao", base.Fitness,
                   weights=pesos)  ##setando objetivo das avaliacoes ###

    creator.create("Individuo", list,
                   fitness=creator.avaliacao)  ##Criando tipo de Individuos

    toolbox = base.Toolbox()  ## Instanciando objeto Toolbox

    toolbox.register(
        "ini_gene", random.randint, 0,
        1)  ## registrando ferramenta para pegar bit ramdomico (0 ou 1)

    tam = tam_entradas * num_entradas

    toolbox.register(
        "individuo", tools.initRepeat, creator.Individuo, toolbox.ini_gene, tam
    )  ## registrando ferramenta para criar individuo com 48 bits apartir da ferramenta "ini_gene"

    toolbox.register(
        "populacao", tools.initRepeat, list, toolbox.individuo
    )  ##registrando ferramenta para criar populacao com base na ferramenta "individuo"

    indiv = Benchmark.Benchmark(
        num_entradas, tam_entradas, lim_min, lim_max,
        benchmark)  ##Instanciando Objeto para Benchmark

    toolbox.register(
        "avaliacao", indiv.fitness
    )  ##registrando ferramenta para avaliar com base na nossa função fitness do Objeto Benchmark

    #toolbox.register("crusar", tools.cxTwoPoint)  ##registrando ferramenta para crusar dois individuos

    #toolbox.register("mutar", tools.mutFlipBit, indpb=prob_p_flip_bit)  ##registrando ferramenta para mutar individuos com chance de mutação de 5%

    toolbox.register(
        "selecionar", tools.selTournament, tournsize=tam_torneio
    )  ##registrando ferramenta para selecionar pais em um torneio.

    toolbox.register(
        "selecao_elitista", tools.selBest
    )  ##registrando ferramenta para selecionar pais de forma totalmente elitista.

    return run_Fluid(toolbox, populacao_inicial, max_geracoes, pesos, solucoes,
                     tam)
Ejemplo n.º 5
0
 def test_benchmark_none1(self):
     input_json = {
         'input_size_in_bytes': {
             'fastq1': 93520,
             'fastq2': 97604,
             'bwa_index': 3364568
         }
     }
     with self.assertRaises(B.AppNameUnavailableException):
         B.benchmark('some_weird_name', input_json, raise_error=True)
def list_benchmark():
    # list
    list_results = list()

    list_results_manager = ResultsManager()
    list_results_manager.collection_name = 'List'
    list_results_manager.number_of_operations = num_of_operations

    for i in range(0, samples):
        print('Progress: ' + str(i) + '/' + str(samples))
        benchmark = Benchmark(ListTest(num_of_operations))
        list_results.append(benchmark.perform_all_tests())

    list_results_manager.save_to_csv(list_results, 'Python_ListTest.csv')
def dict_benchmark():
    # dictionary
    dictionary_results = list()

    dict_results_manager = ResultsManager()
    dict_results_manager.collection_name = 'Dictionary'
    dict_results_manager.number_of_operations = num_of_operations

    for i in range(0, samples):
        print('Progress: ' + str(i) + '/' + str(samples))
        benchmark = Benchmark(DictionaryTest(num_of_operations))
        dictionary_results.append(benchmark.perform_all_tests())

    dict_results_manager.save_to_csv(dictionary_results,
                                     'Python_DictionaryTest.csv')
    def salvar_resultados_teste(self, dir, titulo, melhores, geracoes_finais,
                                Max, Avg, Min, nao_convergidos):
        file = open(dir + '/' + titulo + '.txt', 'w')
        file.write('Resultados do Teste: ' + titulo + '\n')

        file.write('\nAtributos do Teste: \n')
        file.write('    Benchmark = ' + Benchmark.info(self.benchmark)[4] +
                   '\n')
        file.write('    Número de Testes = ' + str(self.num) + '\n')
        file.write('    Número de Testes não convergidos= ' +
                   str(nao_convergidos) + '\n')

        Media, dp, va = media(melhores)
        file.write('\nMelhores Individuos: \n')
        file.write('    ' + str(melhores) + '\n')
        file.write('    Media = ' + str(Media) + '\n')
        file.write('    Desvio Padrão = ' + str(dp) + '\n')
        file.write('    Variância = ' + str(va) + '\n')
        Media, dp, va = media(geracoes_finais)
        file.write('\nGerações Finais: \n')
        file.write('    ' + str(geracoes_finais) + '\n')
        file.write('    Media = ' + str(Media) + '\n')
        file.write('    Desvio Padrão = ' + str(dp) + '\n')
        file.write('    Variância = ' + str(va) + '\n')
        file.close()

        print('Arquivo Salvo em: ' + dir + '/' + titulo + '.txt')
Ejemplo n.º 9
0
 def test_benchmark10(self):
     input_json = {'input_size_in_bytes': {'input_pairs': 1000000000}}
     res = B.benchmark('pairs-patch', input_json)
     print(res)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.micro'
Ejemplo n.º 10
0
 def test_benchmark7(self):
     input_json = {'input_size_in_bytes': {'input_pairsam': 1000000000}}
     res = B.benchmark('pairsam-filter', input_json)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.xlarge'
     print(res)
Ejemplo n.º 11
0
 def test_benchmark6(self):
     input_json = {'input_size_in_bytes': {'input_pairsam': 1000000000}}
     res = B.benchmark('pairsam-markasdup', input_json)
     print(res)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'r4.large'
Ejemplo n.º 12
0
    def classifyData(self, algo=None, saveModel=False):
        bench = Benchmark()
        classifier = None
        prediction = None

        if algo == SVM_SGD:
            classifier = SGDClassifier(n_jobs=-1,
                                       loss='hinge',
                                       penalty='l2',
                                       alpha=1e-5,
                                       n_iter=50,
                                       random_state=42)
            # classifier = self.doSVMwithGridSearch()
        elif algo == NEURAL_NETWORK:
            classifier = sknn.mlp.Classifier(
                layers=[  # Sigmoid, Tanh, Rectifier, Softmax, Linear
                    # sknn.mlp.Layer("Tanh", units=300),
                    (sknn.mlp.Layer("Linear", units=300) for i in range(2)),
                    sknn.mlp.Layer("Softmax"),
                ],
                learning_rate=NN_LEARNING_RATE,
                n_iter=10,
                learning_momentum=.9,
                debug=False,
                regularize=None,  # L1, L2, dropout, and batch normalization.
                learning_rule=
                'sgd'  # sgd, momentum, nesterov, adadelta, adagrad, rmsprop, adam
            )

        elif algo == RANDOM_FOREST:
            classifier = RandomForestClassifier(
                n_estimators=NR_FOREST_ESTIMATORS, n_jobs=-1)

        elif algo == NAIVE_BAYES:
            classifier = MultinomialNB()

        classifier.fit(self.dataset.X_train, self.dataset.Y_train)

        bench.end('Training Data using: ' + algo)

        # save that training model
        if saveModel:
            joblib.dump(classifier,
                        './model/classifier_{}_{}'.format(algo, time.time()),
                        compress=9)
            bench.end('Dumping Classifier Data')

        prediction = classifier.predict(self.dataset.X_test)
        score = classifier.score(self.dataset.X_test, self.dataset.Y_test)
        bench.end('Predicting Data using: ' + algo)

        if algo == NEURAL_NETWORK:
            prediction = [x[0] for x in prediction]

        self.saveResults(prediction, algo, score=score)
Ejemplo n.º 13
0
 def test_benchmark1(self):
     res = B.benchmark('md5',
                       {'input_size_in_bytes': {
                           'input_file': 200000000
                       }})
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.micro'
     print(res)
Ejemplo n.º 14
0
 def test_benchmark_none2(self):
     input_json = {
         'input_size_in_bytes': {
             'fastq1': 93520,
             'fastq2': 97604,
             'bwa_index': 3364568
         }
     }
     res = B.benchmark('some_weird_name', input_json)
     assert res is None
Ejemplo n.º 15
0
def run_solver():
    if len(sys.argv) > 1 and sys.argv[1] and sys.argv[2]:
        assert int(sys.argv[1]) > 0 and int(sys.argv[1]) not in [0, 2, 3]
        assert int(sys.argv[2]) > 1
        b = Benchmark(int(sys.argv[1]), int(sys.argv[2]))
        b.run()
    else:
        n = int(input("Please insert the number of queens: "))
        it = int(input("Please insert the number of iterations: "))
        assert it > 1
        assert n > 0 and n not in [0, 2, 3]
        b = Benchmark(n, it)
        b.run()
Ejemplo n.º 16
0
def run():
    config_exo = {
        'access': 'EXO84e091ac6a22bf8fb7b916f2',
        'secret': '-DU8_52ivubZb0-hdrx788GKtbTjw7r32LUOlFKV_VA'
    }

    config_aws = {'access': '', 'secret': ''}

    provider_exo = Provider(name='exoscale', config=config_exo, region='')
    provider_aws = Provider(name='aws', config=config_aws, region='us-east-1')
    semaphore = threading.BoundedSemaphore(2)

    instance_exo = Instance(provider_exo, 'test', 'Medium',
                            'Linux Ubuntu 18.04 LTS 64-bit')
    instance_aws = Instance(provider_aws, 'COCA-BENCH', 't2.micro',
                            'ami-0a313d6098716f372')

    key = RSA.generate(2048)
    keypair = (key.exportKey('PEM'), key.publickey().exportKey('OpenSSH'))

    benchmark_exo = Benchmark(instance_exo, keypair, semaphore)
    # benchmark_aws = Benchmark(instance_aws, keypair, semaphore)

    print "start tests"
    benchmark_exo.start()
    # benchmark_aws.start()
    print "wait threads"
    benchmark_exo.join()
    # benchmark_aws.join()
    print "end"
Ejemplo n.º 17
0
    def full_experiment(self):
        total_container = self.width * self.height
        for ii in range(5):
            self.reinforce(iterations=5, units=5, instances=200, train=True)
            self.train_and_update_models()

        for ii in range(6, total_container - 5):
            print("Training: Currently training on {} units.".format(ii))
            self.reinforce(iterations=20, units=ii, instances=2000)
            self.buffer.remove_duplicates()
            if ii % 3 == 0:
                data = self.buffer.get_sample(self.buffer.max_size,
                                              remove=True)
                self.policy_net.retrain_model(data)
                self.value_net.retrain_model(data)
                self.buffer.increase_max_size(0.1)
                del data
            else:
                self.train_and_update_models()

        for ii in range(total_container - 5, total_container + 1):
            print("Training: Currently training on {} units.".format(ii))
            self.reinforce(iterations=20, units=ii, instances=2000)
            self.buffer.remove_duplicates()
            data = self.buffer.storage
            self.policy_net.retrain_model(data)
            self.value_net.retrain_model(data)
            self.buffer.increase_max_size(0.1)

        for ii in range(10):
            print("Training with all units. Currently on iteration ",
                  str(ii + 1))
            bm = Benchmark()
            bm.benchmark_caserta()
            self.reinforce(iterations=10,
                           units=self.height * self.width,
                           instances=2000)
            self.buffer.remove_duplicates()
            self.train_and_update_models()
Ejemplo n.º 18
0
def run():
    parser = argparse.ArgumentParser(description='Run benchmarks in all instances defined by the config file')
    parser.add_argument("providers", help='Configuration file describing providers')
    parser.add_argument("instances", help='Configuration file describing instances to create and benchmark')
    parser.add_argument("--nThreads", type=int, help='Number of threads to start')
    parser.add_argument("--keyLength", type=int, default=2048, help='Length of the generated SSH key')
    args = parser.parse_args()

    key = RSA.generate(2048)
    keypair = (key.exportKey('PEM'), key.publickey().exportKey('OpenSSH'))

    pkey_name = "coca-bench.pem"

    os.system("chmod 777 " + pkey_name)
    file1 = open(pkey_name, "w")
    file1.write(keypair[0])
    file1.close()
    os.system("chmod 400 " + pkey_name)

    providers_config = ConfigParser.ConfigParser()
    providers_config.read(args.providers)
    instances_config = ConfigParser.ConfigParser()
    instances_config.read(args.instances)

    nthreads = len(instances_config.sections())
    if args.nThreads is not None:
        nthreads = args.nThreads
    semaphore = threading.BoundedSemaphore(nthreads)

    jobs = list()
    for instance_name in instances_config.sections():
        provider_name = instances_config.get(instance_name, "provider")
        flavor = instances_config.get(instance_name, "flavor")
        image = instances_config.get(instance_name, "image")
        provider_data = dict(providers_config.items(provider_name))
        username = None
        if instances_config.has_option(instance_name, "username"):
            username = instances_config.get(instance_name, "username")
        region = instances_config.get(instance_name, "region")
        provider = Provider(provider_name, region, provider_data)
        instance = Instance(provider, instance_name, flavor, image, username)
        bench = Benchmark(instance, keypair, semaphore)
        jobs.append(bench)

    for job in jobs:
        job.start()

    for job in jobs:
        job.join()

    print("all threads are finished")
Ejemplo n.º 19
0
 def test_benchmark2(self):
     res = B.benchmark(
         'fastqc-0-11-4-1', {
             'input_size_in_bytes': {
                 'input_fastq': 20000000000
             },
             'parameters': {
                 'threads': 2
             }
         })
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.medium'
     print(res)
Ejemplo n.º 20
0
 def test_benchmark4(self):
     res = B.benchmark(
         'pairsam-parse-sort', {
             'input_size_in_bytes': {
                 'bam': 1000000000
             },
             'parameters': {
                 'nThreads': 16
             }
         })
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'c4.8xlarge'
     print(res)
Ejemplo n.º 21
0
 def test_benchmark5(self):
     input_json = {
         'input_size_in_bytes': {
             'input_pairsams': [1000000000, 2000000000, 3000000000]
         },
         'parameters': {
             'nThreads': 32
         }
     }
     res = B.benchmark('pairsam-merge', input_json)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'c4.8xlarge'
     print(res)
Ejemplo n.º 22
0
 def test_benchmark9(self):
     input_json = {
         'input_size_in_bytes': {
             'input_pairs': [1000000000, 2000000000, 3000000000]
         },
         'parameters': {
             'ncores': 16,
             'maxmem': '1900g'
         }
     }
     res = B.benchmark('hi-c-processing-partb', input_json)
     print(res)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'x1.32xlarge'
Ejemplo n.º 23
0
 def test_benchmark11(self):
     input_json = {
         'input_size_in_bytes': {
             'input_cool': 1000000000,
             'input_hic': 2000000000
         },
         'parameters': {
             'ncores': 1
         }
     }
     res = B.benchmark('hi-c-processing-partc', input_json)
     print('hi-c-processing-partc')
     print(res)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'r4.large'
Ejemplo n.º 24
0
 def test_benchmark3(self):
     input_json = {
         'input_size_in_bytes': {
             'fastq1': 93520000,
             'fastq2': 97604000,
             'bwa_index': 3364568000
         },
         'parameters': {
             'nThreads': 4
         }
     }
     res = B.benchmark('bwa-mem', input_json)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.xlarge'
     print(res)
    def classifyData(self, algo=None, saveModel=False):
        bench = Benchmark()
        classifier = None
        prediction = None

        if algo == SVM_SGD:
            classifier = SGDClassifier(n_jobs=-1, loss='hinge', penalty='l2', alpha=1e-5, n_iter=50, random_state=42)
            # classifier = self.doSVMwithGridSearch()
        elif algo == NEURAL_NETWORK:
            classifier = sknn.mlp.Classifier(
                layers=[  # Sigmoid, Tanh, Rectifier, Softmax, Linear
                          # sknn.mlp.Layer("Tanh", units=300),

                          (sknn.mlp.Layer("Linear", units=300) for i in range(2)),
                          sknn.mlp.Layer("Softmax"),
              ],
                learning_rate=NN_LEARNING_RATE,
                n_iter=10,
                learning_momentum=.9,
                debug=False,
                regularize=None,  # L1, L2, dropout, and batch normalization.
                learning_rule='sgd'  # sgd, momentum, nesterov, adadelta, adagrad, rmsprop, adam
            )

        elif algo == RANDOM_FOREST:
            classifier = RandomForestClassifier(n_estimators=NR_FOREST_ESTIMATORS, n_jobs=-1)

        elif algo == NAIVE_BAYES:
            classifier = MultinomialNB()

        classifier.fit(self.dataset.X_train, self.dataset.Y_train)

        bench.end('Training Data using: ' + algo)

        # save that training model
        if saveModel:
            joblib.dump(classifier, './model/classifier_{}_{}'.format(algo, time.time()), compress=9)
            bench.end('Dumping Classifier Data')

        prediction = classifier.predict(self.dataset.X_test)
        score = classifier.score(self.dataset.X_test, self.dataset.Y_test)
        bench.end('Predicting Data using: ' + algo)

        if algo == NEURAL_NETWORK:
            prediction = [x[0] for x in prediction]

        self.saveResults(prediction, algo, score=score)
Ejemplo n.º 26
0
def salvar_resultados(titulo, entrada, GAs, benchmark, dir=''):
    dir = criar_dir(dir + 'Test - ' + titulo)
    file = open(dir + '/' + titulo + '_info' + '.csv', 'w')
    file.write('Resultados do Teste:, ' + titulo + '\n')

    file.write('\nAtributos do Teste: \n')
    file.write('Benchmark ,' + Benchmark.info(benchmark)[4] + '\n')
    file.write('Número de Testes ,' + str(len(entrada[0])) + '\n')

    file.write('\n\nAlgoritimo, Média, Desvio Padrão, Variância\n')
    for i in range(len(entrada)):
        med, desv, var = media(entrada[i])
        file.write(
            str(GAs[i]) + ',' + str(med) + ',' + str(desv) + ',' + str(var) +
            '\n')

    file.close()

    print('Arquivo Salvo em: ' + dir + '/' + titulo + '_info' + '.csv')
Ejemplo n.º 27
0
 def test_benchmark13(self):
     input_json = {
         'input_size_in_bytes': {
             'input_pairs': [1000000000, 2000000000, 3000000000]
         },
         'parameters': {
             'nthreads': 8,
             'maxmem': '32g'
         }
     }
     res = B.benchmark('hi-c-processing-pairs', input_json)
     print('hi-c-processing-pairs')
     print("benchmark13")
     print(res)
     assert 'aws' in res
     assert res['min_CPU'] == 8
     assert int(res['total_mem_in_MB']) == 45776
     assert int(res['total_size_in_GB']) == 97
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 'r4.2xlarge'
Ejemplo n.º 28
0
 def test_benchmark12(self):
     input_json = {
         'input_size_in_bytes': {
             'input_bams': [1000000000, 2000000000],
             'chromsize': 200000
         },
         'parameters': {
             'nthreads_parse_sort': 1,
             'nthreads_merge': 8
         }
     }
     res = B.benchmark('hi-c-processing-bam', input_json)
     print('hi-c-processing-bam')
     print("benchmark12")
     print(res)
     assert 'aws' in res
     assert 'recommended_instance_type' in res['aws']
     assert res['aws']['recommended_instance_type'] == 't2.2xlarge'
     assert res['min_CPU'] == 8
     assert int(res['total_size_in_GB']) == 55
Ejemplo n.º 29
0
__author__ = 'Raphael'

SGD_CLASSIFIER_LOSS_OPTIONS = (
    'hinge',
    'log',
    'modified_huber',
    'squared_hinge',
    'perceptron',
)

# REVIEW_DATA = './data/Season-1.csv'
REVIEW_DATA = './data/All-seasons.csv'

if __name__ == '__main__':
    bench = Benchmark()

    textAnalzyer = TextAnalyzer(REVIEW_DATA)
    bench.end('Initializing')

    textAnalzyer.createDataFrame(nameFilter=[
        'Kyle', 'Stan', 'Kenny', 'Cartman', 'Butters', 'Jimmy', 'Timmy'
    ])
    bench.end('Reading CSV')

    textAnalzyer.cleanData()
    bench.end('Cleaning Data')

    textAnalzyer.splitData()
    bench.end('Generating Test and Training Data')
Ejemplo n.º 30
0
message = 'Please insert a name-prefix for all stated vms (default is "TEST"): '
vm_name = raw_input(message+"\n:-> ").strip()
vm_name = vm_name.strip()
if vm_name == "": vm_name = "TEST"

message = 'Please insert a wait-time between the vm startups (default is 5.0 [sec]): '
wait_time = raw_input(message+"\n:-> ").strip()
if wait_time == "":
    wait_time = 0.0
else:
    wait_time = float(wait_time)



B1 = Benchmark()
B1.debug = False

B1.vm_amount = vm_amount
B1.flavor = flavor
B1.vm_name = vm_name
B1.wait_time = wait_time
B1.setImageId(image_id)
B1.startVMs()


image_ids = B1.getImageIds()
print "\nFor deletion of the started vms, use the these commands (copy/paste):\n"   
for id in image_ids:
    print "nova delete "+id 
Ejemplo n.º 31
0
    # generate_images.create_runtime_num_test(data_name, num_test_list, run_time_results)


if len(sys.argv) != 3:
    print("Needs 2 arguments:\n"
          "arg 1 - chrom_sizes_file\n"
          "arg 2 - bigWig file")
    exit(-1)

chrom_name = 'chr1'

start_time = time.time()
bedGraph = BedGraph(sys.argv[1], sys.argv[2], chrom_name)
print("Time for loading bedGraph file: ", time.time() - start_time)

start_time = time.time()
print(f"Time for loading {chrom_name}: ", time.time() - start_time, '\n')

bench = Benchmark(bedGraph, sys.argv[2])

data_name = Path(sys.argv[2]).stem
if not os.path.isdir(f'graphs'):
    os.mkdir(f'graphs')
if not os.path.isdir(f'graphs/{data_name}'):
    os.mkdir(f'graphs/{data_name}')

# runtime_benchmark()
interval_size_error_benchmark()
# interval_size_runtime_benchmark()
from sklearn.pipeline import Pipeline

from Benchmark import Benchmark
from TextAnalyzer import TextAnalyzer

__author__ = 'Raphael'


SGD_CLASSIFIER_LOSS_OPTIONS = ('hinge', 'log', 'modified_huber', 'squared_hinge', 'perceptron',)


# REVIEW_DATA = './data/Season-1.csv'
REVIEW_DATA = './data/All-seasons.csv'

if __name__ == '__main__':
    bench = Benchmark()

    textAnalzyer = TextAnalyzer(REVIEW_DATA)
    bench.end('Initializing')

    textAnalzyer.createDataFrame(nameFilter=['Kyle', 'Stan', 'Kenny', 'Cartman', 'Butters', 'Jimmy',
                                             'Timmy'])
    bench.end('Reading CSV')

    textAnalzyer.cleanData()
    bench.end('Cleaning Data')

    textAnalzyer.splitData()
    bench.end('Generating Test and Training Data')

    textAnalzyer.determineBestParams()
    def teste(self):
        melhores = []
        geracoes_finais = []
        nao_convergidos = 0
        for i in range(self.num):
            print('Fazendo Teste Número ({})'.format(i))
            if (self.algoritmo == TrangenicGA.trangenicGA):
                melhor, geracao_f, Max, Avg, Min = self.algoritmo(
                    self.benchmark, self.tam_entradas, self.num_entradas,
                    self.max_geracoes, self.populacao_inicial, self.prob_mut,
                    self.prob_p_flip_bit, self.prob_p_cruz, self.tam_torneio,
                    self.fator_aprox_histo)
                melhores.append(melhor)
                geracoes_finais.append(geracao_f)
                if geracao_f == self.max_geracoes:
                    nao_convergidos = nao_convergidos + 1
                titulo, eixo_x_M, eixo_y_M, eixo_x_G, eixo_y_G = 'Transgenic GA with ' + Benchmark.info(
                    self.benchmark
                )[4], 'Number of the Test', 'Evaluation of the Best Individual', 'Number of the Test', 'Final Generation'
            elif self.algoritmo == Theory_Of_ChaosGA.chaosGA:
                melhor, geracao_f, Max, Avg, Min = self.algoritmo(
                    self.benchmark, self.tam_entradas, self.num_entradas,
                    self.max_geracoes, self.populacao_inicial, self.prob_mut,
                    self.prob_p_flip_bit, self.tam_torneio)
                melhores.append(melhor)
                geracoes_finais.append(geracao_f)
                if geracao_f == self.max_geracoes:
                    nao_convergidos = nao_convergidos + 1
                titulo, eixo_x_M, eixo_y_M, eixo_x_G, eixo_y_G = 'Theory of Chaos GA with ' + Benchmark.info(
                    self.benchmark
                )[4], 'Number of the Test', 'Evaluation of the Best Individual', 'Number of the Test', 'Final Generation'
            elif self.algoritmo == GABasico.GAbasico:

                melhor, geracao_f, Max, Avg, Min = self.algoritmo(
                    self.benchmark, self.tam_entradas, self.num_entradas,
                    self.max_geracoes, self.populacao_inicial, self.prob_mut,
                    self.prob_p_flip_bit, self.prob_p_cruz, self.tam_torneio)
                melhores.append(melhor)
                geracoes_finais.append(geracao_f)
                if geracao_f == self.max_geracoes:
                    nao_convergidos = nao_convergidos + 1
                titulo, eixo_x_M, eixo_y_M, eixo_x_G, eixo_y_G = 'Basic GA with ' + Benchmark.info(
                    self.benchmark
                )[4], 'Number of the Test', 'Evaluation of the Best Individual', 'Number of the Test', 'Final Generation'
            elif self.algoritmo == HomogeneousGA.homogeneousGA:
                melhor, geracao_f, Max, Avg, Min = self.algoritmo(
                    self.benchmark, self.tam_entradas, self.num_entradas,
                    self.max_geracoes, self.populacao_inicial, self.prob_mut,
                    self.prob_p_flip_bit, self.prob_p_cruz, self.tam_torneio,
                    self.fator_aprox_histo)
                melhores.append(melhor)
                geracoes_finais.append(geracao_f)
                if geracao_f == self.max_geracoes:
                    nao_convergidos = nao_convergidos + 1
                titulo, eixo_x_M, eixo_y_M, eixo_x_G, eixo_y_G = 'Transgenic GA with ' + Benchmark.info(
                    self.benchmark
                )[4], 'Number of the Test', 'Evaluation of the Best Individual', 'Number of the Test', 'Final Generation'
            elif self.algoritmo == FluidGA.FluidGA:
                melhor, geracao_f, Max, Avg, Min = self.algoritmo(
                    self.benchmark, self.tam_entradas, self.num_entradas,
                    self.max_geracoes, self.populacao_inicial, self.prob_mut,
                    self.prob_p_flip_bit, self.prob_p_cruz, self.tam_torneio)
                melhores.append(melhor)
                geracoes_finais.append(geracao_f)
                if geracao_f == self.max_geracoes:
                    nao_convergidos = nao_convergidos + 1
                titulo, eixo_x_M, eixo_y_M, eixo_x_G, eixo_y_G = 'Basic GA with ' + Benchmark.info(
                    self.benchmark
                )[4], 'Number of the Test', 'Evaluation of the Best Individual', 'Number of the Test', 'Final Generation'
        dir = 'Test - ' + titulo
        if self.salvar:
            dir = criar_dir(dir)
            self.salvar_resultados_teste(dir, titulo, melhores,
                                         geracoes_finais, Max, Avg, Min,
                                         nao_convergidos)
        self.plot(melhores, "Best Individuals - " + titulo, eixo_x_M, eixo_y_M,
                  self.salvar, dir)
        self.plot(geracoes_finais, "Final Generations - " + titulo, eixo_x_G,
                  eixo_y_G, self.salvar, dir)
        return melhores, geracoes_finais, nao_convergidos
            }
        )

        output.to_csv("./results/{}.csv".format(classifierName), index=False)
        logger.info('Accuracy: {} %'.format(round(kwargs['score'] * 100, 3)))

    def optimizeParams(self):
        self.params = {
            'vect__ngram_range': [(1, 1), (1, 2)],
            'tfidf__use_idf': (True, False),
            'clf__alpha': (1e-1, 1e-2, 1e-3),
        }


if __name__ == '__main__':
    bench = Benchmark()

    anal = TextAnalyzer(REVIEW_DATA)
    bench.end('Initializing')

    anal.createDataFrame(nameFilter=['Kyle', 'Stan', 'Kenny', 'Cartman', 'Butters', 'Jimmy',
                                     'Timmy'])
    bench.end('Reading CSV')

    anal.cleanData()  # Prepare data in a format that is good for scikitlearn
    bench.end('Cleaning Data')

    anal.vectorizeData(scheme='bagofwords')
    bench.end('Generating Bag of Words Representation')

    anal.genTfIdf()  #
Ejemplo n.º 35
0
import Initializer, Mutator, Recombiner, Selector, Replacer, Terminator, LocalSearcher
from GeneticAlgorithm import GeneticAlgorithm
from ProblemDefinition import ProblemDefinition
from Benchmark import Benchmark

# Choose your operators
initializer = Initializer.RandomInitializer()
mutator = Mutator.RandomMutator(0.2, dynAdapt=True)
recombiner = Recombiner.CrossoverRecombiner()
selector = Selector.TournamentSelector(s=20, dynAdapt=True)
replacer = Replacer.bottomReplacer()
terminator = Terminator.maxRuntimeTerminator(10)
# Add a local searcher if you want LocalSearcher.Idle() does nothing
localSearcher = LocalSearcher.Idle()

# Set up an example problem
nrMachines, jobRuntimes = Benchmark.benchmark1()
probDef = ProblemDefinition(nrMachines, jobRuntimes)

# Set up GA parameters
popSize = 100
nrOffspring = int(popSize / 10)

# Create Genetic Algorithm instance
GA = GeneticAlgorithm(initializer, selector, recombiner, mutator, replacer,
                      terminator, probDef, popSize, nrOffspring, localSearcher)
bestIndividual, results = GA.run()
print("best Individuals fitness: ", bestIndividual.fitness)