Exemple #1
0
for unit in unit_arr[:]:
    savedir = join(recorddir, "optim_cmp", "%s_%s_%d" % (unit[0], unit[1], unit[2]))
    os.makedirs(savedir, exist_ok=True)
    for Optim_str in Optim_arr:
        for triali in range(10):
            t0 = time()
            if Optim_str == "Genetic":
                optim = Genetic(population_size, mutation_rate, mutation_size, kT_multiplier, recorddir,
                            parental_skew=0.5, n_conserve=0)
            elif Optim_str == "CholCMA":
                optim = CholeskyCMAES(recorddir=recorddir, space_dimen=code_length, init_sigma=init_sigma,
                            Aupdate_freq=Aupdate_freq, init_code=initcode) # np.zeros([1, code_length])
            experiment = ExperimentEvolve(unit, max_step=100, optimizer=optim)
            experiment.run()
            fig0 = experiment.visualize_best(show=False)
            fig0.savefig(join(savedir, "%s_BestImgTrial%03d.png" % (Optim_str, triali,)))
            fig = experiment.visualize_trajectory(show=False)
            fig.savefig(join(savedir, "%s_ScoreTrajTrial%03d.png" % (Optim_str, triali,)))
            # fig2 = experiment.visualize_exp(show=False)
            # fig2.savefig(join(savedir, "EvolveTrial%03d.png" % (triali)))
            plt.close('all')
            np.savez(join(savedir, "%s_scores_trial%03d.npz" % (Optim_str, triali)),
                     generations=experiment.generations,
                     scores_all=experiment.scores_all)
            print("Optimization with %s took %.1f s" % (Optim_str, time() - t0))
            # lastgen_max = [experiment.scores_all[experiment.generations == geni].max() for geni in
            #         range(experiment.generations.max() - 10, experiment.generations.max() + 1)]
            # best_scores_col.append(lastgen_max)

Exemple #2
0
                                    rankbasis=True,
                                    sphere_norm=9)
optimizerZH.lr_schedule(
    100, lim=(10, 6),
    mode="lin")  # the space is much tighter than the fc6 space, so step size
# should be tuned for that
experiment = ExperimentEvolve(("alexnet", "fc8", 1),
                              max_step=100,
                              backend="torch",
                              optimizer=optimizerZH,
                              GAN="BigBiGAN",
                              verbose=True)
experiment.run()
experiment.visualize_trajectory(True)
experiment.visualize_exp(True)
experiment.visualize_best(True)
#%%
mode_dict = ["lin", "exp"]  #"inv",


def optim_result(param):
    pop_size = int(param[0, 0])
    select_rate = param[0, 1]
    select_size = int(pop_size * select_rate)
    lr = param[0, 2]
    mu_init = param[0, 3]
    mu_rate = param[0, 4]
    mode = int(param[0, 5])
    sphere_norm = int(param[0, 6])
    n_gen = 3000 // pop_size  # 4000 is the total evaluation budget
    optimizer = ZOHA_Sphere_lr_euclid(120,