GithubHelp home page GithubHelp logo

Comments (4)

till-m avatar till-m commented on June 18, 2024 1

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.

IrHaque avatar IrHaque commented on June 18, 2024

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.

till-m avatar till-m commented on June 18, 2024

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.

till-m avatar till-m commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.