这是我的问题。
Pyevolve是一个很棒的基于遗传算法的框架。
不同于random.randint
生成初始个体(第一代)的方式。它使用自己的功能来实现:
genome = G1DList.G1DList(8)
# Sets the range max and min of the 1D List
genome.setParams(rangemin=0, rangemax=1000)
# pyevolve will generate 80 different individuals as default
上面的代码等于
def individual(NUMBER):
loc = random.sample(np.arange(1000), NUMBER)
return loc
def population(GENSIZE, NUMBER):
## GENSIZE--> population scale
## NUMBER --> 8-elements list
return [ individual(NUMBER) for x in np.arange(GENSIZE) ]
pop = population(80, 8)
但是当样本域不在连续范围内时。例如:
LIST = np.arange([1,3,4,5,6,7,9,10, 12, 14,16,17,18]) ## some number are missing on purpose
有了sample = random.sample(LIST,8)
,我仍然可以得到一个随机的 8 元素列表。
但是如何使用基因组.setParams 在Pyevolve中实现它。
任何建议将不胜感激。