コード例 #1
0
    def test_performance(self):
        ackley_noise_func = ackley_noise_creator(0, 0.1)
        dim_size = 100  # dimensions
        one_dim = (ValueType.CONTINUOUS, [-1, 1], 1e-6)
        dim_list = [(one_dim)] * dim_size
        dim = Dimension2(dim_list)  # form up the dimension object
        objective = Objective(ackley_noise_func,
                              dim)  # form up the objective function
        budget = 20000  # 20*dim_size  # number of calls to the objective function
        # suppression=True means optimize with value suppression, which is a noise handling method
        # resampling=True means optimize with re-sampling, which is another common used noise handling method
        # non_update_allowed=500 and resample_times=100 means if the best solution doesn't change for 500 budgets,
        # the best solution will be evaluated repeatedly for 100 times
        # balance_rate is a parameter for exponential weight average of several evaluations of one sample.
        parameter = Parameter(budget=budget,
                              noise_handling=True,
                              suppression=True,
                              non_update_allowed=200,
                              resample_times=50,
                              balance_rate=0.5)

        # parameter = Parameter(budget=budget, noise_handling=True, resampling=True, resample_times=10)
        parameter.set_positive_size(5)

        sol = Opt.min(objective, parameter)
        assert sol.get_value() < 4
コード例 #2
0
def minimize_ackley_continuous_noisy():
    """
    SSRacos example of minimizing ackley function under Gaussian noise

    :return: no return value
    """
    ackley_noise_func = ackley_noise_creator(0, 0.1)
    dim_size = 100  # dimensions
    dim_regs = [[-1, 1]] * dim_size  # dimension range
    dim_tys = [True] * dim_size  # dimension type : real
    dim = Dimension(dim_size, dim_regs,
                    dim_tys)  # form up the dimension object
    objective = Objective(ackley_noise_func,
                          dim)  # form up the objective function
    budget = 200000  # 20*dim_size  # number of calls to the objective function
    # suppression=True means optimize with value suppression, which is a noise handling method
    # resampling=True means optimize with re-sampling, which is another common used noise handling method
    # non_update_allowed=500 and resample_times=100 means if the best solution doesn't change for 500 budgets,
    # the best solution will be evaluated repeatedly for 100 times
    # balance_rate is a parameter for exponential weight average of several evaluations of one sample.
    parameter = Parameter(budget=budget,
                          noise_handling=True,
                          suppression=True,
                          non_update_allowed=500,
                          resample_times=100,
                          balance_rate=0.5)

    # parameter = Parameter(budget=budget, noise_handling=True, resampling=True, resample_times=10)
    parameter.set_positive_size(5)

    ExpOpt.min(objective,
               parameter,
               repeat=2,
               plot=True,
               plot_file="img/ackley_continuous_noisy_figure.png")
コード例 #3
0
ファイル: test_seed.py プロジェクト: xynmxy/ZOOpt
    def test_noisy(self):
        ackley_noise_func = ackley_noise_creator(0, 0.1)
        dim_size = 100  # dimensions
        dim_regs = [[-1, 1]] * dim_size  # dimension range
        dim_tys = [True] * dim_size  # dimension type : real
        dim = Dimension(dim_size, dim_regs, dim_tys)  # form up the dimension object
        objective = Objective(ackley_noise_func, dim)  # form up the objective function
        budget = 20000  # 20*dim_size  # number of calls to the objective function
        parameter = Parameter(budget=budget, noise_handling=True, suppression=True, non_update_allowed=200,
                              resample_times=50, balance_rate=0.5, seed=1)

        # parameter = Parameter(budget=budget, noise_handling=True, resampling=True, resample_times=10)
        parameter.set_positive_size(5)
        sol1 = Opt.min(objective, parameter)
        sol2 = Opt.min(objective, parameter)
        assert sol1.get_value() == sol2.get_value()
コード例 #4
0
ファイル: discrete_opt.py プロジェクト: xynmxy/ZOOpt
def minimize_setcover_discrete():
    """
    Discrete optimization example of minimizing setcover problem.

    :return: no return value
    """
    problem = SetCover()
    dim = problem.dim  # the dim is prepared by the class
    objective = Objective(problem.fx, dim)  # form up the objective function
    budget = 100 * dim.get_size()  # number of calls to the objective function
    # if autoset is False, you should define train_size, positive_size, negative_size on your own
    parameter = Parameter(budget=budget, autoset=False)
    parameter.set_train_size(6)
    parameter.set_positive_size(1)
    parameter.set_negative_size(5)

    ExpOpt.min(objective,
               parameter,
               repeat=10,
               best_n=5,
               plot=True,
               plot_file="img/setcover_discrete_figure.png")
コード例 #5
0
    for i in range(repeat):
        for j in range(len(budget_list)):
            dim = Dimension(dim_size, [dim_regs] * dim_size, [True] * dim_size)
            objective = Objective(lambda sol: noisy_function_dict[obj_name]
                                  (sol.get_x()),
                                  dim)  # form the objective function
            if args.noise_handling:
                parameter = Parameter(budget=budget_list[j],
                                      noise_handling=True,
                                      suppression=True,
                                      non_update_allowed=100,
                                      resample_times=20,
                                      balance_rate=0.5)
            else:
                parameter = Parameter(budget=budget,
                                      intermediate_result=True,
                                      intermediate_freq=1000)
            parameter.set_positive_size(5)
            sol = Opt.min(objective, parameter)
            real_value[i][j] = base_function_dict[args.objective](sol.get_x())
    log_address = os.path.join(project_dir, 'ZOOpt_exp/log/noisy/')
    if args.noise_handling is True:
        file_name = os.path.join(log_address,
                                 '{}_nh_{}.txt'.format(obj_name, dim_size))
    else:
        file_name = os.path.join(log_address,
                                 '{}_{}.txt'.format(obj_name, dim_size))
    os.makedirs(log_address, exist_ok=True)
    np.savetxt(file_name, np.array(real_value))
    print(real_value.shape)