コード例 #1
0
ファイル: hyper-optimizer.py プロジェクト: jamaltoutouh/dlopt
def objective(args):
    # print( args )
    config = args['config']
    for attr in args:
        if attr != 'config':
            config.set(attr, args[attr])
    print("Evaluate " + str(config))
    cache = ut.FitnessCache()
    optimizer = config.optimizer_class(data_dict,
                                       config,
                                       cache,
                                       seed=args['seed'])
    pop, logbook, hof = optimizer.optimize(args['hof'])
    sol = hof[0]
    print("Fitness " + str(sol.fitness.values))
    tests.append(str(config) + ";" + str(sol.fitness.values))
    return sol.fitness.values[0]
コード例 #2
0
          help='Hall of fame size.'
    )
    parser.add_argument(
          '--config',
          type=str,
          default='config.json',
          help='Experiment configuration file path (json format).'
    )
    
    FLAGS, unparsed = parser.parse_known_args()
    config = ut.Config()
    config.load_from_file(FLAGS.config)
    print(config)
    reader =config.data_reader_class()
    data_dict = reader.load_data( config.data_folder )
    cache = ut.FitnessCache()
    cache.load_from_file(config.cache_file) 
    optimizer = config.optimizer_class(data_dict, config, cache, seed=FLAGS.seed)
    pop, logbook, hof = optimizer.optimize(FLAGS.hof)
    log_df = pd.DataFrame(data=logbook)
    log_df.to_csv(config.results_folder + config.config_name + '-log.csv', sep=';', encoding='utf-8')    
    try:
        with open(config.results_folder + config.config_name + '-sol.csv','w') as f:
            for sol in hof:
                f.write(str(sol) + ';' + str(sol.fitness.values))
                print('sol=' + str(sol) + ';fitness=' + str(sol.fitness.values))
        f.close()
    except IOError:
        print('Unable to store the hall of fame')
    cache.save_to_file(config.cache_file)