How should I Test a Genetic Algorithm

Posted by James Brooks on Stack Overflow See other posts from Stack Overflow or by James Brooks
Published on 2009-06-24T15:26:08Z Indexed on 2010/03/20 19:21 UTC
Read the original article Hit count: 694

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. 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.

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

  3. 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.

  4. 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.

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about unit-testing