从dlib构建全局函数搜索优化器
gfsopt的Python项目详细描述
gfsopt
pip3 install --user gfsopt
方便的脚手架 Global Function Search 来自Dlib库的超参数优化器。 (见:'A Global Optimization Algorithm Worth Using')
提供以下功能:
- 并行优化:并行运行多个超参数搜索
- 保存和还原进度:将设置和优化进度保存/还原到/从文件。
- 多次运行的平均值:使用相同的 多次参数并将平均值报告给dlib的全局函数 搜索。在高度随机域中很有用,可避免将搜索偏向 运气好。
示例用法
一个基本例子,我们在10次运行中最大化^ {< CD2>}关于^ {< CD3>}, 有多少个并行进程就有多少个逻辑核心,并将进度保存到文件中。
from gfsopt import GFSOptimizer
def obj_func(x, y, pid):
""""Function to be maximized (pid is iteration number)""""
a = (1.5 - x + x * y)**2
b = (2.25 - x + x * y * y)**2
c = (2.625 - x + x * y * y * y)**2
return -(a + b + c)
# For this example we pretend that we want to keep 'x' fixed at 0.5
# while optimizing 'y' in the range -4.5 to 4.5
pp = {'x': 0.5} # Problem parameters
space = {'y': [-4.5, 4.5]} # Parameters to optimize over
optimizer = GFSOptimizer(pp, space, fname="test.pkl")
# Will sample and test 'y' 10 times, then save results, progress and settings to file
optimizer.run(obj_func, n_sims=10)
有关更广泛的示例,请参见 example.py。
安装和要求
需要python>;=3.6和以下库:
datadiff
dlib
numpy
要安装,请执行以下操作:
pip3 install --user gfsopt
文档
参见example.py了解 一个例子和http://gfsopt.readthedocs.io/ 用于API文档。