From: <sla...@us...> - 2008-08-11 16:15:45
|
Revision: 5235 http://octave.svn.sourceforge.net/octave/?rev=5235&view=rev Author: slackydeb Date: 2008-08-11 16:15:48 +0000 (Mon, 11 Aug 2008) Log Message: ----------- add fitscalingrank (but not using it); fix a serious bug in elitism in __ga_problem__ function caused by a previous commit; little improvements in __ga_problem__ function Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/fitscalingrank.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-11 06:20:22 UTC (rev 5234) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-11 16:15:48 UTC (rev 5235) @@ -1,6 +1,6 @@ Name: ga -Version: 0.6.0 -Date: 2008-08-10 +Version: 0.6.1 +Date: 2008-08-11 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-11 06:20:22 UTC (rev 5234) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-11 16:15:48 UTC (rev 5235) @@ -17,18 +17,20 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.13 +## Version: 4.14.2 function [x fval exitflag output population scores] = __ga_problem__ (problem) output.randstate = rand ("state"); output.randnstate = randn ("state"); state.StartTime = time (); - state.Population = __ga_set_initial_population__ (problem.nvars, - problem.fitnessfcn, - problem.options); + state.Population(1:problem.options.PopulationSize, 1:problem.nvars) = \ + __ga_set_initial_population__ (problem.nvars, + problem.fitnessfcn, + problem.options); - state.Score = __ga_scores__ (problem.fitnessfcn, state.Population); + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, state.Population); #TODO consider InitialScores #TODO write __ga_set_initial_scores__ #TODO delete __ga_calcola_img_fitnessfcn__ @@ -43,7 +45,7 @@ [trash IndexSortedScores] = sort (state.Score); popolazione_futura(1:problem.options.EliteCount, 1:problem.nvars) = \ - state.Population(1:problem.options.EliteCount, + state.Population(IndexSortedScores(1:problem.options.EliteCount, 1), 1:problem.nvars); %% in this while the individual of the new generation is fixed Added: trunk/octave-forge/main/ga/inst/fitscalingrank.m =================================================================== --- trunk/octave-forge/main/ga/inst/fitscalingrank.m (rev 0) +++ trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-11 16:15:48 UTC (rev 5235) @@ -0,0 +1,40 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn{Function File} {@var{expectation} =} fitscalingrank (@var{scores}, @var{nParents}) +## Convert the raw fitness scores that are returned by the fitness +## function to values in a range that is suitable for the selection +## function. +## +## @seealso{ga, gaoptimset} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0.2 + +function expectation = fitscalingrank (scores, nParents) + [nr nc] = size (scores); + assert (nc, 1); ## DEBUG + r(1, 1:nr) = ranks (scores); + expectation_wo_nParents(1, 1:nr) = arrayfun (@(n) 1 / sqrt (n), r); + expectation(1, 1:nr) = \ + (nParents / sum (expectation_wo_nParents)) * \ + expectation_wo_nParents; + assert (sum (expectation), nParents, 1e-9); ## DEBUG +endfunction \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |