Re: [jgap-users] BestChromosomesSelector and WeightedRouletteSelectorquestion
Brought to you by:
klausikm
From: Klaus M. <jg...@kl...> - 2009-12-22 14:17:47
|
Krzysztof, to your first question: In method add(IChromosome a_chromosomeToAdd), which has to be called before any selection can take place, the last line is: // Indicate that the list of chromosomes to add needs sorting. // ----------------------------------------------------------- m_needsSorting = true; By this, the sorting procedure is activated. Your second question regarding WeightedRouletteSelector: The number of spins is determined by the JGAP core. The method to do this is: public synchronized void selectChromosomes(int a_howManyToSelect, Population a_to_pop) {... } Best Klaus www.klaus-meffert.com <http://www.klaus-meffert.com/> _____ From: Krzysztof Chmielewski [mailto:krz...@gm...] Sent: Tuesday, December 22, 2009 3:02 AM To: jga...@li... Subject: [jgap-users] BestChromosomesSelector and WeightedRouletteSelectorquestion Hi everyone. Thank You very much for helping me in my last JGAP question/trouble :). Yet I have another question... this time I have some doubts about BestChromosomeSelector and WeightedRouletteSelector. In JGAP documentation we can reed that: "Implementation of a NaturalSelector that takes the top n chromosomes into the next generation. n can be specified. Which chromosomes are the best is decided by evaluating their fitness value." So I looked to the code of that class and DefaultConfiguration code, and there is something like that: DefaultConfiguration code: BestChromosomesSelector bestChromsSelector = new BestChromosomesSelector(this, 0.90d); BestChromosomesSelector code: public BestChromosomesSelector(final Configuration a_config, final double a_originalRate) throws InvalidConfigurationException { super(a_config); m_chromosomes = new Population(a_config); m_needsSorting = false; <- this part give me some doubts setDoubletteChromosomesAllowed(true); setOriginalRate(a_originalRate); m_fitnessValueComparator = new FitnessAgeValueComparator(); } m_needsSorting tells JGAP that, is there need to sort the incoming population by Fitness Value, right? Further in the BestChromosomeSelector ther is a function that select n chromosomes: public void selectChromosomes(final int a_howManyToSelect, Population a_to_pop) . .some code . // Sort the collection of chromosomes previously added for evaluation. // Only do this if necessary. // ------------------------------------------------------------------- if (m_needsSorting) { Collections.sort(m_chromosomes.getChromosomes(), m_fitnessValueComparator); m_needsSorting = false; } // To select a chromosome, we just go thru the sorted list. // -------------------------------------------------------- IChromosome selectedChromosome; for (int i = 0; i < canBeSelected; i++) { selectedChromosome = m_chromosomes.getChromosome(i); selectedChromosome.setIsSelectedForNextGeneration(true); a_to_pop.addChromosome(selectedChromosome); } . some other code . . But if we do not sort the list... we will not get TOP n chromosomes. We will get only first/last n chromosomes from the list. So why there is no m_deedsSorting = true in DefaultConfiguration , or why in BestChromosomesSelector code we have m_needsSorting = false? Where I can change this? My next question is about WeightedRouletteSelector. In JGAP documentation we can reed that: Then the wheel is spun again and again until the requested number of Chromosomes have been selected. But there is no parameter to determine the number of spun. The class constructors are: WeightedRouletteSelector(), and WeightedRouletteSelector(Configuration). So where I can set the number of spuns, where I can define how many chromosomes goes to next evolution. Ok, so going next... the basic calculation of number of slots (or probability of selection) in roulette wheel that each chromosome has is something like that: fitness_value_of_chromosome_i/sum(fitness_values_off_all_chromosomes). Is it something like that in JGAP WeightedRouletteSelector or is something different? Thank You for any help ;) Best Krzysztof |