Issue Details (XML | Word | Printable)

Key: MATH-207
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Phil Steitz
Reporter: David Stefka
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Math

Implementation of GeneticAlgorithm.nextGeneration() is wrong

Created: 21/May/08 09:50 PM   Updated: 07/Aug/09 09:20 AM
Return to search
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.0

Time Tracking:
Original Estimate: 0.17h
Original Estimate - 0.17h
Remaining Estimate: 0.17h
Remaining Estimate - 0.17h
Time Spent: Not Specified
Remaining Estimate - 0.17h

File Attachments:
  Size
Text File Licensed for inclusion in ASF works geneticalgorithm.patch 2009-03-01 07:41 PM Benjamin McCann 8 kB
Zip Archive Licensed for inclusion in ASF works geneticAlgorithms.zip 2009-03-26 01:50 PM David Stefka 49 kB
Zip Archive genetics_impl.zip 2008-09-29 11:05 AM David Stefka 33 kB
File Licensed for inclusion in ASF works patch 2008-05-21 09:51 PM David Stefka 2 kB

Resolution Date: 30/Jun/09 12:44 AM


 Description  « Hide
The implementation of GeneticAlgorithm.nextGeneration() is wrong, since the only way how a Chromosome can get into the new generation is by mutation.

Enclosed, I am sending a patch for this.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
David Stefka added a comment - 21/May/08 09:51 PM
Patch for the bug

Phil Steitz added a comment - 27/Sep/08 06:09 PM
Patch applied to MATH_2_0 branch in r699704.

Leaving open because I think we need to either make nextGeneration public or protected or make it configurable. Interested in comments on this.


David Stefka added a comment - 29/Sep/08 11:05 AM
Dear Phil,

if you are interested in the topic of genetic algorithms, I am sending a
simple implementation of GA using the commons-math framework. If you find any
of the ideas in it useful, you may use it.

Best regards,
David Stefka


David Stefka
david.stefka@gmail.com (personal mail)


Ben McCann added a comment - 27/Feb/09 02:07 AM
I think that making nextGeneration public would be reasonable.
A few other thoughts about the API:
All the setters should be changed to constructor arguments. If you do not call each of the setters then you are in an illegal state. You avoid the problem of having some call evolve before the mutation policy and crossover policy are set if you just make them required in the constructor.
For crossOverRate and mutationRate we should specify that the input is expected to be between 0 and 1 and throw an exception when given invalid input. It's currently not clear in the javadocs what is expected.

Benjamin McCann added a comment - 01/Mar/09 07:41 PM
Patch to improve the API.

Benjamin McCann added a comment - 09/Mar/09 06:50 PM
Any thoughts on the patch submitted to clean up the API?

David Stefka added a comment - 18/Mar/09 12:50 PM
I think the ideas to clean up the API are okay. However, I don't know whether the patch is against the latest version. Things are starting to be a bit messy...

Phil Steitz added a comment - 19/Mar/09 02:00 AM
Sorry for delay in reviewing these patches. I like both the implementation (David's first patch) and the API improvements and will apply them both if I can get answers to the following.

1) David - pls confirm that you can grant the code in your patch. It is a borderline case whether or not we need a code grant. Given that it just implements the commons-math ga framework, I think it is OK to commit without a grant; but since you did not include ASL license headers in the patch, I need you to confirm that you own the code and can freely contribute it under the terms of the Apache Contributor License Agreement. If you don't mind, it would be good to file a CLA.

2) David's patch looks like it has some JDK 1.6 dependencies. Math 2.0 targets 1.5+, so these need to be removed. I can do this; but a revised patch with these removed and ASL headers would be appreciated.

3) Ben - why expose fields as protected?

Thanks for the patches!


David Stefka added a comment - 19/Mar/09 03:46 PM
ad 1) what do you mean by "file a CLA"? Should I include the license header (e.g. in GeneticAlgorithm.java) to every file in the framework? I do own the code and I agree with the Apache license (http://www.apache.org/licenses/LICENSE-2.0)
ad 2) okay, i will try to make it Java 1.5+ compatible

BTW, I am currently working on a better way of representing permutations, so do not include the original patch now. I will post here a revised version of the implementation in a week or so.


Phil Steitz added a comment - 19/Mar/09 08:18 PM
Thanks, David!

All files should include headers like what you see in GenericAlgorithm.java or any other apache java source file. As long as you own the code and are willing to attach those headers, we should be OK. A Contributors Licence Agreement (CLA) is a good thing to have on file and will be required in any case should you become a committer. Have a look at the "Contributor License Agreements" section at http://www.apache.org/licenses/ to find the form. The form itself includes info on how to submit it.

Thanks again for your conttribution.


David Stefka added a comment - 26/Mar/09 01:48 PM
Hi again,

I have finished work on better representation of permutations in GA, so I am sending the implementation in a .zip file. The code includes:

  • new implementation of RandomKey – chromosome representing permutations; the old PermutationChromosome implementation has been removed
  • some minor improvements (chromosome's representation is held in an unmodifiable list instead of an array, better implementation of generic issues, renaming of several classes, etc.)
  • GeneticAlgorithm has a static Random instance, which is used for all random numbers in the implementation. This is useful for debugging, because if the Random is initialized to a particular seed, the behavior can be reproduced. If a similar mechanism is already somewhere in the
  • the code should be java 1.5 compatible
  • all the files should include the Apache license headers

I have also filled and signed the CLA and sent it to secretary@apache.org


David Stefka added a comment - 26/Mar/09 01:50 PM
New implementation of basic GA algorithms

Ben McCann added a comment - 04/May/09 08:08 PM
Sorry for my delayed response. JIRA didn't email me on any of these updates for whatever reason.
There's no real need to make the fields protected in my patch. Private would be fine. I've just gotten in the habit of frequently using protected to allow easier subclassing and unit testing, but those fields all have public getters, so no harm in making them private.

Phil Steitz added a comment - 14/Jun/09 07:08 PM
Committed a slightly modified version of David's last patch in r784604.

Other than minor javadoc/formatting changes to make checkstyle happy, I also made the shared source of randomness pluggable.

I am not 100% happy with the static randomGenerator attached to GeneticAlgorithm, though I understand and support the need to ensure reproducibility for some applications. Comments / suggestions for better ways to do this welcome.

Leaving open as we need to update the user guide to complete this.


Phil Steitz added a comment - 30/Jun/09 12:44 AM
User guide updated in r789511

Luc Maisonobe added a comment - 07/Aug/09 09:20 AM
closing resolved issue for 2.0 release