Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to "suggest" just a configuration out of a fixed list? #17

Closed
sebastianpinedaar opened this issue Apr 20, 2022 · 4 comments

Comments

@sebastianpinedaar
Copy link

In HEBO there are different spaces designs, such a Integer, StepInteger, etc... I was wondering if it is possible to have just a list of possible configurations that we want to be suggested and subsequently observe.

Best,

Sebastian

@Alaya-in-Matrix
Copy link
Collaborator

Alaya-in-Matrix commented Apr 22, 2022

We don't have a special API for that, but it's possible in HEBO with the observe function. you just need to feed the configurations with observe.

For example, let's say you want to minimize f(x) = x^2, and you want to provide two initial guess x = 3 and x = -5, then you can do it by the following code

import pandas as pd
from hebo.design_space import DesignSpace
from hebo.optimizers.hebo import HEBO

def obj_func(param):
    return (param['x'].values**2).reshape(-1, 1)

space = DesignSpace().parse([{'name' : 'x', 'type' : 'num', 'lb': -10, 'ub' : 10}])
opt   = HEBO(space)

initial_suggest = pd.DataFrame([{'x' : 3}, {'x' : -5}])
opt.observe(initial_suggest, obj_func(initial_suggest))

for i in range(3):
    rec = opt.suggest()
    opt.observe(rec, obj_func(rec))

print(opt.X)

@phyzhenli
Copy link

phyzhenli commented May 22, 2022

It is not enough with observe only. There must be suggest before observe.

The code should be modified as follows:

......
initial_suggest = pd.DataFrame([{'x' : 3}, {'x' : -5}])
initial_suggest = opt.suggest(n_suggestions=1, fix_input = initial_suggest)
opt.observe(initial_suggest, obj_func(initial_suggest))
......

@sebastianpinedaar
Copy link
Author

Thank you for the reply.

I actually mean a set of fixed configurations to observe, not only initial configurations.

For instance, if we want to optimize "learning rate" from an arbitrary list : [1e-5, 3e-5, 6e-5, 7e-5, 4e-4, 5e-2, 8e-1],
how can I do it? I wonder because this list does not match any pattern from the possible design spaces.

Best,
Sebastian

@AntGro
Copy link
Collaborator

AntGro commented Dec 8, 2022

Hello Sebastian,

For now I think the best option would consist in considering "lr" as an integer parameter with lower bound 1 and upper bound the size of your list L (so for L = [1e-5, 3e-5, 6e-5, 7e-5, 4e-4, 5e-2, 8e-1] it would be 6) and to make your blackbox convert the suggestion lr = i to lr = L[i]. Note that you could also use a categorical parameter to directly suggest an element of your list, but then HEBO would not be aware of the order relations among the "categories".

@AntGro AntGro closed this as completed May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants