guofei9987 / guofei9987/scikit-opt

为什么用粒子群算法做的等式约束不能实现?

Open
#144 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

constraint_eq_2 = [
lambda x: **x[4] - 0.624510,**
lambda x: **x[6] - 0.117594,**
lambda x: **x[8] - 0.828125,**
lambda x: **x[9] - 0.391045]**

constraint_ueq_2 = [
lambda x: 0-svr.predict(np.array(x).reshape(1,13)),
lambda x: x[12] - 0.209,
lambda x: 0 - x[12],
lambda x: svr.predict(np.array(x).reshape(1,13)) - 0.7*svr.predict(np.array(data_12_x_nor.iloc[0,:]).reshape(1,13)),
lambda x: 0 - np.min(x),
lambda x: np.max(x) - 0.865692441322172
]
from sko.PSO import PSO
pso = PSO(func=func_2, n_dim=13, pop=40, max_iter=15, lb=[0, 0, 0,0,0,0,0,0,0,0,0,0,0], ub=[1, 1, 1,1,1,1,1,1,1,1,1,1,1], w=0.8, c1=0.5, c2=0.5,constraint_eq=constraint_eq_2, constraint_ueq=constraint_ueq_2)
pso.run()
print('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)

结果: best_x is [0.26858353 0.18923076 0.21069997 0.83421386 **0.24298983** 0.24772933
**0.34677789** 0.47642962 **0.37834972** **0.15027168** 0.75211158 0.21605726
0.17657801] best_y is [-0.99187476]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.