我在Python中使用PyGMO包进行多目标优化。我无法在构造函数中修复fitness函数的维度,而且文档也不是很具描述性。我想知道这里是否有人在过去有过PyGMO的经验:这可能相当简单。在
我试图构建一个最小的示例:from PyGMO.problem import base
from PyGMO import algorithm, population
import numpy as np
import matplotlib.pyplot as plt
class my_problem(base):
def __init__(self, fdim=2):
NUM_PARAMS = 4
super(my_problem, self).__init__(NUM_PARAMS)
self.set_bounds(0.01, 100)
def _objfun_impl(self, K):
E1 = K[0] + K[2]
E2 = K[1] + K[3]
return (E1, E2, )
if __name__ == '__main__':
prob = my_problem() # Create the problem
print (prob)
algo = algorithm.sms_emoa(gen=100)
pop = population(prob, 50)
pop = algo.evolve(pop)
F = np.array([ind.cur_f for ind in pop]).T
plt.scatter(F[0], F[1])
plt.xlabel("$E_1$")
plt.ylabel("$E_2$")
plt.show()
上面的fdim=2是设置适应度维度的失败尝试。代码失败,错误如下:
^{pr2}$
如果有人能帮我解决这个问题,我将不胜感激。谢谢!在