Hyperopt:定义依赖于其他参数的参数 [英] Hyperopt: Define parameter which is dependent on other parameter

查看:66
本文介绍了Hyperopt:定义依赖于其他参数的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pythonhyperopt 并且我有一个参数 a 需要大于参数 b>.

I am using python package hyperopt and I have a parameter a which requires to be larger than parameter b.

比如我希望我的参数空间是这样的

For example, I hope my parameter space is like

from hyperopt import hp

space = {"b": hp.uniform(0, 0.5), "a": hp.uniform(b, 0.5)}

哪个,要求 a 至少大于 b,我该怎么做?

Which, requires a to be at least larger than b, how can I do that?

提前致谢

推荐答案

一个简单的选择是使用 hyperopt 嵌套参数的能力.因此,您可以根据需要定义超参数空间:

A simple option is to use the ability of hyperopt to nest parameters. You can thus define a hyper-parameter space like you want:

space = hp.uniform("a", hp.uniform("b", 0, 0.5), 0.5)

只有 "a" 的值会传递给您优化的函数(因为这是超参数空间),但是 hyperopt.fmin() 会返回两个参数.

Only "a"'s value is passed to the function that you optimize (because this is the hyper-parameter space), but hyperopt.fmin() will return both parameters.

一个类似的选项,但要优化的函数接收两个参数的地方是:

A similar option, but where the function to be optimized receives both parameters is:

b_var = hp.uniform("b", 0, 0.5)
space = {"b": b_var, "a": hp.uniform("a", b_var, 0.5)}

最后,稍微改变优化函数的输入可能更简单:参数 a 可以替换为 a_fraction,在 0 和 1 之间运行,并在 b 和 0.5(即 a_fraction = 0 产生 a = ba_fraction = 1 产生 a = 0.5 内修改的函数进行优化).因此参数空间具有通常的形式:

Finally, it might be simpler to change a bit the inputs to the optimized function: parameter a can be replaced by a_fraction running between 0 and 1 and interpolating between b and 0.5 (i.e. a_fraction = 0 yields a = b and a_fraction = 1 gives a = 0.5 inside the modified function to be optimized). The parameter space thus has the usual form:

space = {"b": hp.uniform("b", 0, 0.5), "a_fraction": hp.uniform("a_fraction", 0, 1)}

https://github.com/hyperopt/上有一个有趣的讨论hyperopt/issues/175#issuecomment-29401501.

这篇关于Hyperopt:定义依赖于其他参数的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆