From: <sla...@us...> - 2008-08-05 14:08:35
|
Revision: 5216 http://octave.svn.sourceforge.net/octave/?rev=5216&view=rev Author: slackydeb Date: 2008-08-05 14:08:44 +0000 (Tue, 05 Aug 2008) Log Message: ----------- clean the initialization of the population; initial support for the option InitialPopulation Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/gacreationuniform.m trunk/octave-forge/main/ga/inst/gaoptimset.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 12:24:46 UTC (rev 5215) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 14:08:44 UTC (rev 5216) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4.4 +Version: 0.4.5 Date: 2008-08-05 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-05 12:24:46 UTC (rev 5215) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-05 14:08:44 UTC (rev 5216) @@ -17,14 +17,15 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.1 +## Version: 4.1.1 function [x fval exitflag output population scores] = __ga_problem__ (problem) - individui_migliori = []; + popolazione = __ga_set_initial_population__ (problem); + #popolazione = problem.options.CreationFcn (problem.nvars, + # problem.fitnessfcn, + # problem.options); - popolazione = problem.options.CreationFcn (problem.nvars, problem.fitnessfcn, problem.options); - %% in this while, generation is fixed generazione = 1; individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); Added: trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m 2008-08-05 14:08:44 UTC (rev 5216) @@ -0,0 +1,63 @@ +## 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{Population} =} __ga_set_initial_population__ (@var{problem}) +## Create an initial population. +## +## @seealso{__ga_problem__} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0 + +function Population = __ga_set_initial_population__ (problem) + #TODO consider options.InitialScores + if (columns (problem.options.InitialPopulation) == 0) + Population = problem.options.CreationFcn (problem.nvars, \ + problem.fitnessfcn, \ + problem.options); + elseif (columns (problem.options.InitialPopulation) != problem.nvars) + error ("nonempty InitialPopulation must have 'number of variables' \ + columns"); + else ## columns (problem.options.InitialPopulation) == problem.nvars + + ## it is impossible to have a matrix with 0 rows and a positive + ## number of columns + if (rows (problem.options.InitialPopulation) > \ + problem.options.PopulationSize) + error ("nonempty InitialPopulation must have no more than \ + 'PopulationSize' rows"); + elseif (rows (problem.options.InitialPopulation) == \ + problem.options.PopulationSize) + Population = InitialPopulation; + else + + Population = \ + vertcat (InitialPopulation, + problem.options.CreationFcn (problem.nvars, + problem.fitnessfcn, + setfield (problem.options, + "PopulationSize", + problem.options.PopulationSize - rows (problem.options.InitialPopulation) + ) + ) + ); + endif + endif +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/gacreationuniform.m =================================================================== --- trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-05 12:24:46 UTC (rev 5215) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-05 14:08:44 UTC (rev 5216) @@ -40,9 +40,13 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.1.1 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) + %options.PopulationSize + %options.InitialPopulation + %%options.InitialScores + %options.PopInitRange %% aux variables tmp_aux = options.PopInitRange; Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-05 12:24:46 UTC (rev 5215) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-05 14:08:44 UTC (rev 5216) @@ -44,6 +44,7 @@ ## @item EliteCount ## @item FitnessLimit ## @item Generations +## @item InitialPopulation ## @item MutationFcn ## @item PopInitRange ## @item PopulationSize @@ -54,7 +55,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.3 +## Version: 4.3.1 function options = gaoptimset (varargin) if ((nargout != 1) || This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |