You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello experts,
Can you help with the guidelines on how to use non-object based minimization?
Thank you very much!
Steps to reproduce
Run the code below and observe sensible outputs. Then uncomment the COBYLA method and the code breaks.
Observed Results
I get an error:
TypeError: NonObjectOptimizer.__init__() got an unexpected keyword argument 'parametrization'
Expected Results
I expect this to break, because the minimizer is "non object" and cannot be instantiated as an object. But I do not understand how to get a for loop and ask-tell architecture from nevergrad. How can I adapt my code to accomplish this?
Note that I have read and implemented the functional scipy version, but my question is how to use the nevergrad wrapping so that I can have ask-tell format in a for loop.
Also is it possible to pass in a Nevergrad parameterization to the wrapped method?
Relevant Code
import nevergrad as ng
def square(x, y=12):
return sum((x - 0.5) ** 2) + abs(y)
# IT WOULD BE GREAT TO USE NEVERGRAD NATIVE PARAMETERIZATION
parametrization = ng.p.Instrumentation(
ng.p.Array(shape=(2,)).set_bounds(lower=-12, upper=12),
y=ng.p.Scalar()
)
def print_candidate_and_value(optimizer, candidate, value):
print(candidate,value)
# THIS WORKS JUST FINE
optimizer = ng.optimizers.NGOpt(parametrization=parametrization, budget=50, num_workers=1)
# UNCOMMENT THIS AND IT BREAKS
#optimizer = ng.families.NonObjectOptimizer(method= 'COBYLA',parametrization=parametrization, budget=50, num_workers=1)
optimizer.register_callback("tell", print_candidate_and_value)
# GETTING THE LOOP BELOW TO WORK IS THE GOAL
for i in range(optimizer.budget):
x = optimizer.ask()
loss = square(*x.args, **x.kwargs)
optimizer.tell(x, loss)
The text was updated successfully, but these errors were encountered:
Well, I was able to figure it out! Here is the working code if anyone else has the same goal:
def square(x, y=12):
return sum((x - 0.5) ** 2) + abs(y)
# IT WOULD BE GREAT TO USE NEVERGRAD NATIVE PARAMETERIZATION
parametrization = ng.p.Instrumentation(
x=ng.p.Array(shape=(2,)).set_bounds(lower=-12, upper=12),
y=ng.p.Scalar()
)
def print_candidate_and_value(optimizer, candidate, value):
print(candidate,value)
optimizer=nevergrad.families.NonObjectOptimizer(method = 'Nelder-Mead')(parametrization=parametrization,budget=100)
optimizer.register_callback("tell", print_candidate_and_value)
for i in range(optimizer.budget):
x = optimizer.ask()
loss = square(*x.args, **x.kwargs)
optimizer.tell(x, loss)
Hello experts,
Can you help with the guidelines on how to use non-object based minimization?
Thank you very much!
Steps to reproduce
Run the code below and observe sensible outputs. Then uncomment the COBYLA method and the code breaks.
Observed Results
I get an error:
Expected Results
I expect this to break, because the minimizer is "non object" and cannot be instantiated as an object. But I do not understand how to get a for loop and ask-tell architecture from nevergrad. How can I adapt my code to accomplish this?
Note that I have read and implemented the functional scipy version, but my question is how to use the nevergrad wrapping so that I can have ask-tell format in a for loop.
Also is it possible to pass in a Nevergrad parameterization to the wrapped method?
Relevant Code
The text was updated successfully, but these errors were encountered: