我应该如何测试遗传算法 [英] How should I Test a Genetic Algorithm

查看:92
本文介绍了我应该如何测试遗传算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制定了很多遗传算法;他们工作(他们很快找到了一个合理的解决方案).但是我现在发现了 TDD .有没有一种方法可以以TDD方式编写遗传算法(严重依赖于随机数) ?

I have made a quite few genetic algorithms; they work (they find a reasonable solution quickly). But I have now discovered TDD. Is there a way to write a genetic algorithm (which relies heavily on random numbers) in a TDD way?

更笼统地提出这个问题:如何测试不确定的方法/功能.这是我想到的:

To pose the question more generally, How do you test a non-deterministic method/function. Here is what I have thought of:

  1. 使用特定的种子.如果我一开始就在代码中犯了一个错误,那将无济于事,但在重构时将有助于查找错误.

  1. Use a specific seed. Which wont help if I make a mistake in the code in the first place but will help finding bugs when refactoring.

使用已知的数字列表.与上述类似,但是我可以手工跟踪代码(这很繁琐).

Use a known list of numbers. Similar to the above but I could follow the code through by hand (which would be very tedious).

使用常数.至少我知道会发生什么.确保当RandomFloat(0,1)始终返回1时,骰子始终读取6会很好.

Use a constant number. At least I know what to expect. It would be good to ensure that a dice always reads 6 when RandomFloat(0,1) always returns 1.

尝试将尽可能多的不确定性代码移出GA.这似乎很愚蠢,因为这是其目的的核心.

Try to move as much of the non-deterministic code out of the GA as possible. which seems silly as that is the core of it's purpose.

也将链接到非常好的测试书籍.

Links to very good books on testing would be appreciated too.

推荐答案

在我看来,测试其一致逻辑的唯一方法是应用一致输入. ..或将每次迭代视为单个自动机,在迭代之前和之后对其状态进行测试,从而根据确定性迭代值将整个不确定性系统转换为可测试的组件.

Seems to me that the only way to test its consistent logic is to apply consistent input, ... or treat each iteration as a single automaton whose state is tested before and after that iteration, turning the overall nondeterministic system into testable components based on deterministic iteration values.

对于迭代中的变异/育种/属性继承,请在每次迭代的边界上测试这些值,并基于成功的迭代子测试的已知输入/输出来测试所有迭代的全局输出...

For variations/breeding/attribute inheritance in iterations, test those values on the boundaries of each iteration and test the global output of all iterations based on known input/output from successful iteration-subtests ...

由于该算法是迭代算法,因此您可以在测试中使用 induction 来确保它可以进行1次迭代,因此n + 1次迭代可以证明对于给定的条件,它将产生正确的结果(与数据确定性无关)输入范围/域以及输入中可能值的约束.

Because the algorithm is iterative you can use induction in your testing to ensure it works for 1 iteration, n+1 iterations to prove it will produce correct results (regardless of data determinism) for a given input range/domain and the constraints on possible values in the input.

编辑,我发现了此测试策略非确定性系统,可能会提供一些见识.一旦TDD/开发过程证明逻辑是合理的,这可能会对实时结果的统计分析有所帮助.

Edit I found this strategies for testing nondeterministic systems which might provide some insight. It might be helpful for statistical analysis of live results once the TDD/development process proves the logic is sound.

这篇关于我应该如何测试遗传算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆