code世代遗传算法 [英] Code generation by genetic algorithms
问题描述
进化规划似乎是一个伟大的方式来解决许多优化问题。这个想法是很容易的,实现不使问题。
Evolutionary programming seems to be a great way to solve many optimization problems. The idea is very easy and the implementation does not make problems.
我想知道是否有任何方式的进化创造的Ruby / Python脚本程序(或任何其他语言)?
I was wondering if there is any way to evolutionarily create a program in ruby/python script (or any other language)?
这个想法很简单:
- 创建程序人口
- 进行遗传操作(轮盘赌轮选择或任何其他选择),从最好的项目创建新的继承程序等。
- 在循环点2,直到方案,将满足我们的条件是找到
但仍存在一些问题:
- 如何将染色体重新presented?例如,应该染色体的一个单元是一行code?
- 如何将染色体会产生?如果他们将是code线,我们如何生成它们,以确保它们的语法正确,等等?
这可能产生一个程序的实施例:
Example of a program that could be generated:
创建脚本,需要N个数字作为输入并返回它们的平均值作为输出。
Create script that takes N numbers as input and returns their mean as output.
如果有任何试图建立这样的算法我会很高兴地看到任何链接/来源。
If there were any attempts to create such algorithms I'll be glad to see any links/sources.
推荐答案
如果你确定要做到这一点,你需要的遗传规划,而不是遗传算法。 GP让你进化树的结构化程序。你会怎么做是给它一堆基本的操作(而($寄存器),读($寄存器),增量($寄存器),减($寄存器),分($结果$分子$分母),打印,progn2(这是GP代言执行两个命令顺序))。
If you are sure you want to do this, you want genetic programming, rather than a genetic algorithm. GP allows you to evolve tree-structured programs. What you would do would be to give it a bunch of primitive operations (while($register), read($register), increment($register), decrement($register), divide($result $numerator $denominator), print, progn2 (this is GP speak for "execute two commands sequentially")).
您可能会产生这样的事情:
You could produce something like this:
progn2(
progn2(
read($1)
while($1
progn2(
while($1
progn2( #add the input to the total
increment($2)
decrement($1)
)
)
progn2( #increment number of values entered, read again
increment($3)
read($1)
)
)
)
)
progn2( #calculate result
divide($1 $2 $3)
print($1)
)
)
您会用,因为你的健身功能,是真正的解决方案的距离。就在这里抓,那你算算,传统反正*。再有什么事情,该转换成code中(您选择的语言)。需要注意的是,当你已经有了一个潜在的无限循环在那里,你将有一段时间后切断执行(还有周围的停机问题没办法),它可能会无法正常工作。哪里哪里。还要注意,我提供的code将试图除以零。
You would use, as your fitness function, how close it is to the real solution. And therein lies the catch, that you have to calculate that traditionally anyway*. And then have something that translates that into code in (your language of choice). Note that, as you've got a potential infinite loop in there, you'll have to cut off execution after a while (there's no way around the halting problem), and it probably won't work. Shucks. Note also, that my provided code will attempt to divide by zero.
*有办法解决这个,但一般不是非常远绕过它。
*There are ways around this, but generally not terribly far around it.
这篇关于code世代遗传算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!