python - pymoo 中具有自定义或任意步长的离散变量
问题描述
我正在使用 Python 的 pymoo 包,我正在尝试做一些简单的事情。
我有三个变量(a,b,c)。
我希望 a 是连续的,这是微不足道的。
我希望 b 是离散的,以 5 为步长,例如 [0,5,10,...,25]。
我希望 c 也是离散的,但以对数间隔,例如 [1,10,100,1000]。
使用离散变量时,我似乎无法将步长更改为 1 以外的任何值。我已成功尝试以下操作:
... #snippet
def __init__(self):
super().__init__(
n_var = 3,
n_obj = 1,
n_constr = 1,
xl = np.array([0,0,0]),
xu = np.array([1,5,3]),
elementwise_evaluation = True,
)
def _evaluate(self,x,out,*args,**kwargs):
a = x[0] # itself
b = round(x[1]) * 5 # evals to 0,5,10,15,20,25
c = [1,10,100,1000][round(x[2])] # evals to 1,10,100,1000
...
然而,这似乎是一种混乱的方法。有没有一种简单的方法可以做到这一点?
解决方案
直接地,使用这些步骤限制搜索空间将需要对 GA 进行大量定制。但是,您可以通过在评估之前对变量进行相当简单的映射来实现这一点:
class MyProblem(Problem):
def __init__(self):
super().__init__(
n_var = 3,
n_obj = 1,
n_constr = 1,
xl = np.array([0,0,0]),
xu = np.array([5,5,5]),
elementwise_evaluation = True,
)
def _evaluate(self,x,out,*args,**kwargs):
_a, _b, _c = x
a = _a
b = _b * 5
c = 10 ** _c
这是你想要达到的目标吗?
推荐阅读
- java - 以 GUI swing JFrame 作为其父级创建 JDialog?
- python-3.x - str 和 int 之间不支持的操作数
- reactjs - 使用 Amplify 实现的登录表单未应用样式
- r - ggplot boxplot 只显示一个而不是 10 个,如何解决?
- java - Android进度条不显示tje进度
- python - PyQt5 像素级碰撞检测
- node.js - 每个客户单页应用程序的自定义域名
- google-bigquery - DBT 404 未找到:数据集 hello-data-pipeline:staging_benjamin 在 EU 位置未找到
- html - Django:下拉框
- html - 如何使用 CSS 使表单输入垂直而不是水平?