From: <sla...@us...> - 2008-08-10 17:40:11
|
Revision: 5233 http://octave.svn.sourceforge.net/octave/?rev=5233&view=rev Author: slackydeb Date: 2008-08-10 17:40:15 +0000 (Sun, 10 Aug 2008) Log Message: ----------- add TimeLimit option; clean __ga_stop__ function; clean __ga_calcola_img_fitnessfcn__ function and rename it to __ga_scores__; heavily modify __ga_problem__ function; move __ga_sort_ascend_population__.m script to doc/old_stuff/ folder Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_stop__.m trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m trunk/octave-forge/main/ga/inst/gaoptimset.m trunk/octave-forge/main/ga/inst/selectionroulette.m Added Paths: ----------- trunk/octave-forge/main/ga/doc/old_stuff/__ga_sort_ascend_population__.m trunk/octave-forge/main/ga/inst/__ga_scores__.m Removed Paths: ------------- trunk/octave-forge/main/ga/inst/__ga_calcola_img_fitnessfcn__.m trunk/octave-forge/main/ga/inst/__ga_sort_ascend_population__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-10 17:40:15 UTC (rev 5233) @@ -1,6 +1,6 @@ Name: ga -Version: 0.5.5 -Date: 2008-08-09 +Version: 0.6.0 +Date: 2008-08-10 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Copied: trunk/octave-forge/main/ga/doc/old_stuff/__ga_sort_ascend_population__.m (from rev 5232, trunk/octave-forge/main/ga/inst/__ga_sort_ascend_population__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__ga_sort_ascend_population__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__ga_sort_ascend_population__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -0,0 +1,30 @@ +## 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. + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.2 + +function sorted_population = __ga_sort_ascend_population__ (fitnessfcn, + popolazione) + + %% ordered images of the fitnessfcn on the population + [trash index] = sort (__ga_calcola_img_fitnessfcn__ (fitnessfcn, + popolazione)); + + sorted_population = popolazione(index, :); +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/__ga_sort_ascend_population__.m ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/octave-forge/main/ga/inst/__ga_calcola_img_fitnessfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_calcola_img_fitnessfcn__.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/__ga_calcola_img_fitnessfcn__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -1,31 +0,0 @@ -## 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. - -## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 - -function retval = __ga_calcola_img_fitnessfcn__ (fitnessfcn, population) - img_fitnessfcn = zeros (rows (population), 1); - - %% inside this for the individual is fixed - for i = 1:rows (population) - img_fitnessfcn (i) = fitnessfcn (population (i, :)); - endfor - - retval = img_fitnessfcn; -endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -17,31 +17,35 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.5.1 +## Version: 4.13 function [x fval exitflag output population scores] = __ga_problem__ (problem) - individui_migliori = []; + output.randstate = rand ("state"); + output.randnstate = randn ("state"); + state.StartTime = time (); + state.Population = __ga_set_initial_population__ (problem.nvars, problem.fitnessfcn, problem.options); - #TODO - #consider InitialScores for state structure - %% in this while, generation is fixed - state.Generation = 1; ## TODO initial generation should be 0 (for state structure) - individui_migliori(state.Generation, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, state.Population))(1, :); - while (! __ga_stop__ (problem, state.Population, state.Generation)) + state.Score = __ga_scores__ (problem.fitnessfcn, state.Population); + #TODO consider InitialScores + #TODO write __ga_set_initial_scores__ + #TODO delete __ga_calcola_img_fitnessfcn__ - %% doing this initialization here to make the variable - %% popolazione_futura visible at the end of the next while - popolazione_futura = zeros (problem.options.PopulationSize, - problem.nvars); + state.Generation = 0; + state.Best(state.Generation + 1, 1) = min (state.Score); - %% elitist selection - for i = 1:problem.options.EliteCount - popolazione_futura(i, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, state.Population))(i, :); - endfor + ## in this while, generation is fixed + while (! __ga_stop__ (problem, state)) + ## elitist selection + [trash IndexSortedScores] = sort (state.Score); + popolazione_futura(1:problem.options.EliteCount, + 1:problem.nvars) = \ + state.Population(1:problem.options.EliteCount, + 1:problem.nvars); + %% in this while the individual of the new generation is fixed for i = (1 + problem.options.EliteCount):problem.options.PopulationSize @@ -69,13 +73,13 @@ parent = state.Population(index_parent(1), :); ## start preparing state structure #DONE state.Population - #state.Score + #DONE state.Score #DONE state.Generation - #state.StartTime + #DONE state.StartTime #state.StopFlag #state.Selection #state.Expectation - #state.Best + #DONE state.Best #state.LastImprovement #state.LastImprovementTime #state.NonlinIneq @@ -93,9 +97,27 @@ endfor state.Population = popolazione_futura; + state.Score = __ga_scores__ (problem.fitnessfcn, state.Population); state.Generation++; - individui_migliori(state.Generation, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, state.Population))(1, :); + state.Best(state.Generation + 1, 1) = min (state.Score); endwhile - x = individui_migliori(state.Generation, :); + ## return variables + ## + [trash IndexMinScore] = min (state.Score); + x = state.Population(IndexMinScore, 1:problem.nvars); + + fval = problem.fitnessfcn (x); + + #TODO exitflag + + ## output.randstate and output.randnstate must be assigned at the + ## start of the algorithm + output.generations = state.Generation; + #TODO output (funccount, message, + #maxconstraint) + + population = state.Population; + + scores = state.Score; endfunction \ No newline at end of file Copied: trunk/octave-forge/main/ga/inst/__ga_scores__.m (from rev 5232, trunk/octave-forge/main/ga/inst/__ga_calcola_img_fitnessfcn__.m) =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -0,0 +1,28 @@ +## 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. + +## Author: Luca Favatella <sla...@gm...> +## Version: 4.0 + +function Scores = __ga_scores__ (fitnessfcn, Population) + [nr nc] = size (Population); + + for i = 1:nr + Scores(i, 1) = fitnessfcn (Population (i, 1:nc)); + endfor +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_scores__.m ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/octave-forge/main/ga/inst/__ga_sort_ascend_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_sort_ascend_population__.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/__ga_sort_ascend_population__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -1,30 +0,0 @@ -## 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. - -## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 - -function sorted_population = __ga_sort_ascend_population__ (fitnessfcn, - popolazione) - - %% ordered images of the fitnessfcn on the population - [trash index] = sort (__ga_calcola_img_fitnessfcn__ (fitnessfcn, - popolazione)); - - sorted_population = popolazione(index, :); -endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_stop__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -16,15 +16,27 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. +## -*- texinfo -*- +## @deftypefn{Function File} {@var{x} =} __ga_stop__ (@var{problem}, @var{state}) +## Determine whether the genetic algorithm should stop. +## +## @seealso{__ga_problem__} +## @end deftypefn + ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 5.0 -%% return true if the stop condition is reached, false otherwise -function retval = __ga_stop__ (problem, popolazione, generazione) - __ga_stop_aux1__ = (generazione >= problem.options.Generations); +function retval = __ga_stop__ (problem, state) + Generations = \ + (state.Generation >= problem.options.Generations); - %% in doc Matlab <= and not < is supposed - __ga_stop_aux2__ = (problem.fitnessfcn ((__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :)) <= problem.options.FitnessLimit); + TimeLimit = \ + ((time () - state.StartTime) >= problem.options.TimeLimit); - retval = (__ga_stop_aux1__ || __ga_stop_aux2__); + FitnessLimit = \ + (state.Best(state.Generation + 1, 1) <= problem.options.FitnessLimit); + + retval = (Generations || + TimeLimit || + FitnessLimit); endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.2 +## Version: 1.1.3 function default_options = __gaoptimset_default_options__ () default_options.CreationFcn = @gacreationuniform; @@ -50,7 +50,7 @@ #TODO write default selectionstochunif #default_options.StallGenLimit = 50; #default_options.StallTimeLimit = Inf; - #default_options.TimeLimit = Inf; + default_options.TimeLimit = Inf; #default_options.TolCon = 1e-6; #default_options.TolFun = 1e-6; #default_options.UseParallel = "never"; Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -49,13 +49,14 @@ ## @item PopInitRange ## @item PopulationSize ## @item SelectionFcn +## @item TimeLimit ## @end table ## ## @seealso{ga, gaoptimget} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.3.1 +## Version: 4.3.2 function options = gaoptimset (varargin) if ((nargout != 1) || Modified: trunk/octave-forge/main/ga/inst/selectionroulette.m =================================================================== --- trunk/octave-forge/main/ga/inst/selectionroulette.m 2008-08-09 18:57:32 UTC (rev 5232) +++ trunk/octave-forge/main/ga/inst/selectionroulette.m 2008-08-10 17:40:15 UTC (rev 5233) @@ -61,7 +61,7 @@ endfor %% ordered images of fitnessfcn on population - [trash index_img_fitnessfcn] = sort (__ga_calcola_img_fitnessfcn__ (fitnessfcn, popolazione)); + [trash index_img_fitnessfcn] = sort (__ga_scores__ (fitnessfcn, popolazione)); parents = [index_img_fitnessfcn(index_individui_scelti(1)), index_img_fitnessfcn(index_individui_scelti(2))]; 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. |