【发布时间】:2023-03-18 01:30:01
【问题描述】:
我正在使用 python 中的 Gene AI 包来测试遗传算法 (https://github.com/diogomatoschaves/geneal/blob/master/geneal/genetic_algorithms/genetic_algorithm_base.py)。
我想要自己的健身功能,所以我写了
def my_fitness(chromosome):
fitness = mean_absolute_percentage_error(chromosome, [0.5 0.5 0.5 0.5])
return fitness
然后按照文档编写如下代码:
from geneal.genetic_algorithms import ContinuousGenAlgSolver
from geneal.applications.fitness_functions.continuous import fitness_functions_continuous
solver = ContinuousGenAlgSolver(
n_genes=4,
fitness_function=my_fitness(chromosome),
pop_size=10,
max_gen=200,
mutation_rate=0.1,
selection_rate=0.6,
selection_strategy="roulette_wheel",
problem_type=float, # Defines the possible values as float numbers
variables_limits=(-10, 10) # Defines the limits of all variables between -10 and 10.
# Alternatively one can pass an array of tuples defining the limits
# for each variable: [(-10, 10), (0, 5), (0, 5), (-20, 20)]
)
solver.solve()
不清楚如何使用我自己的健身功能。得到染色体未定义的错误(显然!)。 如何在这个包中使用我自己的健身功能。请出示。
【问题讨论】: