在多目标、多变量优化问题中,如何减少对黑盒方法的访问量?

2024-10-02 10:25:38 发布

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

我有一个黑盒函数,有几个输入和several objectives。我正在寻找一个框架,帮助我优化输入参数。你知道吗

执行该函数大约需要两秒钟。因此,总体运行时间不应过多。你知道吗

我开始看platypus-opt。你知道吗

我创建了一个小脚本来检查通过库访问我的黑盒函数的数量(为了简单起见,只有一个目标)。关于我的输入参数,似乎有太多的访问。并且只有当大量访问完成时,才会传递期望的结果(00)。你知道吗

如何减少对函数的访问量?你知道吗

或者有没有其他更适合我的问题的框架?你知道吗

from platypus import Problem, Integer, NSGAII

accessCounter = 0

def my_function(x):
    global accessCounter
    accessCounter += 1
    return -x[0] ** 2 - x[1] ** 2

problem = Problem(2, 1)  # define 2 inputs and 1 objective (and no constraints)
problem.directions[:] = Problem.MAXIMIZE
int0 = Integer(-2, 2)
int1 = Integer(-2, 2)
problem.types[:] = [int0, int1]
problem.function = my_function
algorithm = NSGAII(problem)

myLengths = [10, 100, 1_000]

for myLength in myLengths:
    algorithm.run(myLength)
    uniqueResults0 = set([int0.decode(x.variables[0]) for x in algorithm.result])
    uniqueResults1 = set([int1.decode(x.variables[1]) for x in algorithm.result])
    print('-----------------')
    print("myLength:", myLength)
    print("accessCounter:", accessCounter)
    print("uniqueResults0:", uniqueResults0)
    print("uniqueResults1:", uniqueResults1)

结果:

-----------------
myLength: 10
accessCounter: 100
uniqueResults0: {0, 1, 2, -2, -1}
uniqueResults1: {0, 1, 2, -1, -2}
-----------------
myLength: 100
accessCounter: 273
uniqueResults0: {0, 1, -1}
uniqueResults1: {0, 1, -1}
-----------------
myLength: 1000
accessCounter: 1314
uniqueResults0: {0}
uniqueResults1: {0}

Tags: 函数inforfunctionintegeralgorithmprintproblem

热门问题