hyperopt
hyperopt copied to clipboard
hp.randint returns zero-dimensional arrays instead of integers
pyll.stochastic.sample(hp.randint('x', 3))
Expected: an integer, like
3
Actual: a "zero-dimensional" array, like
array(3)
Yes, np.array(3).shape
is actually ()
.
Is this expected behavior anywhere in Hyperopt? It makes unpacking parameters annoying and leads to a bunch of other odd behavior.
It also looks like it's due to screwy behavior in Numpy itself:
np.random.randint(0, high=1, size=())
# array(1)
but I'm not sure whether they consider this a feature or a bug.
It can be trivially fixed by changing the default size=()
to size=None
:
pyll.stochastic.sample(hp.randint('x', 3, size=None))
returns the right thing.
Numpy's randint() function allows you to force an output type, as you've likely discovered. Their default size is None, which will return the int value itself. When we call np.random.randint(0, high=1, size=()), we are telling Numpy to return our result in an array with shape, "()".
I agree that it would be nice if a single integer were returned, but I'm worried about backwards compatibility at this point. We would have to:
- Make sure no internal logic breaks because of the pyll update.
- Identify the best course of action for deploying an update that could cause compatibility issues.
The first part is easy, the second part would likely require us waiting until the next "major" version release (i.e. v.1.0.0)
@brandonschabell I came across this issue as I noticed that ray tuning doesn't show parameters that are created using hp.randint
. As of this pull request ray tuning supports np.bool8
and np.int
but not np.ndarray
. Further, I think it will be unwise to support this. To solve this, I currently use the following workaround:
from hyperopt import hp
from hyperopt.pyll.base import scope
search_space = {
"x": scope.int(hp.randint("traj_per_epoch", 5, 50)),
}
I, therefore, think returning an int
or allowing users to specify the return type would be very useful.
Parameters sampled from tune.randint
also don't show up as HPARAMS in Tensorboard.
This issue has been marked as stale because it has been open 120 days with no activity. Remove the stale label or comment or this will be closed in 30 days.