首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mystic能解决有约束的黑盒优化问题吗?

mystic能解决有约束的黑盒优化问题吗?
EN

Stack Overflow用户
提问于 2020-06-12 14:51:14
回答 1查看 459关注 0票数 2

我想知道在python中使用mystic是否可以进行受约束的黑盒优化。如果是这样的话,这个优化包中将提供哪些算法?

EN

回答 1

Stack Overflow用户

发布于 2020-06-12 20:41:59

我是mystic的作者。是的,黑盒约束优化在mystic中是可能的。要了解更多信息,请查看这里的文档:https://github.com/uqfoundation/mystic,以及其中的文档链接。

在约束优化方面,代码库中有大约50个示例:https://github.com/uqfoundation/mystic/tree/master/examples2。约束可以是符号的或函数的,等式和不等式,硬的或软的,可以与and或not组合,并且可以应用于任何优化器。Mystic的约束也是可移植的,可以应用于其他优化代码,如scipy.optimize,以及机器学习代码,如sklearn

Mystic没有很多优化器,但优化器非常可定制,允许您对优化算法的几乎每个方面进行调整。更多的优化器大部分都在开发中,并将在今年夏天/秋天的发布中添加。

下面是上面链接中的一个显式示例:

代码语言:javascript
复制
"""
Maximize: f = 2*x[0]*x[1] + 2*x[0] - x[0]**2 - 2*x[1]**2
Subject to: -2*x[0] + 2*x[1] <= -2
             2*x[0] - 4*x[1] <= 0
               x[0]**3 -x[1] == 0
where: 0 <= x[0] <= inf
       1 <= x[1] <= inf
"""
import numpy as np
import mystic.symbolic as ms
import mystic.solvers as my
import mystic.math as mm

# generate constraints and penalty for a nonlinear system of equations 
ieqn = '''
   -2*x0 + 2*x1 <= -2
    2*x0 - 4*x1 <= 0'''
eqn = '''
     x0**3 - x1 == 0'''
cons = ms.generate_constraint(ms.generate_solvers(ms.simplify(eqn,target='x1')))
pens = ms.generate_penalty(ms.generate_conditions(ieqn), k=1e3)
bounds = [(0., None), (1., None)]

# get the objective
def objective(x, sign=1):
  x = np.asarray(x)
  return sign * (2*x[0]*x[1] + 2*x[0] - x[0]**2 - 2*x[1]**2)

# solve    
x0 = np.random.rand(2)
sol = my.fmin_powell(objective, x0, constraint=cons, penalty=pens, disp=True,
                     bounds=bounds, gtol=3, ftol=1e-6, full_output=True,
                     args=(-1,))

print('x* = %s; f(x*) = %s' % (sol[0], -sol[1]))
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62338990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档