Comments (4)
Hey @IrHaque,
I tried to make a more minimal example, but I cannot reproduce your error -- see the snippet below.
Are you sure the function you are optimizing is deterministic?
Assuming that is the case, there could be an issue with our code that my example is too simple to produce. The two major sources of randomness are the GP fitting step and the random sampling step of the acquisition function optimization. You could check that the results produced there are identical.
If you can reduce your example significantly while still retaining the problem, I can also have another look.
import numpy as np
from bayes_opt import BayesianOptimization
import matplotlib.pyplot as plt
from scipy.optimize import NonlinearConstraint
maxs_ = []
for _ in range(10):
def target_function(x, y):
# Gardner is looking for the minimum, but this packages looks for maxima, thus the sign switch
return np.cos(2*x)*np.cos(y) + np.sin(x)
def constraint_function(x, y):
return np.cos(x) * np.cos(y) - np.sin(x) * np.sin(y)
constraint_limit = 0.5
constraint = NonlinearConstraint(constraint_function, -np.inf, constraint_limit)
# Bounded region of parameter space
pbounds = {'x': (0, 6), 'y': (0, 6)}
optimizer = BayesianOptimization(
f=target_function,
constraint=constraint,
pbounds=pbounds,
verbose=0, # verbose = 1 prints only when a maximum is observed, verbose = 0 is silent
random_state=1,
)
optimizer.maximize(
init_points=2,
n_iter=5,
)
maxs_.append(optimizer.max['target'])
print(maxs_)
# Out: [1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493, 1.7926580410885493
from bayesianoptimization.
Thank you for taking your time checking out my issue @till-m.
I have run your code snippet and I do not see the same issue there. I am fairly sure my function is deterministic, though, I will have to double check that again.
I have been since trying locate the problem and reduce it to a more simple reproducible code snippet as you suggested, however, when I ran my code again with a smaller number of iterations and initial points (eg. init_points = 2, n_iter = 2), I now get the following error message:
Traceback (most recent call last):
File "/afs/cern.ch/user/i/ihaque/.local/lib/python3.9/site-packages/bayes_opt/bayesian_optimization.py", line 369, in maximize
x_probe = next(self._queue)
File "/afs/cern.ch/user/i/ihaque/.local/lib/python3.9/site-packages/bayes_opt/bayesian_optimization.py", line 40, in __next__
raise StopIteration("Queue is empty, no more objects to retrieve.")
StopIteration: Queue is empty, no more objects to retrieve.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/afs/cern.ch/user/i/ihaque/scannerS/ScannerS-master/build/sh-bbyy-pheno/testing/AtlasLimitsMax_BayesianOpt/tb.py", line 161, in <module>
optimizer.maximize(
File "/afs/cern.ch/user/i/ihaque/.local/lib/python3.9/site-packages/bayes_opt/bayesian_optimization.py", line 372, in maximize
x_probe = self.suggest(util)
File "/afs/cern.ch/user/i/ihaque/.local/lib/python3.9/site-packages/bayes_opt/bayesian_optimization.py", line 276, in suggest
y_max_params=self._space.params_to_array(self._space.max()['params']))
TypeError: 'NoneType' object is not subscriptable
I will come back to you if I find what is causing the above.
from bayesianoptimization.
I now get the following error message:
Quick guess, but it could be that none of the randomly sampled init_points
are allowed since they don't fulfill the constraints (thus there is no maximum). Could you try raising the init_points
and see if the problem persists?
from bayesianoptimization.
Hi @IrHaque,
I assume the problem has been fixed. I will close this issue, feel free to re-open if needed.
from bayesianoptimization.
Related Issues (20)
- How to specify pbounds when there are no variable names per se HOT 7
- Make n_restarts_optimizer dynamic HOT 2
- pbounds step size HOT 2
- Manually provide observed samples as init points HOT 2
- Pass *args, *kwargs as non-optimized arguments to the cost function HOT 3
- Verbose=2 doesn't work in terminal or bash HOT 1
- 'str object has no attribute reproduce' HOT 5
- add supported python versions badge to readme HOT 1
- NotUniqueError encountered for constrained problems. HOT 4
- [Question] can I use ML model as a black_box function? HOT 2
- How to use specific init_points HOT 3
- Move `static` inside `docsrc` HOT 1
- Problem about ```allow_duplicate_points``` HOT 4
- Experience with 4D or higher parameter spaces HOT 4
- `suggest` does not return the maximum of acquisition function HOT 7
- ```constraint``` and ```allow_duplicate_points``` can't be used at the same time. HOT 1
- Constrained optimization but constraint function is unknown HOT 4
- Visualization HOT 6
- Inclusion of other adquisition functions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bayesianoptimization.