遗传算法与矮人
我正在尝试使用Pygad制作一种遗传算法,以找到最大化此功能的最佳值:z =(3*(x^2 -y)^2 +(100 -x)^2) +(y - x)
,x和y [-4,4]之间。
有人可以给我发送与此功能类似的示例吗?我发现的示例使用了一个已经给出的输入的函数:y = f(w1:w6)= w1x1 + w2x2 + w3x3 + w4x4 + w4x4 + w5x5 + 6wx6
我不知道我怎么能使用两个变量的函数获取每个人的健身价值
I'm trying to make a genetic algorithm with PyGAD to find the best value that maximize this function: Z = (3*(x^2 - y)^2 + (100 - x)^2) + (y- x)
, x and y between [-4, 4].
Could someone send me an example of something similar to this function? The example I found uses a function with inputs that have already been given: y = f(w1:w6) = w1x1 + w2x2 + w3x3 + w4x4 + w5x5 + 6wx6
I don't know how i can get the fitness value to each individual using the function with two variables
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个解决您的问题的小枪代码。
基于您的描述,以下是某些参数的值:
num_genes = 2
:将其设置为2,因为您只有2个基因。sol_per_pop = 10
:设置为10,因为您说您有10个人。gene_space = {“ low”:-2,“高”:2}
:它限制了基因不会超出-2:2范围。mutation_by_replacement = true
:这确保应用突变后不会超出范围。您可以根据自己的喜好更改使用的其他参数。例如,您可能通过增加世代数来获得更好的健身(
num_generations
)。请确保安装了Pygad并运行&nbsp'脚本。
This is a PyGAD code that solves your problem.
Based on your description, here are the values of some parameters:
num_genes=2
: It is set to 2 because you only have 2 genes.sol_per_pop=10
: Set to 10 because you said you have 10 individuals.gene_space={"low": -2, "high": 2}
: It restricts the genes to not go beyond the -2:2 range.mutation_by_replacement=True
: This makes sure the genes do not go beyond the range after mutation is applied.You can change the other parameters used according to your preference. For example, you may get better fitness by increasing the number of generations (
num_generations
).Please make sure that PyGAD is installed and run the script.