超参数优化工具smc的python接口。

pysmac的Python项目详细描述


简单的python包装器 SMAC,多才多艺的 优化算法参数的工具。

fmin(objective, x0, xmin, xmax, x0_int, xmin_int, xmax_int, xcategorical, params)
   min_x f(x) s.t. xmin < x < xmax

 objective: The objective function that should be optimized.

安装

PIP

pip install pysmac

手动

python setup.py install

示例用法

以branin函数为例。(注意branin 函数不是SMAC的理想用例,它被设计为 用于代价高昂的函数的全局优化工具。也就是说,它会服务 检查是否一切正常的目的。)

importnumpyasnpdefbranin(x):b=(5.1/(4.*np.pi**2))c=(5./np.pi)t=(1./(8.*np.pi))return1.*(x[1]-b*x[0]**2+c*x[0]-6.)**2+10.*(1-t)*np.cos(x[0])+10.

对于x1∈[-5,10],x2∈[0,15],函数达到最小值: 0.397887

注意:fmin接受任何具有名为x的参数的函数。 并返回一个目标值。

frompysmac.optimizeimportfminxmin,fval=fmin(branin,x0=(0,0),xmin=(-5,0),xmax=(10,15),max_evaluations=5000)

评估完成后,我们可以检查输出:

>>>xmin{'x':array([3.14305644,2.27827543])}>>>fval0.397917

让我们用找到的参数运行目标函数:

>>>branin(**xmin)0.397917

许可证

SMAC免费用于学术和非商业用途。请联系Frank Hutter讨论获取 商业许可证。

高级

目标函数的自定义参数:

注意:确保没有与参数名的命名冲突 以及自定义参数。

defminfunc(x,custom_arg1,custom_arg2):print"custom_arg1:",custom_arg1print"custom_arg2:",custom_arg2return1xmin,fval=fmin(minfunc,x0=(0,0),xmin=(-5,0),xmax=(10,15),max_evaluations=5000,custom_args={"custom_arg1":"test","custom_arg2":123})

整数参数

整数参数的编码如下:

defminfunc(x,x_int):print"x: ",xprint"x_int: ",x_intreturn1.xmin,fval=fmin(minfunc,x0=(0,0),xmin=(-5,0),xmax=(10,15),x0_int=(0,0),xmin_int=(-5,0),xmax_int=(10,15),max_evaluations=5000)

分类参数

分类参数可以指定为 它们可以接受的值,例如:

categorical_params={"param1":[1,2,3,4,5,6,7],"param2":["string1","string2","string3"]}defminfunc(x_categorical):print"param1: ",x_categorical["param1"]print"param2: ",x_categorical["param2"]return1.xmin,fval=fmin(minfunc,x_categorical=categorical_params,max_evaluations=5000)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从Struts操作的钩子更改表单值(Liferay 6.2)   java如何改变Spring MVC处理url“点”字符的行为   Clojure中使用Java接口的问题   junit如何模拟comosDB azure java集成客户端?   运行函数时发生java错误   netbeans Java。jar文件和依赖项   Eclipse中文本字段中的java输入类型   在JAVA中,将集合变量从实时批处理运行时传递到调用批处理文件   java通过Bean验证API中的自定义消息管理异常   XML到json的转换,在Java中,同时保留数据类型   根据JAVA中的列名从Excel文件中获取单元格值   在AsyncTask的doInBackground中未调用java FirebaseMessagingService   java如何在数据库中插入一行?