如何将多目标多输入优化问题的输出可视化?

2024-09-28 21:01:39 发布

您现在位置:Python中文网/ 问答频道 /正文

对于multi-objective optimization problem,可视化输出的一种可能性是在二维图中绘制两个目标函数输出(参见下面的参考代码):

plotting the output of the objective functions in a scatter plot

如何整合绘图中输入参数的参考值,以直观了解输入参数对目标输出的影响

代码:

from platypus import NSGAII, Problem, Real

import matplotlib
matplotlib.use('QT5Agg')
import matplotlib.pyplot as plt

def schaffer(x):
    return [x[0]**2 + x[1]**2, (x[0]-2)**2 + (x[1]-2)**2]

problem = Problem(2, 2)    # two decision variables, two objective functions
problem.types[:] = Real(-100, 100)
problem.function = schaffer

algorithm = NSGAII(problem)
algorithm.run(10_000)

plt.figure(1)
plt.scatter([s.objectives[0] for s in algorithm.result],
            [s.objectives[1] for s in algorithm.result])
plt.xlabel("$f_1(x)$")
plt.ylabel("$f_2(x)$")
plt.grid()
plt.show()

Tags: 代码import目标参数matplotlibpltalgorithmreal