[Quantproject-developers] QuantProject/b1_ADT/Optimizing/Genetic GeneticOptimizer.cs, 1.18, 1.19
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2006-08-11 18:21:51
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv4044/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs Log Message: Back to previous version of IsConvergenceReached method. Plain fitness values (also negative) are used for computing convergence of current generation (just as before). Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** GeneticOptimizer.cs 10 Aug 2006 16:08:27 -0000 1.18 --- GeneticOptimizer.cs 11 Aug 2006 18:21:45 -0000 1.19 *************** *** 52,55 **** --- 52,56 ---- private int genomeSize; private double totalSpecialFitnessForRouletteSelection; + private double totalFitness; private Genome bestGenome; private Genome worstGenome; *************** *** 287,300 **** { bool returnValue = false; ! double averageSpecialFitness = this.totalSpecialFitnessForRouletteSelection / this.populationSize; ! double bestSpecialFitnessReachedUntilNow = this.BestGenome.Fitness + ! Math.Abs(((Genome)this.currentGeneration[0]).Fitness); ! ! if (averageSpecialFitness >= ! this.minConvergenceRate * bestSpecialFitnessReachedUntilNow ) returnValue = true; return returnValue; - } --- 288,297 ---- { bool returnValue = false; ! double averageFitness = this.totalFitness / this.populationSize; ! double bestFitnessReachedUntilNow = this.BestGenome.Fitness; ! if (averageFitness >= this.minConvergenceRate * bestFitnessReachedUntilNow ) returnValue = true; return returnValue; } *************** *** 308,312 **** this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration , this.generationCounter , this.generationNumber ) ); ! this.calculateTotalSpecialFitnessForRouletteSelection(); this.updateCumulativeSpecialFitnessListForRouletteSelection(); this.setInitialBestAndWorstGenomes(); --- 305,309 ---- this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration , this.generationCounter , this.generationNumber ) ); ! this.calculateTotalSpecialFitnessForRouletteSelectionAndPlainTotalFitness(); this.updateCumulativeSpecialFitnessListForRouletteSelection(); this.setInitialBestAndWorstGenomes(); *************** *** 320,326 **** string genes = ""; //System.Console.WriteLine("\n*_*_*_*_*_*_*_*_*_*_*\n\nGeneration " + this.generationCounter +"\n"); ! // string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! // "\\GenomesThroughoutGenerations.txt"; ! // System.IO.StreamWriter w = System.IO.File.AppendText(pathFile); for(int i = 0; i < this.populationSize; i++) { --- 317,323 ---- string genes = ""; //System.Console.WriteLine("\n*_*_*_*_*_*_*_*_*_*_*\n\nGeneration " + this.generationCounter +"\n"); ! string pathFile = System.Configuration.ConfigurationSettings.AppSettings["GenericArchive"] + ! "\\GenomesThroughoutGenerations.txt"; ! System.IO.StreamWriter w = System.IO.File.AppendText(pathFile); for(int i = 0; i < this.populationSize; i++) { *************** *** 328,345 **** foreach(int gene in ((Genome)this.currentGeneration[i]).Genes() ) genes = genes + " " + gene.ToString(); ! System.Console.WriteLine("\r\n" + this.GenerationCounter + " " + genomeNumber + " " + genes + " " + ! ((Genome)this.currentGeneration[i]).Fitness + " " + ! ((Genome)this.currentGeneration[i]).HasBeenChanged.ToString() + " " + ! ((Genome)this.currentGeneration[i]).HasBeenCloned.ToString() + " " + ! ((Genome)this.currentGeneration[i]).Generation); ! // w.Write("\r\n" + this.GenerationCounter + " " + genomeNumber + " " + genes + " " + // ((Genome)this.currentGeneration[i]).Fitness + " " + // ((Genome)this.currentGeneration[i]).HasBeenChanged.ToString() + " " + // ((Genome)this.currentGeneration[i]).HasBeenCloned.ToString() + " " + // ((Genome)this.currentGeneration[i]).Generation); genes = ""; } ! // w.Flush(); ! // w.Close(); //Console.WriteLine("Press enter key to continue ..."); //Console.ReadLine(); --- 325,343 ---- foreach(int gene in ((Genome)this.currentGeneration[i]).Genes() ) genes = genes + " " + gene.ToString(); ! // System.Console.WriteLine("\r\n" + this.GenerationCounter + " " + genomeNumber + " " + genes + " " + // ((Genome)this.currentGeneration[i]).Fitness + " " + // ((Genome)this.currentGeneration[i]).HasBeenChanged.ToString() + " " + // ((Genome)this.currentGeneration[i]).HasBeenCloned.ToString() + " " + // ((Genome)this.currentGeneration[i]).Generation); + w.Write("\r\n" + this.GenerationCounter + " " + genomeNumber + " " + genes + " " + + ((Genome)this.currentGeneration[i]).Fitness + " " + + ((Genome)this.currentGeneration[i]).HasBeenChanged.ToString() + " " + + ((Genome)this.currentGeneration[i]).HasBeenCloned.ToString() + " " + + ((Genome)this.currentGeneration[i]).Generation + " " + + this.BestGenome.Fitness); genes = ""; } ! w.Flush(); ! w.Close(); //Console.WriteLine("Press enter key to continue ..."); //Console.ReadLine(); *************** *** 380,392 **** /// <summary> /// Calculate total special fitness for current generation /// </summary> ! private void calculateTotalSpecialFitnessForRouletteSelection() { this.totalSpecialFitnessForRouletteSelection = 0.0; double worstSpecialFitnessForRouletteSelection = Math.Abs(((Genome)this.currentGeneration[0]).Fitness); foreach(Genome g in this.currentGeneration) ! this.totalSpecialFitnessForRouletteSelection += g.Fitness + ! worstSpecialFitnessForRouletteSelection; } --- 378,396 ---- /// <summary> /// Calculate total special fitness for current generation + /// and plain total fitness /// </summary> ! private void calculateTotalSpecialFitnessForRouletteSelectionAndPlainTotalFitness() { this.totalSpecialFitnessForRouletteSelection = 0.0; + this.totalFitness = 0.0; double worstSpecialFitnessForRouletteSelection = Math.Abs(((Genome)this.currentGeneration[0]).Fitness); foreach(Genome g in this.currentGeneration) ! { ! this.totalSpecialFitnessForRouletteSelection += g.Fitness + ! worstSpecialFitnessForRouletteSelection; ! this.totalFitness += g.Fitness; ! } ! } *************** *** 479,483 **** this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration , this.generationCounter , this.generationNumber ) ); ! this.calculateTotalSpecialFitnessForRouletteSelection(); this.updateCumulativeSpecialFitnessListForRouletteSelection(); --- 483,487 ---- this.NewGeneration( this , new NewGenerationEventArgs( this.currentGeneration , this.generationCounter , this.generationNumber ) ); ! this.calculateTotalSpecialFitnessForRouletteSelectionAndPlainTotalFitness(); this.updateCumulativeSpecialFitnessListForRouletteSelection(); |