Beispiel #1
0
def get_neighborhood(center,result,start,end,step,typ,p,conf,alpha):

    for c in conf:
        if c in typ.keys():
            if typ[c] == "exp":
                # New range of values for the conf c
                r = int((end[c] - start[c])*alpha)
                # So that it doesn't go below the already set low limit
                start[c] = utils.roundMultiple(max(math.log(center[c],2)-round(r/2),start[c]),step[c])
                end[c] = utils.roundMultiple(min(math.log(center[c],2)+round(r/2),end[c]),step[c])
        else:
            r = int((end[c] - start[c])*alpha)
            start[c] = utils.roundMultiple(max(center[c]-round(r/2),start[c]),step[c])
            end[c] = utils.roundMultiple(min(center[c]+round(r/2),end[c]),step[c])
    return start,end
Beispiel #2
0
def generate_LHS(result,start,end,step,typ,relations,p,conf,size):
    lhm = lhs(len(conf),samples=size)
    lhs_space = list(dict())
    for i in range(0,len(lhm)):
        sample = lhm[i]
        j =0
        print sample
        #print typ
        for c in conf:
            if c in typ.keys():
                if typ[c] == "boolean":
                # FIXME: This shouldn't be a random choice
                    result[c] =  random.choice([True,False])
                else:
                    result[c] = pow(2,int(start[c] + (end[c] - start[c])*sample[j]))
            else:
                result[c] = utils.roundMultiple(int(start[c] + (end[c] - start[c])*sample[j]), step[c])
            if c in relations:
                for e in relations[c]:
                    result[e] = pow(2,int(math.ceil(math.log(result[c],2))))
                    if result[c]*1.1>result[e]:
                        result[e] = pow(2,int(math.ceil(math.log(result[c],2)))+1)
            j +=1
        lhs_space.append(dict(result))
    return lhs_space
Beispiel #3
0
def put_limits(value, start, end, step):
    if value < start:
        return start
    elif value > end:
        return end
    else:
        return utils.roundMultiple(value, step)
Beispiel #4
0
def generate_initial(result, start, end, step, typ, relations, p, conf):
    cores = int(core_count.get())
    threads = np.random.dirichlet([1000, 1000, 1000, 1000, 1000], 1)
    k = 0
    print conf
    for c in conf:
        if c in typ.keys():
            if typ[c] == "boolean":
                # FIXME: This shouldn't be a random choice
                result[c] = False
            else:
                result[c] = pow(2, int(start[c]))
        else:
            if "component.spout" in c or "topology.acker" in c:
                result[c] = result["topology.workers"]
            elif "component" in c:
                #Max so that it never gets below the min of one executor per bolt per worker
                result[c] = max(
                    result["topology.workers"],
                    roundDownMultiple(
                        (cores - 1 - 3 * int(result["topology.workers"])) *
                        threads[0][k], result["topology.workers"]))
                k += 1
            else:
                result[c] = utils.roundMultiple(int(start[c]), step[c])
        if c in relations:
            for e in relations[c]:
                result[e] = pow(2, int(math.ceil(math.log(result[c], 2))))
                if result[c] * 1.1 > result[e]:
                    result[e] = pow(2,
                                    int(math.ceil(math.log(result[c], 2))) + 1)
    print result
    return result
Beispiel #5
0
def get_pbest(design_space, numbers, conf, metric_values, start, end, step,
              typ, relations):
    vals = dict(list())
    y = dict(list())
    config = dict()
    for c in conf:
        vals[c] = list()
        y[c] = list()
        if c not in typ.keys():
            count = 0
            for i in numbers:
                vals[c].append(design_space[i][c])
                y[c].append(metric_values[count])
                count += 1
        elif typ[c] == "exp":
            count = 0
            for i in numbers:
                vals[c].append(design_space[i][c])
                y[c].append(metric_values[count])
                count += 1

    for c in conf:
        if c not in typ.keys():
            z = numpy.polyfit(vals[c], y[c], 2)
            f = numpy.poly1d(z)
            bounds = [start[c], end[c]]
            crit_points = bounds + [
                x for x in f.deriv().r
                if x.imag == 0 and bounds[0] < x.real < bounds[1]
            ]
            crit_vals = [f(x) for x in crit_points]
            minimum = min(crit_vals)
            config[c] = utils.roundMultiple(
                crit_points[crit_vals.index(minimum)], step[c])
        elif typ[c] == "exp":
            z = numpy.polyfit(vals[c], y[c], 2)
            f = numpy.poly1d(z)
            bounds = [start[c], end[c]]
            crit_points = bounds + [
                x for x in f.deriv().r
                if x.imag == 0 and bounds[0] < x.real < bounds[1]
            ]
            crit_vals = [f(x) for x in crit_points]
            minimum = min(crit_vals)
            config[c] = pow(2, int(crit_points[crit_vals.index(minimum)]))
        if c in relations:
            for e in relations[c]:
                config[e] = pow(2, int(math.ceil(math.log(config[c], 2))))
                if config[c] * 1.1 > config[e]:
                    config[e] = pow(2,
                                    int(math.ceil(math.log(config[c], 2))) + 1)
    return config