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

Suggesting Values #1066

Closed
kjans123 opened this issue Mar 3, 2021 · 2 comments
Closed

Suggesting Values #1066

kjans123 opened this issue Mar 3, 2021 · 2 comments

Comments

@kjans123
Copy link

kjans123 commented Mar 3, 2021

Steps to reproduce

loc = ng.p.Scalar(lower=-5,upper=5)
scale = ng.p.Scalar(lower=0, upper=5)
s = ng.p.Scalar(lower=0, upper=10)
k = ng.p.Choice(list(range(2,6)))
w = ng.p.Array(shape=(self.times.shape[0],)).set_bounds(-10,10)
instru = ng.p.Instrumentation(loc=loc,
                          scale = scale,
                          s=s,
                          k=k,
                          w = w)
optimizer = ng.optimizers.DE(parametrization=instru,
                                      budget=budget)
optimizer.suggest((),{'k':3,'loc':-2,'s':2,'scale':2,'w':np.ones(self.times.shape[0])})

Observed Results

ValueError: Tuple value must be a tuple of size 0, got: ((), {'k': 3, 'loc': -2, 's': 2, 'scale': 2, 'w': array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1.])}).
Current value: ()

Expected Results

For initial values to be set in an optimizer run

Has anyone had success using the suggest method? If so, would you mind copying/pasting working code? I've been trying different forms of the example in the documentation, but cannot seem to get it to work.

@jrapin
Copy link
Contributor

jrapin commented Mar 3, 2021

Hi,
Can you point to the part of the documentation you have been looking at? So that we can clarify it.

Basically, suggest should be called the same way as the function to optimize, in your case, given you are using an Instrumentation, I guess it should be:
optimizer.suggest(k=3, loc=-2, s=2, scale=2, w=mp.ones(self.times.shape[0]))

Another option, which can work for all but the Choice parameter would be to use the init option of Array and Scalar (eg: loc = ng.p.Scalar(init=-2, lower=-5, upper=5))

@kjans123
Copy link
Author

kjans123 commented Mar 3, 2021

Here is the part I was looking at:
https://facebookresearch.github.io/nevergrad/optimization.html?highlight=suggest#telling-non-asked-points-or-suggesting-points

And you're suggested edit did the trick. Thanks!

@kjans123 kjans123 closed this as completed Mar 3, 2021
@jrapin jrapin mentioned this issue Mar 10, 2021
7 tasks
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

2 participants