示例#1
0
def get_fitted_gaussian_processor(X_train,
                                  y_train,
                                  constraint_upper,
                                  standardize_y=True,
                                  **gp_params):
    # Initialize gaussian process regressor
    gp = GaussianProcessRegressor()
    gp.set_params(**gp_params)
    logger.debug('Instantiated gaussian processor for objective function:\n' +
                 f'{gp}')
    logger.debug(f"Fitting gaussian processor")

    if standardize_y:
        if constraint_upper is not None:
            y_train = scale(np.hstack((y_train, constraint_upper)))
            scaled_constraint_upper = y_train[-1]
            y_train = y_train[:-1]
        else:
            y_train = scale([i for i in y_train])
            scaled_constraint_upper = None
        gp.constraint_upper = scaled_constraint_upper
    else:
        gp.constraint_upper = constraint_upper

    logger.debug(f'X_train:\n{X_train}')
    logger.debug(f'y_train\n{y_train}')
    logger.debug(f'constraint_upper: {gp.constraint_upper}')
    if gp_params is None or gp_params.get('alpha') is None:
        # Find unique rows of X to avoid GP from breaking
        ur = unique_rows(X_train)
        gp.fit(X_train[ur], y_train[ur])
    else:
        gp.fit(X_train, y_train)
    return gp