Git Product home page Git Product logo

Comments (6)

nzw0301 avatar nzw0301 commented on July 21, 2024 1

Thank you for your check. You're right. Sorry for confusing you.

from optuna.

rzhang-at-hrt avatar rzhang-at-hrt commented on July 21, 2024 1

no problem. Is there any quick hacks I can do to get around this? I'm assuming this is showing up because constant_liar's implementation doesn't add any constraints during the period after ask() and before tell(). Does the fact that we don't have constraint values and it being "treated as a lower priority" actually cause a quantifiable difference in the optimization quality? If not, I'm happy to suppress this warning for now on my side.

from optuna.

not522 avatar not522 commented on July 21, 2024 1

Thank you for your bug report. I investigated the cause, and it will be fixed by #5298. In my understanding, it does not affect the optimization quality if you do not set infinity for constraint values.

from optuna.

nzw0301 avatar nzw0301 commented on July 21, 2024

Strangely, Trials 0-9 do not have any warnings

The first 10 trials use random sampler instead of TPESampler with a default argument . At least this behaviour is expected.

from optuna.

nzw0301 avatar nzw0301 commented on July 21, 2024

Thank you for reporting it. As a workaround, could you use trial.set_system_attr rather than set_user_attr?

import optuna


def objective(trial):
    # Binh and Korn function with constraints.
    x = trial.suggest_float("x", -15, 30)
    y = trial.suggest_float("y", -15, 30)

    # Constraints which are considered feasible if less than or equal to zero.
    # The feasible region is basically the intersection of a circle centered at (x=5, y=0)
    # and the complement to a circle centered at (x=8, y=-3).
    c0 = (x - 5) ** 2 + y ** 2 - 25
    c1 = -((x - 8) ** 2) - (y + 3) ** 2 + 7.7

    # Store the constraints as user attributes so that they can be restored after optimization.
    # trial.set_user_attr("constraint", (c0, c1))
    trial.set_system_attr("constraint", (c0, c1))

    v0 = 4 * x ** 2 + 4 * y ** 2
    v1 = (x - 5) ** 2 + (y - 5) ** 2

    return v0, v1


def constraints(trial):
    # return trial.user_attrs["constraint"]
    return trial.system_attrs["constraint"]


sampler = optuna.samplers.TPESampler(constraints_func=constraints, constant_liar=True)
study = optuna.create_study(
    directions=["minimize", "minimize"],
    sampler=sampler,
)
study.optimize(objective, n_trials=32, timeout=600)

Anyways, I think this should be fixed.

from optuna.

rzhang-at-hrt avatar rzhang-at-hrt commented on July 21, 2024

Hi @nzw0301 thanks for getting back to me so quickly. I think using system attrs doesn't work either:

import optuna


def objective(trial):
    # Binh and Korn function with constraints.
    x = trial.suggest_float("x", -15, 30)
    y = trial.suggest_float("y", -15, 30)

    # Constraints which are considered feasible if less than or equal to zero.
    # The feasible region is basically the intersection of a circle centered at (x=5, y=0)
    # and the complement to a circle centered at (x=8, y=-3).
    c0 = (x - 5) ** 2 + y**2 - 25
    c1 = -((x - 8) ** 2) - (y + 3) ** 2 + 7.7

    # Store the constraints as user attributes so that they can be restored after optimization.
    trial.set_system_attr("constraint", (c0, c1))

    v0 = 4 * x**2 + 4 * y**2
    v1 = (x - 5) ** 2 + (y - 5) ** 2

    return v0, v1


def constraints(trial):
    return trial.system_attrs["constraint"]


sampler = optuna.samplers.TPESampler(constraints_func=constraints, constant_liar=True)
study = optuna.create_study(
    directions=["minimize", "minimize"],
    sampler=sampler,
)

# distributed optimization
batch_size = 10
rounds = 20
for round_idx in range(rounds):
    objs = []
    trials = []
    for batch_idx in range(batch_size):
        trials.append((trial := study.ask()))
        objs.append(objective(trial))

    for obj, trial in zip(objs, trials):
        study.tell(trial, obj)

Runs into the same problem. I don't think you can reproduce it if you use study.optimize instead of this batch optimization approach

from optuna.

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.