Skip to content

Values outside pbounds #443

Closed
Closed

Description

@vanessastadAIT

Describe the bug
The optimizer tries values that are outside my pbounds. In particular, it happens for the pitch variable. It happens few iterations. I check the definition of pbounds but it seems correct to me .

To Reproduce
A concise, self-contained code snippet that reproduces the bug you would like to report.

from bayes_opt import SequentialDomainReductionTransformer
from bayes_opt import BayesianOptimization
from bayes_opt.util import UtilityFunction
from bayes_opt import BayesianOptimization

pbounds = {'y': (y_limits[0], y_limits[1]), 'yaw': (0, math.pi/2), 'pitch': (pitch_limits[0], pitch_limits[1])}  
  

 f_sensor_bayesian = partial(f_sensor_b, a_old_i=a_old_i, a_c_old_i=a_c_old_i,
                                origin_to_zivid=origin_to_zivid, width_c=width_c, height_c=height_c, width_p=width_p,
                                height_p=height_p,
                                scene=scene, T=T, K_c=K_c, K_p=K_p, r_max=r_max, r_min=r_min, mesh_tri=mesh_tri,
                                grazing_angle_c=grazing_angle_c, grazing_angle_p=grazing_angle_p, x_limits=x_limits,
                                z_limits=z_limits,
                                roll_limits=roll_limits, tilt_angle=tilt_angle,
                                constrained_visibility_bool=constrained_visibility_bool, epsilon=epsilon,
                                resolution=resolution, baseline_p=baseline_p)


    #bounds_transformer = SequentialDomainReductionTransformer(minimum_window=0.5)
    optimizer = BayesianOptimization(
        f=f_sensor_bayesian,
        pbounds=pbounds,
        verbose=1,  # verbose = 1 prints only when a maximum is observed, verbose = 0 is silent
        random_state=10,
        #bounds_transformer=bounds_transformer
    )
 
    optimizer.probe(
    params={"y": position[1], "yaw": orientation[0], "pitch": orientation[1]},
    lazy=True,
    )
    # Set the Gaussian process parameters using the set_gp_params method
    optimizer.set_gp_params(alpha=bayesian_opt['alpha'], n_restarts_optimizer=bayesian_opt['n_restarts_optimizer']) 

    # Create an instance of the UtilityFunction class
    utility = UtilityFunction(kind=bayesian_opt['kind'], kappa=bayesian_opt['kappa'], kappa_decay=bayesian_opt['kappa_decay'], xi=0.1) 


    optimizer.maximize(
        init_points=bayesian_opt['init_points'],
        n_iter=bayesian_opt['n_iter'],
        acquisition_function=utility,
    )  


# The function f_sensor_b is defined with the following inputs
def f_sensor_b(y, yaw, pitch, a_old_i, a_c_old_i, origin_to_zivid, width_c, height_c, width_p, height_p,
               scene, T, K_c, K_p, r_max, r_min, mesh_tri, grazing_angle_c,
               grazing_angle_p, x_limits, z_limits, roll_limits, tilt_angle, baseline_p,
               constrained_visibility_bool, epsilon, resolution)

Activity

  1. t-muser commented on Sep 4, 2023

    @t-muser
    Member

    Hi @vanessastadAIT,

    thanks for reporting the bug. Unfortunately I cannot run your code, as it is not self-contained, but from glancing at it, it looks correct. Ideally, if you can, please provide a self-contained example or some more information, otherwise it is very hard to help you debug this problem. Sidenote: According to the code you posted you are not using the SequentialDomainReductionTransformer, but FYI this could potentially a source of issues since it messes with the pbounds internally (see #441).

  2. vanessastadAIT commented on Sep 4, 2023

    @vanessastadAIT
    Author

    Hi @Till-M. Thank you for replying.
    I tried to run the algorithm without SequentialDomainReductionTransformer but I was getting the same error.
    I found out that the algorithm runs correctly when I define the pbounds numerically e.g. pbounds = {'y': (-0.2, 0.2), 'yaw': (0, 1.57), 'pitch': (-0.7, 0.7)}.
    I don't know why this happens since when I print y_limits[0], y_limits[1] or pitch_limits[0], pitch_limits[1]) I get the same values.

    Unfortunately, I am not able to provide a self-contained code because the function f_sensor_b depends on many other functions :( .

  3. t-muser commented on Sep 4, 2023

    @t-muser
    Member

    Could you maybe try printing optimizer.space.bounds at various points in your code?

  4. perezed00 commented on Sep 4, 2023

    @perezed00
    Contributor

    @vanessastadAIT ,

    It seems like there are two scenarios: with domain reduction and without domain reduction. If you see a pbound error in code that does not use domain reduction, I recommend troubleshooting that version of the code first.

    If for some reason you find that the error does indeed occur when domain reduction is used, I would double check the value of orientation[1] that is used in the call to optimizer.probe. There is a bug in v1.4.3 that can cause pbounds to be bypassed if the value of the params in the probe are outside of the pbounds. A fix for this bug has been implemented in #441.

  5. t-muser commented on Sep 7, 2023

    @t-muser
    Member

    Hey @vanessastadAIT, did you solve the problem?

  6. vanessastadAIT commented on Sep 7, 2023

    @vanessastadAIT
    Author

    Hi @perezed00 and @Till-M. My initial work around was to define pbounds numerically. I have just tried to print the pbounds with optimizer.space.bounds both when pbounds are defined numerically or with variables e.g. pbounds = {"y": (-0.21, 0.29)} or pbounds = {"y": (y_limits[0], y_limits[1])} and now everything seems working fine (even in case of bounds_transformer = SequentialDomainReductionTransformer(minimum_window=0.01)). In the last week, I played around with the hyperparameters of the optimizer e.g. init_points, n_iteration etc. I don't know if the error was for example due to a too high number of iterations.

  7. t-muser commented on Sep 7, 2023

    @t-muser
    Member

    Glad to hear it is working. I will close the issue for now, feel free to reopen if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions