Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

How to name parameter dimensions? #570

@Hvass-Labs

Description

@Hvass-Labs

Hello, I applaud your effort with this library and I'm sorry to bother you with such a simple question.

I would like to use skopt with Keras and TensorFlow for optimization of hyper-parameters of a Convolutional Neural Network.

I have installed skopt v.0.4 using pip.

Ideally I would like to name the hyper-parameters only once when I define the search-space, and when skopt calls my "fitness" function, it gives named arguments so I don't have to unpack a list of parameters, which is error-prone.

It appears that BayesSearchCV can take a dict of named parameter-dimensions. But I don't think I can use BayesSearchCV because I need to run fit_generator() from Keras instead of fit(), because I want to use larger datasets from the harddisk that don't fit in memory.

So I think I have to use gp_minimize() but this does not take a dict of named parameters, instead it takes a list of dimensions, which can be defined in various ways.

I tried doing the following to name the parameters:

from skopt.space import Real, Categorical, Integer

dimensions = [Real(name='learning_rate', low=1e-6, high=1e-3, prior='log-uniform'),
          Integer(name='num_nodes', low=10, high=256),
          Categorical(name='activation', categories=['relu', 'sigmoid'])]

And then I would call:

from skopt import gp_minimize

res = gp_minimize(func=f, dimensions=dimensions)

The docs say that Integer, Real and Categorical can take a name argument:

https://scikit-optimize.github.io/space/space.m.html#skopt.space.space.Integer

But I get the following error:

TypeError: __init__() got an unexpected keyword argument 'name'

Going into the source-code for space.py we see that name is indeed missing:

class Real(Dimension):
    def __init__(self, low, high, prior="uniform", transform=None):

Is this because I have installed an older version of skopt using pip?

Could you advise how to construct named dimensions in the search-space. Ideally I would only have to name each dimension once when I define it, and then in my fitness function I would like to get named arguments somehow, so I don't need to unpack a list.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions