Exemplo n.º 1
0
def get_next_memory_windows(trace_file, cache_type, cache_size, n_early_stop,
                            seq_start, parameters, args_global):
    # use 80% warmup, manually check for unimodal behavior
    n_warmup = int(0.8 * n_early_stop)
    # per cache size parameters overwrite other parameters
    df = database.load_reports(
        trace_file=trace_file,
        cache_type=cache_type,
        cache_size=str(cache_size),
        seq_start=str(seq_start),
        n_early_stop=str(n_early_stop),
        n_warmup=n_warmup,
        version=parameters['version'],  # use version as a strong key
        dburi=parameters["dburi"],
        dbcollection=parameters["dbcollection"],
    )
    if len(df) == 0:
        next_windows = np.linspace(1,
                                   int(0.4 * n_early_stop),
                                   args_global['n_beam'] + 1,
                                   dtype=int)[1:]
    else:
        # window at most 40% of length
        parameter_space = ParameterSpace(
            [ContinuousParameter('x', 1, int(0.4 * n_early_stop))])
        bo = GPBayesianOptimization(
            variables_list=parameter_space.parameters,
            X=df['memory_window'].values.reshape(-1, 1),
            Y=df['byte_miss_ratio'].values.reshape(-1, 1),
            batch_size=args_global['n_beam'])
        next_windows = bo.suggest_new_locations().reshape(-1).astype(int)
    return next_windows
Exemplo n.º 2
0
def get_validation_tasks_per_cache_size(trace_file, cache_type, cache_size, parameters, args_global, df):
    n_req = parameters['n_req']
    n_validation = int(n_req * args_global['ratio_validation'])
    n_iteration = args_global['n_iteration']
    n_beam = args_global['n_beam']
    if len(df) == 0 or len(df[df['cache_size'] == cache_size]) == 0:
        # init value
        next_windows = np.linspace(1, int(0.4 * n_validation), args_global['n_beam'] + 1, dtype=int)[1:]
        tasks = []
        for memory_window in next_windows:
            # override n_early stop
            task = _get_task(trace_file, cache_type, cache_size, parameters, n_validation, memory_window)
            tasks.append(task)
        return tasks

    # as emukit output is random, don't assume same points each time, as long as # point is enough
    df1 = df[df['cache_size'] == cache_size]
    if len(df1) >= n_iteration * n_beam:
        return []
    # next round
    # window at most 40% of length
    # add xs, ys in a consistent order otherwise the results will be difference
    parameter_space = ParameterSpace([ContinuousParameter('x', 1, int(0.4 * n_validation))])
    bo = GPBayesianOptimization(variables_list=parameter_space.parameters,
                                X=df1['memory_window'].values.reshape(-1, 1),
                                Y=df1['byte_miss_ratio'].values.reshape(-1, 1),
                                batch_size=args_global['n_beam'])
    next_windows = bo.suggest_new_locations().reshape(-1).astype(int)
    tasks = []
    for memory_window in next_windows:
        task = _get_task(trace_file, cache_type, cache_size, parameters, n_validation, memory_window)
        tasks.append(task)
    return tasks
def test_loop():
    n_iterations = 5

    x_init = np.random.rand(5, 1)
    y_init = np.random.rand(5, 1)
    x = ContinuousParameter('x', 0, 1)
    bo = GPBayesianOptimization(variables_list=[x], X=x_init, Y=y_init)
    bo.run_optimization(f, n_iterations)

    # Check we got the correct number of points
    assert bo.loop_state.X.shape[0] == n_iterations + 5