Skip to content

Encounter an error when using Intparameters #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chiang-hsuan opened this issue Jan 23, 2025 · 2 comments
Closed

Encounter an error when using Intparameters #543

chiang-hsuan opened this issue Jan 23, 2025 · 2 comments

Comments

@chiang-hsuan
Copy link

chiang-hsuan commented Jan 23, 2025

I met a ValueError:

setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (4,) + inhomogeneous part.

happens here in the package
self._bounds: NDArray[Float] = np.array( [item[1] for item in sorted(pbounds.items(), key=lambda x: x[0])], dtype=float

When I am testing to optimize hyperparameter with the code

define the optimizer

hyper_optimizer = BayesianOptimization(
f=clf,
pbounds=hyperparameter_grid,
acquisition_function=acquisition.ExpectedImprovement(xi=1e-2, random_state=1),
random_state=1,
)

hyper_optimizer.maximize(
init_points=3,
n_iter=50,
)

define a search space

hyperparameter_grid = {
'hidden_size': [16,32,int],
'batch_size' : [32,256,int],
'lr' : [0.001,0.0001],
'epochs' : [10,50,int]
}

Not sure if there's function in the package to set it, but what I retraced and found the possible reason is when including int, the array become inhomogeneous shape and cannot be set as a np.array. Alternatively set float to object works in my code. Or is there any other way which can simply solve the error?

@till-m
Copy link
Member

till-m commented Jan 23, 2025

Hi @chiang-hsuan,

what version of the package are you using? I think you're not on the pre-release that features the int optimization because, as far as I can tell, the line you're referring to is not present in that version.

@till-m
Copy link
Member

till-m commented Feb 4, 2025

I assume the problem is fixed. Feel free to re-open if you encounter it again.

@till-m till-m closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants