示例#1
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 = 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)

    ExpOpt.min(objective,
               parameter,
               repeat=5,
               plot=False,
               plot_file="img/ackley_continuous_noisy_figure.png")
    def test_resample(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
        # 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, resampling=True, resample_times=10)

        # 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
示例#3
0
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")