遗传算法中的最优种群规模、变异率和交配率

发布于 2024-10-02 19:31:11 字数 775 浏览 0 评论 0原文

我为比赛编写了一个游戏程序,它依赖于大约 16 个浮点“常量”。改变常数可以并且将会对游戏风格和成功率产生巨大影响。

我还编写了一个简单的遗传算法来生成常数的最佳值。然而,该算法不会生成“最佳”常数。

可能的原因:

  • 算法有错误(暂时排除这一点!)
  • 种群太小
  • 变异率太高
  • 交配率可能会更好

算法是这样的:

  • 首先创建初始种群
  • 初始常数为每个成员都被分配(根据我的偏见乘以 0.75 到 1.25 之间的随机因子)
  • 对于每一代,人口中的成员都会配对进行一场游戏比赛
  • 获胜者被克隆两次,如果平局,则两个都被克隆一次 克隆
  • 会突变一个基因,如果random() 小于突变率
  • 突变将随机常数乘以 0.75 到 1.25 之间的随机因子
  • 在固定间隔,根据交配率,成员配对并且基因混合

我当前的设置:

  • 种群:40(至低)
  • 突变比率 0.10 (10%)
  • 交配率 0.20(每 5 代)

种群规模、突变率和交配率的更好值是多少?

欢迎猜测,不期望确切的值! 另外,如果您对类似的遗传算法有见解,并且愿意分享,请这样做。

PS:所讨论的游戏比赛,如果有人感兴趣的话:http://ai-contest.com/

I have written a game playing program for a competition, which relies on some 16 floating point "constants". Changing a constant can and will have dramatic impact on playing style and success rate.

I have also written a simple genetic algorithm to generate the optimal values for the constants. However the algorithm does not generate "optimal" constants.

The likely reasons:

  • The algorithm has errors (for the time being rule this out!)
  • The population is to small
  • The mutate rate is to high
  • The mate rate could be better

The algorithm goes like this:

  • First the initial population is created
  • Initial constants for each member are assigned (based on my bias multiplied with a random factor between 0.75 and 1.25)
  • For each generation members of the population are paired for a game match
  • The winner is cloned twice, if draw both are cloned once
  • The cloning mutates one gene if random() is less than mutate rate
  • Mutation multiplies a random constant with a random factor between 0.75 and 1.25
  • At fixed intervals, dependent on mate rate, the members are paired and genes are mixed

My current settings:

  • Population: 40 (to low)
  • Mutate rate 0.10 (10%)
  • Mate rate 0.20 (every 5 generations)

What would be better values for population size, mutate rate and mate rate?

Guesses are welcome, exact values are not expected!
Also, if you have insights with similar genetic algorithms, you will like to share, please do so.

P.S.: The game playing competition in question, if anyone is interested: http://ai-contest.com/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屌丝范 2024-10-09 19:31:11

你的突变大小让我惊讶地高。它还存在一些固有的偏差——当前值越大,突变就越大。

你可能会考虑

  1. 有一个(小得多!)较小的突变
  2. 给突变一个固定的范围
  3. 以不同的方式分布你的突变大小 - 例如你可以使用平均值为 1 的正态分布

。 RA Fisher 曾经将突变大小与聚焦显微镜进行了比较。如果你改变焦点,你可能会朝着正确的方向前进,也可能会朝着错误的方向前进。然而,如果你相当接近最佳值并且经常转动它 - 要么你会走错方向,要么你会超越目标。因此,更微妙的调整通常会更好!

Your mutation size strikes me as surprisingly high. There's also a bit of bias inherent in it - the larger the current value is, the larger the mutation will be.

You might consider

  1. Having a (much!) smaller mutation
  2. Giving the mutation a fixed range
  3. Distributing your mutation sizes differently - e.g. you could use a normal distribution with a mean of 1.

R.A. Fisher once compared the mutation size to focusing a microscope. If you change the focus, you might be going in the right direction, or the wrong direction. However, if you're fairly close to the optimum and turn it a lot - either you'll go in the wrong direction, or you'll overshoot the target. So a more subtle tweak is generally better!

痕至 2024-10-09 19:31:11

使用 GAUL 框架,非常简单,您可以提取目标函数并将其插入 GAUL。如果您有一台多核机器,那么您会在编译时使用 omp (openMP ) 来并行化您的评估(我认为这很耗时)。这样你就可以拥有更大的人口规模。 http://gaul.sourceforge.net/

通常他们使用高交叉和低突变。既然你想要创造力,我建议你高突变和低交叉。http://games.slashdot.org/story/10/11/02/0211249/Developing-emStarCraft-2em-Build-Orders-With-Genetic-Algorithms? from=rss

在你的变异函数中要非常小心,以留在你的空间搜索中(在 0.75, 1.25 内)。使用 GAUL 随机函数,例如 random_double( min, max )。它们设计得非常好。构建您自己的突变函数。确保父母都死了!

然后您可能需要将其与 GAUL 中包含的单纯形 (Nelder-Mead) 结合起来,因为低交叉的遗传编程会找到非最佳解决方案。

Use GAUL framework, it's really easy so you could extract your objective function to plug it to GAUL. If you have a multi-core machine, then you would want to use omp (openMP ) when compiling to parallelize your evaluations( that I assume are time consumming ). This way you can have a bigger population size. http://gaul.sourceforge.net/

Normally they use High crossover and low mutation. Since you want creativity i suggest you High mutation and low crossover.http://games.slashdot.org/story/10/11/02/0211249/Developing-emStarCraft-2em-Build-Orders-With-Genetic-Algorithms?from=rss

Be really carefull in your mutation function to stay in your space search ( inside 0.75, 1.25 ). Use GAUL random function such as random_double( min, max ). They are really well designed. Build your own mutation function. Make sure parents dies !

Then you may want combine this with a simplex (Nelder-Mead), included in GAUL, because genetic programming with low crossover will find a non optimal solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文