[Quantproject-developers] QuantProject/b1_ADT/Optimizing/Genetic GeneticOptimizer.cs,1.8,1.9 GenomeM
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2005-07-31 20:03:40
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17771/b1_ADT/Optimizing/Genetic Modified Files: GeneticOptimizer.cs GenomeManagerTest.cs IGenomeManager.cs Log Message: Fixed bugs in GenomeManagerForEfficientPortfolio; - added new property CurrentGeneticOptimizer to the IGenomeManager interface; - added new public method CalculateRandomFitness() for a new computation of fitness (now the code this new computation of fitness has been remarked: if you want more details, please write to me) Index: GenomeManagerTest.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GenomeManagerTest.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GenomeManagerTest.cs 13 Jul 2005 16:37:04 -0000 1.3 --- GenomeManagerTest.cs 31 Jul 2005 20:03:31 -0000 1.4 *************** *** 37,40 **** --- 37,41 ---- private int minValueForGenes; private int maxValueForGenes; + private GeneticOptimizer currentGeneticOptimizer; public int GenomeSize *************** *** 53,56 **** --- 54,62 ---- } + public GeneticOptimizer CurrentGeneticOptimizer + { + get{return this.currentGeneticOptimizer;} + set{this.currentGeneticOptimizer = value;} + } public GenomeManagerTest(int genomeSize, int minValueForGenes, int maxValueForGenes) Index: GeneticOptimizer.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/GeneticOptimizer.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GeneticOptimizer.cs 27 Jul 2005 22:34:24 -0000 1.8 --- GeneticOptimizer.cs 31 Jul 2005 20:03:31 -0000 1.9 *************** *** 65,68 **** --- 65,71 ---- private int generationCounter; + private double averageRandomFitness; + private double standardDeviationOfRandomFitness; + #endregion *************** *** 131,134 **** --- 134,154 ---- get{return this.currentGeneration;} } + + /// <summary> + /// Average fitness of a group of genomes (this.numberOfGenomesForAverageRandomFitness) + /// chosen at random + /// </summary> + public double AverageRandomFitness + { + get{return this.averageRandomFitness;} + } + /// <summary> + /// Standard deviation of fitness of a group of genomes (this.numberOfGenomesForAverageRandomFitness) + /// chosen at random + /// </summary> + public double StandardDeviationOfRandomFitness + { + get{return this.standardDeviationOfRandomFitness;} + } #endregion *************** *** 207,212 **** --- 227,265 ---- eliteNumber); this.generationCounter = 1; + this.genomeManager.CurrentGeneticOptimizer = this; + } + + /// <summary> + /// It updates AverageRandomFitness and StandardDeviationOfRandomFitness + /// properties with the average and std dev fitness + /// of a given group of genomes chosen at random + /// </summary> + public void CalculateRandomFitness() + { + this.createFirstGeneration(false); + this.averageRandomFitness = this.totalFitness/this.currentGeneration.Count; + this.standardDeviationOfRandomFitness = this.calculateRandomFitness_getStdDevOfRandomFitness(); + } + /// <summary> + /// It updates StandardDeviationOfRandomFitness property with the std dev of + /// fitness of a given group of genomes chosen at random + /// </summary> + private double calculateRandomFitness_getStdDevOfRandomFitness() + { + double[] fitnesses = new double[this.currentGeneration.Count]; + for(int i = 0; i<this.currentGeneration.Count; i++) + fitnesses[i] = ((Genome)this.currentGeneration[i]).Fitness; + return QuantProject.ADT.Statistics.BasicFunctions.StdDev(fitnesses); } + private void run_calculateRandomFitness() + { + GeneticOptimizer GOForAverageRandomFitness = + new GeneticOptimizer(this.genomeManager, ConstantsProvider.NumGenomesForRandomFitnessComputation, + 0,ConstantsProvider.SeedForRandomGenerator); + GOForAverageRandomFitness.CalculateRandomFitness(); + this.averageRandomFitness = GOForAverageRandomFitness.AverageRandomFitness; + this.standardDeviationOfRandomFitness = GOForAverageRandomFitness.StandardDeviationOfRandomFitness; + } /// <summary> /// Method to start the GeneticOptmizer *************** *** 214,217 **** --- 267,271 ---- public void Run(bool showOutputToConsole) { + //this.run_calculateRandomFitness(); to be tested yet this.createFirstGeneration(showOutputToConsole); if(this.keepOnRunningUntilConvergenceIsReached) Index: IGenomeManager.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Optimizing/Genetic/IGenomeManager.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IGenomeManager.cs 1 Dec 2004 22:36:11 -0000 1.1 --- IGenomeManager.cs 31 Jul 2005 20:03:31 -0000 1.2 *************** *** 43,46 **** --- 43,47 ---- int MinValueForGenes{get;} int MaxValueForGenes{get;} + GeneticOptimizer CurrentGeneticOptimizer{get;set;} int GetNewGeneValue(Genome genome); // Used in generation of genes |