当我使用 nsga2 在 pymoo 中使用 lstm 作为元模型时,我有一个数据集。我有 4 个目标函数,其中一些是负值,一些是正值。目标是使 4 个目标函数尽可能接近 0。但是我不确定如何为 pymoo 改变什么。我的代码如下。谢谢
...
class MyProblem(Problem):
def __init__(self):
super().__init__(n_var=6,
n_obj=4,
xl=np.array([xl0[i],xl1[i],xl2[i],np.min(xl3),xl4[i],xl5[i],np.min(xl6)]),
xu=np.array([xl0[i]+0.01,xl1[i]+0.01,xl2[i]+0.01,np.max(xl3),xl4[i]+0.01,xl5[i]+0.01,np.max(xl6)]))
def _evaluate(self, X, out, *args, **kwargs):
f1 = model_o1.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f2 = model_o2.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f3 = model_o3.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f4 = model_o4.predict(X.reshape(X.shape[0], 1, X.shape[1]))
out["F"] = np.column_stack([f1, f2, f3,f4])
vectorized_problem = MyProblem()
res_interval = []
algorithm = NSGA2(
pop_size=200,
n_offsprings=200,
sampling=get_sampling("real_random"),
crossover=get_crossover("real_sbx", prob=0.8, eta=15),
mutation=get_mutation("real_pm", eta=20),
eliminate_duplicates=True
)
termination1 = MultiObjectiveDefaultTermination(
x_tol=1e-8,
cv_tol=1e-6,
f_tol=0.0025,
nth_gen=5,
n_last=30,
n_max_gen=500,
n_max_evals=100000)
res = minimize(vectorized_problem,
algorithm,
termination1,
seed=1,
save_history=False,
verbose=False)
...