From: <sla...@us...> - 2008-08-05 18:48:14
|
Revision: 5219 http://octave.svn.sourceforge.net/octave/?rev=5219&view=rev Author: slackydeb Date: 2008-08-05 18:48:21 +0000 (Tue, 05 Aug 2008) Log Message: ----------- clean gacreationuniform Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/gacreationuniform.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 14:58:20 UTC (rev 5218) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 18:48:21 UTC (rev 5219) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4.5 +Version: 0.4.6 Date: 2008-08-05 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/gacreationuniform.m =================================================================== --- trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-05 14:58:20 UTC (rev 5218) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-05 18:48:21 UTC (rev 5219) @@ -40,19 +40,38 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.1.1 +## Version: 4.2.6 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) - %options.PopulationSize - %options.InitialPopulation - %%options.InitialScores - %options.PopInitRange + [nr, nc] = size (options.PopInitRange); - %% aux variables - tmp_aux = options.PopInitRange; - lb = min (tmp_aux(1, 1), tmp_aux(2, 1)); - ub = max (tmp_aux(1, 1), tmp_aux(2, 1)); + if ((nr != 2) + ((nc != 1) && (nc != GenomeLength))) + print_usage (); #TODO to modify + endif - n_rows_aux = options.PopulationSize; - Population = ((ub - lb) * rand (n_rows_aux, GenomeLength)) + (lb * ones (n_rows_aux, GenomeLength)); -endfunction \ No newline at end of file + ## obtain a 2-by-GenomeLength LocalPopInitRange + LocalPopInitRange = options.PopInitRange; + if (nc == 1) + LocalPopInitRange = LocalPopInitRange * ones (1, GenomeLength); + endif + + LB = LocalPopInitRange(1, 1:GenomeLength); + UB = LocalPopInitRange(2, 1:GenomeLength); + + ## pseudocode + ## + ## Population = Delta * RandomPopulationBetween0And1 + Offset + Population = \ + ((ones (options.PopulationSize, 1) * (UB - LB)) .* \ + rand (options.PopulationSize, GenomeLength)) + \ + (ones (options.PopulationSize, 1) * LB); +endfunction + +%!test +%! GenomeLength = 2; +%! FitnessFcn = @rastriginsfcn; +%! options = gaoptimset (); +%! Population = gacreationuniform (GenomeLength, FitnessFcn, options); +%! [nr, nc] = size (Population); +%! assert (((nr == options.PopulationSize) && (nc == GenomeLength)), true); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |