相关疑难解决方法(0)

scipy 的 shgo 优化器无法最小化方差

为了熟悉全局优化方法,特别是shgo优化器,scipy.optimize v1.3.0我尝试在具有给定平均值的约束下最小化向量的方差var(x)x = [x1,...,xN]0 <= xi <= 1x

import numpy as np
from scipy.optimize import shgo

# Constraint
avg = 0.5  # Given average value of x
cons = {'type': 'eq', 'fun': lambda x: np.mean(x)-avg}

# Minimize the variance of x under the given constraint
res = shgo(lambda x: np.var(x), bounds=6*[(0, 1)], constraints=cons)
Run Code Online (Sandbox Code Playgroud)

shgo方法在这个问题上失败了:

>>> res
     fun: 0.0
 message: 'Failed to find a feasible minimiser point. Lowest sampling point …
Run Code Online (Sandbox Code Playgroud)

optimization scipy shgo

5
推荐指数
0
解决办法
2162
查看次数

标签 统计

optimization ×1

scipy ×1

shgo ×1