原本运行正常,但用pip重新下载了sko之后,就出现错误
维度设置正常,但是报错:
TypeError: __init__() got an unexpected keyword argument 'n_dim'
运行官方https://scikit-opt.github.io/scikit-opt/#/zh/README里的example的时候,也会出现这个报错
官方例子如下:
def demo_func(x):
x1, x2, x3 = x
return x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2
from sko.PSO import PSO
pso = PSO(func=demo_func, n_dim=3, pop=40, max_iter=150, lb=[0, -1, 0.5], ub=[1, 1, 1], w=0.8, c1=0.5, c2=0.5)
pso.run()
print('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)
import matplotlib.pyplot as plt
plt.plot(pso.gbest_y_hist)
plt.show()