Skip to content

Logging with Constraints: ScreenLogger doesn't print information related to constraints #363

Closed

Description

@t-muser

(Less of a bug and more of an oversight on my part)

Describe the bug
When using ScreenLogger, no information about the constrained optimization is printed.

To Reproduce

import numpy as np
from bayes_opt import BayesianOptimization
from scipy.optimize import NonlinearConstraint

def target_function(x, y):
    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,
    random_state=1,
)

optimizer.maximize(
    init_points=2,
    n_iter=10,
)

Expected behavior
I'm somewhat torn on what information should be output. I see a few options:

  • Just the value(s) of the constraint function(s) at the specific point
  • Just the "allowed"-ness of the point
  • Both the specific values and the "allowed"-ness
  • Colour disallowed points red and/or allowed points green
  • Just the value(s) of the constraint function(s) at the specific point, colour coded green/red for allowed/disallowed

Personally I'm leaning towards the second option to reduce clutter, but I'm open to other opinions. It would look something like this:

|   iter    |  target   |  allowed  |     x     |     y     |
-------------------------------------------------------------
| 1         | 0.4872    | False     | 2.502     | 4.322     |
| 2         | -0.2401   | True      | 0.0006862 | 1.814     |
| 3         | 0.7821    | False     | 2.304     | 4.326     |
| 4         | 1.249     | False     | 1.899     | 4.321     |
| 5         | 0.7351    | False     | 1.351     | 4.982     |
| 6         | 1.814     | True      | 1.534     | 3.757     |
| 7         | 1.793     | False     | 1.854     | 2.982     |
| 8         | 0.02935   | False     | 2.834     | 1.913     |
| 9         | 1.496     | False     | 1.108     | 3.106     |
| 10        | 0.5423    | True      | 5.99      | 0.06449   |
| 11        | 0.4597    | True      | 5.985     | 5.858     |
| 12        | -1.095    | True      | 5.986     | 2.891     |
=============================================================

Activity

  1. bwheelz36 commented on Oct 11, 2022

    @bwheelz36
    Collaborator

    I agree for the screen logger.
    What about the json logger - there we should probably have the ability to read back in the constraint model the same way we can read back in the objective model?

  2. t-muser commented on Oct 12, 2022

    @t-muser
    MemberAuthor

    What about the json logger - there we should probably have the ability to read back in the constraint model the same way we can read back in the objective model?

    good point, didn't think of that at the time. Should this be in a separate issue?

    @bwheelz36 do you have any preference as to how the ScreenLogger should behave?

  3. bwheelz36 commented on Oct 12, 2022

    @bwheelz36
    Collaborator

    I think the example you posted above with just True/False is adequate

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