keeping the evolve() population size constant

View: New views
2 Messages — Rating Filter:   Alert me  

keeping the evolve() population size constant

by dave johnson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HI!  I'm loving JGAP.  It has been very helpful for some projects I've been working on.

I have a question concerning the ability to maintain a constant population size for the evolve() method.  I am concerned because according to the javadoc, my own examination of the source code, and empirical tests, the population size does not stay constant when I call the evolve() method on my Genotype population.

This is troubling because my BulkFitnessFunction evaluates the fitness of the chromosomes by running them through a tournament.  Unfortunately, the tournament runs in O(n!) time (running time grows based on the factorial of n, where n is the poulation size).  I am concerned because if I set my population size to 10, the evolve() method may end up calling my evaluate method of my BulkFitnessFunction with a population of 20 (or more) chromosomes.  The difference between 10! = 3628800 and 20! = 2432902008176640000 is enormous and makes running my tournament impossible -- especially if I want to evolve() my population more than once! ;)

Is there anything I can do (short of editing the source) to ensure that my population size will remain constant based on my configuration?  I have already tried using setKeepPopulationSizeConstant
(true) on my configuration.  I know I could also set my population size smaller to limit the size of the population sent to my evaluate() method, but that seems hackish.

Is there anything else I can try?  Maybe I am missing something?  Below is some sample code and output to demonstrate my issue.

Thanks in advance and keep up the great work!

From testGA.java:
public static void main(String[] args) throws InvalidConfigurationException {
    Configuration conf = new DefaultConfiguration();

    Gene[] sampleGenes = new Gene[CHROMOSOME_SIZE];
    for (int i = 0; i < CHROMOSOME_SIZE; i++) {
        sampleGenes[i] = new BooleanGene(conf);
    }

    Chromosome sampleChromosome = new Chromosome(conf, sampleGenes);
    conf.setSampleChromosome(sampleChromosome);
    conf.setPopulationSize(POPULATION_SIZE);
    conf.setKeepPopulationSizeConstant(true);
    conf.setBulkFitnessFunction(new MyBulkFitnessFunction());
    Genotype population = Genotype.randomInitialGenotype(conf);

    for (int i = 0; i < 5; i++) {
        System.out.println("Genotype population size: " + Integer.toString(population.getPopulation().size()));
        population.evolve();
    }
}

From MyBulkFitnessFunction.java:
public void evaluate(Population pop) {
    Configuration a_config = pop.getConfiguration();
       
    System.out.println("  Generation number: " + Integer.toString(a_config.getGenerationNr()));
    System.out.println("  Population size: " + Integer.toString(pop.size()));

}

Sample output:
Genotype population size: 10
  Generation number: 0
  Population size: 19
Genotype population size: 10
  Generation number: 1
  Population size: 21
Genotype population size: 10
  Generation number: 2
  Population size: 22
Genotype population size: 10
  Generation number: 3
  Population size: 20
Genotype population size: 10
  Generation number: 4
  Population size: 18


--
dave
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: keeping the evolve() population size constant

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dave,
 
after investigating into the issue, I get the following picture:
+ The population size stays constant at a certain point of time in evolution (what you called "genotype population size")
+ The population size varies regarding the input to the bulk fitness function (what you called "population size")
+ The number of chromosomes in the population given to the bulk fitness function, that are marked with operatedOn = 0, remains constant (at least this should be the case and some few manual tests showed - although not verified - that)
 
So, only the chromosomes that have a value > 0 as result of call to method operatedOn (of interface IChromosome) are new ones regarding the population. The other chromosomes are unchanged during the current evolution cycle.
 
I wonder if this information could be used to reduce the tournament size?
If not, then I offer the following solution:
Modify class GABreeder, so that the code block...
-- snip
    BulkFitnessFunction bulkFunction = a_conf.getBulkFitnessFunction();
    if (bulkFunction != null) {
     
/**@todo utilize jobs: bulk fitness function is not so important for a
       * prototype! */
      bulkFunction.evaluate(pop);
    }
-- snap
..is moved down after the next statement ("pop = applyNaturalSelectors(a_conf, pop, false);").
 
With your test program, the output then shows a constant population size of 10.
 
Should I add an option for executing the bulk function at the new position (with default set in a way that executes the bulk function as before)? Is it dangerous to execute the bulk function always in the new position?
 
Best
 


From: jgap-users-bounces@... [mailto:jgap-users-bounces@...] On Behalf Of dave johnson
Sent: Saturday, July 05, 2008 9:14 PM
To: jgap-users@...
Subject: [jgap-users] keeping the evolve() population size constant

HI!  I'm loving JGAP.  It has been very helpful for some projects I've been working on.

I have a question concerning the ability to maintain a constant population size for the evolve() method.  I am concerned because according to the javadoc, my own examination of the source code, and empirical tests, the population size does not stay constant when I call the evolve() method on my Genotype population.

This is troubling because my BulkFitnessFunction evaluates the fitness of the chromosomes by running them through a tournament.  Unfortunately, the tournament runs in O(n!) time (running time grows based on the factorial of n, where n is the poulation size).  I am concerned because if I set my population size to 10, the evolve() method may end up calling my evaluate method of my BulkFitnessFunction with a population of 20 (or more) chromosomes.  The difference between 10! = 3628800 and 20! = 2432902008176640000 is enormous and makes running my tournament impossible -- especially if I want to evolve() my population more than once! ;)

Is there anything I can do (short of editing the source) to ensure that my population size will remain constant based on my configuration?  I have already tried using setKeepPopulationSizeConstant
(true) on my configuration.  I know I could also set my population size smaller to limit the size of the population sent to my evaluate() method, but that seems hackish.

Is there anything else I can try?  Maybe I am missing something?  Below is some sample code and output to demonstrate my issue.

Thanks in advance and keep up the great work!

From testGA.java:
public static void main(String[] args) throws InvalidConfigurationException {
    Configuration conf = new DefaultConfiguration();

    Gene[] sampleGenes = new Gene[CHROMOSOME_SIZE];
    for (int i = 0; i < CHROMOSOME_SIZE; i++) {
        sampleGenes[i] = new BooleanGene(conf);
    }

    Chromosome sampleChromosome = new Chromosome(conf, sampleGenes);
    conf.setSampleChromosome(sampleChromosome);
    conf.setPopulationSize(POPULATION_SIZE);
    conf.setKeepPopulationSizeConstant(true);
    conf.setBulkFitnessFunction(new MyBulkFitnessFunction());
    Genotype population = Genotype.randomInitialGenotype(conf);

    for (int i = 0; i < 5; i++) {
        System.out.println("Genotype population size: " + Integer.toString(population.getPopulation().size()));
        population.evolve();
    }
}

From MyBulkFitnessFunction.java:
public void evaluate(Population pop) {
    Configuration a_config = pop.getConfiguration();
       
    System.out.println("  Generation number: " + Integer.toString(a_config.getGenerationNr()));
    System.out.println("  Population size: " + Integer.toString(pop.size()));

}

Sample output:
Genotype population size: 10
  Generation number: 0
  Population size: 19
Genotype population size: 10
  Generation number: 1
  Population size: 21
Genotype population size: 10
  Generation number: 2
  Population size: 22
Genotype population size: 10
  Generation number: 3
  Population size: 20
Genotype population size: 10
  Generation number: 4
  Population size: 18


--
dave

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users
LightInTheBox - Buy quality products at wholesale price