问题描述
限时送ChatGPT账号..我有以下问题:对于遗传算法,我正在创建 5 个突变并将它们存储在一个准备好的列表中(参见下面的代码).
i have the following Problem: For a genetic algorithm i'm creating 5 mutations and store them in a prepared list (see code below).
这是我想要附加变异驱动程序的函数:
This is my function where i want to append the mutated drivers:
def startNewRunFromScratch(self):
self.log.logBlue('Starting new run from scratch', 2, 0)
parameterSet = []
parameterSet.append(Parameter('TEST', 0.5, 0, 1))
defaultGDriver = GDriver(parameterSet)
gDriverList = []
gDriverList.append(defaultGDriver)
m = Mutation(self.mutationRate)
for i in range(1, self.populationSize, 1):
g = m.mutate(defaultGDriver)
self.log.log('After mutaion: '+str(g.parameterSet[0].value), 0, 2)
gDriverList.append(g)
self.startSuite(gDriverList)
这里是 startSuite 原型函数:
And here the the startSuite prototype function:
def startSuite(self, gDriverList):
self.log.logSuccess('Starting suite', 1, 0)
for g in gDriverList:
self.log.log('Inside suite: '+str(g.parameterSet[0].value), 0, 2)
问题是,输出与我的逻辑不匹配:
The problem is, that the output does not match my logic:
Starting new run from scratch
After mutaion: 0.5
After mutaion: 0.5
After mutaion: 0.5
After mutaion: 0.740296236666
Starting suite
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
预期输出:
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.740296236666
有人知道如何解决这个问题吗?也许我错过了什么.
Does anyone have an good idea how to solve this problem? Maybee im missing something.
推荐答案
您反复追加相同的 Mutation
,结果在列表中多次引用它.如果你想要不同的 Mutations
,你必须制作新的.(我假设这就是您认为的问题",因为您从未明确说明输出有什么问题.)
You repeatedly append the same Mutation
, and end up with multiple references to it in the list. If you want different Mutations
, you have to make new ones. (I assume that's what you think is the "problem", as you never explicitly say what is wrong about the output.)
这篇关于追加没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论