ARM-software / mango

Parallel Hyperparameter Tuning in Python
Apache License 2.0
335 stars 40 forks source link

Wrong minimum calculation #111

Closed schliffen closed 8 months ago

schliffen commented 8 months ago

I tried the following objective function:

def objective(x):
    return (x-1) * (x-2) +1

and it returned the wrong answer x=1 and objective value = 1.

code:

from mango import scheduler, Tuner
# Search space
param_space = dict(x=range(-10,10))

# Quadratic objective Function
@scheduler.serial
def objective(x):
    return (x-1) * (x-2) +1

# Initialize and run Tuner
tuner = Tuner(param_space, objective)
results = tuner.minimize()

print(f'Optimal value of parameters: {results["best_params"]} and objective: {results["best_objective"]}' )
# => Optimal value of parameters: {'x': 1.5}  and objective: 0.72
schliffen commented 8 months ago

It seems that only takes integers and the answer is also is integer.

sandeep-iitr commented 8 months ago

You can pass in float/non-integer values using proper parameter space definition. Your current definition only defines integer (param_space = dict(x=range(-10,10)))

Take a look at other parameter spaces shown in the readme like:

from scipy.stats import uniform

# uniformly distributed between -10 and 10
param_space = dict(a=uniform(-10, 20))