Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Optimization space and initial points in x0 use inconsistent dimensions. #1178

Open
annelize-vn opened this issue Aug 17, 2023 · 0 comments
Open

Comments

@annelize-vn
Copy link

annelize-vn commented Aug 17, 2023

I have a simple example of using skopt:

from skopt import gp_minimize
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel, RBF

# Define your observed data (replace with your own data)
observed_X = np.array([0.5, 1.5, 2.0])
observed_y = np.array([2.0, 1.0, 0.5])

# Reshape the observed_X to have shape (n_samples, n_features)
observed_X = observed_X.reshape(-1, 1)

# Define the surrogate model
kernel = ConstantKernel(1.0, constant_value_bounds="fixed") * RBF(length_scale=1.0, length_scale_bounds="fixed")
surrogate_model = GaussianProcessRegressor(kernel=kernel)

# Define the optimization function using the surrogate model's prediction
def optimization_function(x):
    return surrogate_model.predict(np.array([[x]]))

# Perform Bayesian optimization using Gaussian Process with observed data
result = gp_minimize(optimization_function,
                     dimensions=[(0., 5.0)],
                     n_calls=20,
                     n_random_starts=5,
                     x0=observed_X,
                     y0=observed_y)

but when I run it I get the error:

RuntimeError: Optimization space (Space([Real(low=0.0, high=5.0, prior='uniform', transform='normalize')])) and initial points in x0 use inconsistent dimensions.

I am using the following versions in a conda enviroment:

scikit-learn 1.0.2
scikit-optimize 0.9.0
scipy 1.8.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant