使用 DEAP 对多个变量进行多目标优化



我正在尝试优化仿真软件的两个输出(我使用随机森林来训练一个模型以快速预测输出(。有七个输入变量,三个是连续的,其余的都是离散的。我使用 DEAP 包进行多目标优化,但只有一个变量或一组相关变量(如背包(。提到的七个变量是:

n_rate = [0.1:0.5]
estim = [1000, 1500, 2000]
max_d = [1:20]
ft = [None, "rel"]
min_s = [2:1000]
min_m = [1:1000]
lim = [0:1]

除了ft,对于所有继续变量,可以定义几个离散数。

我的问题是,我如何为这些输入创建不同的个体来定义人口?

执行此操作的方法是注册可以从中创建每个人的"属性"。这是我在代码中使用的内容:

toolbox.register("attr_peak", random.uniform, 0.1,0.5)
toolbox.register("attr_hours", random.randint, 1, 15)
toolbox.register("attr_float", random.uniform, -8, 8)
toolbox.register("individual", tools.initCycle, creator.Individual,
(toolbox.attr_float,toolbox.attr_float,toolbox.attr_float,
toolbox.attr_hours,
toolbox.attr_float, toolbox.attr_float, toolbox.attr_float,
toolbox.attr_hours,toolbox.attr_peak
), n=1)

在我的代码中,我有三个不同的"基因"或"属性",因为我在toolbox中注册了它们。在我的示例中,我有两个连续变量和一个整数约束变量。例如,您将如何定义属性:

toolbox.register("n_rate", random.uniform, 0.1, 0.5)
toolbox.register("estim", random.choice, [1000,1500,2000])
toolbox.register("max_d", random.randint, 1, 20)
toolbox.register("ft", random.choice, [None, 'rel'])
toolbox.register("min_m", random.randint, 1, 1000)
toolbox.register("min_s", random.randint, 2, 1000)
toolbox.register("lim", random.randint, 0, 1)

然后你会像我对initCycle一样构建你的个人。

toolbox.register("individual", tools.initCycle, creator.Individual, (toolbox.your_attribute, toolbox.next_attribute, ... ), n=1)

最新更新