sherpa-ai / sherpa

Hyperparameter optimization that enables researchers to experiment, visualize, and scale quickly.
http://parameter-sherpa.readthedocs.io/
GNU General Public License v3.0
333 stars 54 forks source link

Prevent int parameters from being cast to float in Bayesian optimization #109

Closed jbboin closed 4 years ago

jbboin commented 4 years ago

When we request both float and int parameters in Bayesian optimization, right now sherpa returns all parameters as float. This is due to some pandas behavior which casts int values to float when taking the transpose of the data frame. This PR fixes this and adds a test to ensure the proper behavior.

The steps to reproduce this issue are as follows:

import sherpa

algorithm = sherpa.algorithms.GPyOpt(max_num_trials=4)
parameters = [
    sherpa.Choice('param_int', [0, 1]),
    sherpa.Choice('param_float', [0.1, 1.1]),
]
study = sherpa.Study(
    parameters=parameters,
    algorithm=algorithm,
    lower_is_better=True,
    disable_dashboard=True,
)

for trial in study:
    study.add_observation(trial, iteration=0, objective=0)
    study.finalize(trial)
    assert type(trial.parameters['param_int']) == int
    assert type(trial.parameters['param_float']) == float
LarsHH commented 4 years ago

Thank you for the fix!