def __init__(self, dim): self.__Pop = [] # population set self.__PosPop = [] # positive sample set self.__Optimal = [] # the best sample so far self.__NextPop = [] # the next population set self.__region = [] # the region of model self.__label = [] # the random label, if true random in this dimension self.__SampleSize = 0 # the instance number of sampling in an iteration self.__MaxIteration = 0 # the number of iterations self.__Budget = 0 # budget of evaluation self.__PositiveNum = 0 # the set size of PosPop self.__RandProbability = 0 # the probability of sample in model self.__UncertainBits = 0 # the dimension size that is sampled randomly self.__OnlineSwitch = False self.__dimension = dim for i in range(dim.getSize()): reg = [] reg.append(0) reg.append(0) self.__region.append(reg) self.__label.append(True) self.__ro = RandomOperator() return
def __init__(self, dimension): self.__pop = [] # population set self.__pos_pop = [] # positive sample set self.__optimal = None # the best sample so far self.__region = [] # the region of model self.__label = [] # the random label, if true random in this dimension self.__sample_size = 0 # the instance size of sampling in an iteration self.__budget = 0 # budget of evaluation self.__positive_num = 0 # positive sample set size self.__rand_probability = 0.0 # the probability of sampling in model self.__uncertain_bit = 0 # the dimension size of sampling randomly self.__dimension = dimension # sampling saving self.__model_ins = [] # positive sample used to modeling self.__negative_set = [] # negative set used to modeling self.__new_ins = [] # new sample self.__sample_label = [] # the label of each sample for i in range(self.__dimension.get_size()): region = [0.0, 0.0] self.__region.append(region) self.__label.append(0) self.__ro = RandomOperator() return
def __init__(self, dim=None, bias_region=[-0.2, 0.2]): ro = RandomOperator() self.__dimension = dim # generate bias randomly self.__bias = [] for i in range(self.__dimension.get_size()): # self.__bias.append(ro.getUniformDouble(self.__dimension.getRegion(i)[0], self.__dimension.getRegion(i)[1])) self.__bias.append( ro.get_uniform_double(bias_region[0], bias_region[1])) # print 'bias:', self.__bias return
from ObjectiveFunction import DistributedFunction from Components import Dimension from Tools import RandomOperator import numpy as np dimension_size = 10 dimension = Dimension() dimension.set_dimension_size(dimension_size) dimension.set_regions([[-0.5, 0.5] for _ in range(dimension_size)], [0 for _ in range(dimension_size)]) func = DistributedFunction(dimension, bias_region=[-0.5, 0.5]) target_bias = [0.25 for _ in range(dimension_size)] func.setBias(target_bias) ro = RandomOperator() prob_fct = func.DisRosenbrock x0 = [ro.get_uniform_double(-0.5, 0.5) for _ in range(dimension_size)] ans = [] for i in range(10): x, cost, _ = fmin_smac(func=prob_fct, x0=x0, bounds=[[-0.5, 0.5] for _ in range(dimension_size)], maxfun=50, rng=3) ans.append(x) # print("Optimum at {} with cost of {}".format(x, cost)) print(np.mean(ans)) print(np.std(ans))