From: <sla...@us...> - 2008-07-27 12:41:38
|
Revision: 5202 http://octave.svn.sourceforge.net/octave/?rev=5202&view=rev Author: slackydeb Date: 2008-07-27 12:41:48 +0000 (Sun, 27 Jul 2008) Log Message: ----------- made ga tests working again; bug solved observing that a double precision number is always 64 bit long (not less) Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__bin2hex__.m trunk/octave-forge/main/ga/inst/__hex2bin__.m trunk/octave-forge/main/ga/inst/__num2bin__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-07-27 12:41:48 UTC (rev 5202) @@ -1,5 +1,5 @@ Name: ga -Version: 0.1.2 +Version: 0.2 Date: 2008-07-23 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/__bin2hex__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -29,13 +29,13 @@ ## ## @example ## __bin2hex__ (["1101110"; "1110"]) -## @result{} [6E; 0E] +## @result{} [6E; E] ## @end example ## @seealso{__hex2bin__, bin2dec, dec2hex} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.4 +## Version: 1.5 function h = __bin2hex__ (b) h = dec2hex (bin2dec (b)); @@ -43,4 +43,4 @@ %!assert (__bin2hex__ ("1101110"), "6E") -%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "0E"]) \ No newline at end of file +%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__hex2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} __hex2bin__ (@var{s}) +## @deftypefn {Function File} {} __hex2bin__ (@var{s}, @var{len}) ## Return the binary number corresponding to the hexadecimal number stored in the string @var{s}. For example, ## ## @example @@ -25,18 +25,33 @@ ## @result{} 1101110 ## @end example ## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}. +## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}, padded with leading zeros to the width of the largest value. ## ## @example ## __hex2bin__ (["6E"; "E"]) ## @result{} [1101110; 0001110] ## @end example +## +## The optional third argument, @var{len}, specifies the minimum +## number of digits in the result. + ## @seealso{__bin2hex__, hex2dec, dec2bin} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 +## Version: 1.7 -function b = __hex2bin__ (h) - b = dec2bin (hex2dec (h)); -endfunction \ No newline at end of file +function b = __hex2bin__ (h, len) + d = hex2dec (h); + + switch nargin + case {1} + b = dec2bin (d); + case {2} + b = dec2bin (d, len); + endswitch +endfunction + +%!assert (__hex2bin__ ("6E"), "1101110") + +%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__num2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -35,8 +35,13 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.2 +## Version: 1.4 function b = __num2bin__ (n) - b = __hex2bin__ (num2hex (n)); -endfunction \ No newline at end of file + ## a double precision number is always 64 bits long + b = __hex2bin__ (num2hex (n), 64); +endfunction + +%!assert (__num2bin__ (1), "0011111111110000000000000000000000000000000000000000000000000000") + +%!assert (__num2bin__ ([1; -3]), ["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-03 14:59:31
|
Revision: 5208 http://octave.svn.sourceforge.net/octave/?rev=5208&view=rev Author: slackydeb Date: 2008-08-03 14:59:41 +0000 (Sun, 03 Aug 2008) Log Message: ----------- moved the definition of a common function to test ga algorithms in a script file; modified ga.m to take advantage of it Modified Paths: -------------- trunk/octave-forge/main/ga/INDEX trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/INDEX =================================================================== --- trunk/octave-forge/main/ga/INDEX 2008-07-30 12:38:05 UTC (rev 5207) +++ trunk/octave-forge/main/ga/INDEX 2008-08-03 14:59:41 UTC (rev 5208) @@ -9,4 +9,5 @@ crossoversinglepoint gacreationuniform mutationsinglepoint - selectionroulette + rastriginsfcn + selectionroulette \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-07-30 12:38:05 UTC (rev 5207) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 14:59:41 UTC (rev 5208) @@ -44,7 +44,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 +## Version: 3.4 function x = ga (varargin) if ((nargout > 1) || (length (varargin) < 1) || (length (varargin) > 3)) @@ -67,6 +67,8 @@ endif endfunction +%!assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) + %!function retval = test_4_variabili (x) %! retval = 0; %! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); @@ -82,11 +84,6 @@ %!assert (ga (@test_rastriginsfcn_traslato, 2, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) -%!function retval = test_rastriginsfcn (x) -%! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); - -%!assert (ga (@test_rastriginsfcn, 2), [0, 0], 1e-6) - %!function retval = test_f_con_inf_minimi_locali (x) %! retval = (x ** 2) - (cos (2 * pi * x)) + 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-03 16:19:35
|
Revision: 5210 http://octave.svn.sourceforge.net/octave/?rev=5210&view=rev Author: slackydeb Date: 2008-08-03 16:19:44 +0000 (Sun, 03 Aug 2008) Log Message: ----------- removed gaoptimget function because it is almost unuseful and too difficult to mantain; modified all code not to use the removed function; bump version because of these changes 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/gacreationuniform.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 15:00:59 UTC (rev 5209) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 16:19:44 UTC (rev 5210) @@ -1,5 +1,5 @@ Name: ga -Version: 0.2.1 +Version: 0.3 Date: 2008-07-23 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-03 15:00:59 UTC (rev 5209) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-03 16:19:44 UTC (rev 5210) @@ -17,13 +17,13 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0 function x = __ga_problem__ (problem) individui_migliori = []; - popolazione = (gaoptimget (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; @@ -32,39 +32,33 @@ %% doing this initialization here to make the variable %% popolazione_futura visible at the end of the next while - popolazione_futura = zeros (gaoptimget (problem.options, - 'PopulationSize'), + popolazione_futura = zeros (problem.options.PopulationSize, problem.nvars); %% elitist selection - for i = 1:(gaoptimget (problem.options, 'EliteCount')) + for i = 1:problem.options.EliteCount popolazione_futura(i, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(i, :); endfor %% in this while the individual of the new generation is fixed - for i = (1 + (gaoptimget (problem.options, - 'EliteCount'))):(gaoptimget (problem.options, - 'PopulationSize')) + for i = (1 + problem.options.EliteCount):problem.options.PopulationSize %% stochastically choosing the genetic operator to apply aux_operatore = rand (); %% crossover - if (aux_operatore < gaoptimget (problem.options, - 'CrossoverFraction')) - index_parents = (gaoptimget (problem.options, - 'SelectionFcn')) (problem.fitnessfcn, - popolazione); - parents = [popolazione(index_parents(1), :); + if (aux_operatore < problem.options.CrossoverFraction) + index_parents = problem.options.SelectionFcn (problem.fitnessfcn, + popolazione); + parents = [popolazione(index_parents(1), :); popolazione(index_parents(2), :)]; - popolazione_futura(i, :) = gaoptimget (problem.options, 'CrossoverFcn') (parents); + popolazione_futura(i, :) = problem.options.CrossoverFcn (parents); - %% mutation + %% mutation else - index_parent = (gaoptimget (problem.options, - 'SelectionFcn')) (problem.fitnessfcn, - popolazione); - popolazione_futura(i, :) = (gaoptimget (problem.options, 'MutationFcn')) (popolazione(index_parent(1), :)); + index_parent = problem.options.SelectionFcn (problem.fitnessfcn, + popolazione); + popolazione_futura(i, :) = problem.options.MutationFcn (popolazione(index_parent(1), :)); endif endfor Modified: trunk/octave-forge/main/ga/inst/__ga_stop__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-03 15:00:59 UTC (rev 5209) +++ trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-03 16:19:44 UTC (rev 5210) @@ -17,15 +17,14 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0 %% return true if the stop condition is reached, false otherwise function retval = __ga_stop__ (problem, popolazione, generazione) - __ga_stop_aux1__ = (generazione >= gaoptimget (problem.options, - 'Generations')); + __ga_stop_aux1__ = (generazione >= problem.options.Generations); %% in doc Matlab <= and not < is supposed - __ga_stop_aux2__ = (problem.fitnessfcn ((__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :)) <= gaoptimget (problem.options, 'FitnessLimit')); + __ga_stop_aux2__ = (problem.fitnessfcn ((__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :)) <= problem.options.FitnessLimit); retval = (__ga_stop_aux1__ || __ga_stop_aux2__); 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-03 15:00:59 UTC (rev 5209) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-03 16:19:44 UTC (rev 5210) @@ -40,15 +40,15 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) %% aux variables - tmp_aux = gaoptimget (options, 'PopInitRange'); + tmp_aux = options.PopInitRange; lb = min (tmp_aux(1, 1), tmp_aux(2, 1)); ub = max (tmp_aux(1, 1), tmp_aux(2, 1)); - n_rows_aux = gaoptimget (options, 'PopulationSize'); + 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-03 19:03:52
|
Revision: 5211 http://octave.svn.sourceforge.net/octave/?rev=5211&view=rev Author: slackydeb Date: 2008-08-03 19:04:01 +0000 (Sun, 03 Aug 2008) Log Message: ----------- modifying interface of the ga function; it is no more possible to invoke something as ga (fitnessfcn, nvars, options) Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gaoptimset.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 19:04:01 UTC (rev 5211) @@ -1,6 +1,6 @@ Name: ga -Version: 0.3 -Date: 2008-07-23 +Version: 0.4 +Date: 2008-08-03 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-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -17,9 +17,9 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.1 -function x = __ga_problem__ (problem) +function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -44,26 +44,53 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.4 +## Version: 5.0 -function x = ga (varargin) - if ((nargout > 1) || (length (varargin) < 1) || (length (varargin) > 3)) +function [x fval exitflag output population scores] = ga (varargin) + if ((nargout > 6) || + (length (varargin) < 1) || + (length (varargin) == 3) || + (length (varargin) == 5) || + (length (varargin) == 7) || + (length (varargin) > 10)) print_usage (); else - switch (length (varargin)) - case (1) - problem = varargin{1}; - case (2) - problem.fitnessfcn = varargin{1}; - problem.nvars = varargin{2}; - problem.options = gaoptimset; - case (3) - problem.fitnessfcn = varargin{1}; - problem.nvars = varargin{2}; - problem.options = varargin{3}; - endswitch - x = __ga_problem__ (problem); + ## retrieve problem structure + if (length (varargin) == 1) + problem = varargin{1}; + else ## length (varargin) >= 2 + + ## set default options field + problem.options = gaoptimset; + + ## set fields specified + problem.fitnessfcn = varargin{1}; + problem.nvars = varargin{2}; + if (length (varargin) >= 4) + problem.Aineq = varargin{3}; + problem.Bineq = varargin{4}; + if (length (varargin) >= 6) + problem.Aeq = varargin{5}; + problem.Beq = varargin{6}; + if (length (varargin) >= 8) + problem.lb = varargin{7}; + problem.ub = varargin{8}; + if (length (varargin) >= 9) + problem.nonlcon = varargin{9}; + + ## if a custom options field is specified, overwrite the + ## default one + if (length (varargin) == 10) + problem.options = varargin{10}; + endif + endif + endif + endif + endif + endif + + [x fval exitflag output population scores] = __ga_problem__ (problem); endif endfunction @@ -75,21 +102,21 @@ %! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; %! retval += x(4) ** 2; -%!assert (ga (@test_4_variabili, 4, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) +%!assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) %!function retval = test_rastriginsfcn_traslato (t) %! min = [1, 0]; %! x = t - min; %! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%!assert (ga (@test_rastriginsfcn_traslato, 2, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) +%!assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) %!function retval = test_f_con_inf_minimi_locali (x) %! retval = (x ** 2) - (cos (2 * pi * x)) + 1; -%!assert (ga (@test_f_con_inf_minimi_locali, 1, gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) +%!assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) %!function retval = test_parabola (x) %! retval = x ** 2; -%!assert (ga (@test_parabola, 1, gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) \ No newline at end of file +%!assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -17,8 +17,7 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} gaoptimset -## @deftypefnx{Function File} {@var{options} =} gaoptimset +## @deftypefn{Function File} {@var{options} =} gaoptimset ## @deftypefnx{Function File} {@var{options} =} gaoptimset ('@var{param1}', @var{value1}, '@var{param2}', @var{value2}, @dots{}) ## Create genetic algorithm options structure. ## @@ -54,14 +53,11 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 +## Version: 3.4 function options = gaoptimset (varargin) - if (nargout == 0) - warning ("Should show a complete list of parameters with their arguments."); + if (nargout != 1) print_usage (); - elseif (nargout > 1) - print_usage (); else if (mod (length (varargin), 2) == 1) print_usage (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-03 20:22:19
|
Revision: 5212 http://octave.svn.sourceforge.net/octave/?rev=5212&view=rev Author: slackydeb Date: 2008-08-03 20:22:28 +0000 (Sun, 03 Aug 2008) Log Message: ----------- rewrote the ga function to be simpler; more fields added to the problem structure in the function ga Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gaoptimset.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 19:04:01 UTC (rev 5211) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 20:22:28 UTC (rev 5212) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4 +Version: 0.4.2 Date: 2008-08-03 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 19:04:01 UTC (rev 5211) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 20:22:28 UTC (rev 5212) @@ -44,52 +44,45 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.0 +## Version: 5.5 -function [x fval exitflag output population scores] = ga (varargin) +function [x, fval, exitflag, output, population, scores] = \ + ga (fitnessfcn_or_problem, + nvars, + A = [], b = [], + Aeq = [], beq = [], + LB = [], UB = [], + nonlcon = [], + options = gaoptimset) if ((nargout > 6) || - (length (varargin) < 1) || - (length (varargin) == 3) || - (length (varargin) == 5) || - (length (varargin) == 7) || - (length (varargin) > 10)) + (nargin < 1) || + (nargin == 3) || + (nargin == 5) || + (nargin == 7) || + (nargin > 10)) print_usage (); else ## retrieve problem structure - if (length (varargin) == 1) - problem = varargin{1}; - else ## length (varargin) >= 2 - - ## set default options field - problem.options = gaoptimset; - - ## set fields specified - problem.fitnessfcn = varargin{1}; - problem.nvars = varargin{2}; - if (length (varargin) >= 4) - problem.Aineq = varargin{3}; - problem.Bineq = varargin{4}; - if (length (varargin) >= 6) - problem.Aeq = varargin{5}; - problem.Beq = varargin{6}; - if (length (varargin) >= 8) - problem.lb = varargin{7}; - problem.ub = varargin{8}; - if (length (varargin) >= 9) - problem.nonlcon = varargin{9}; - - ## if a custom options field is specified, overwrite the - ## default one - if (length (varargin) == 10) - problem.options = varargin{10}; - endif - endif - endif - endif - endif + if (nargin == 1) + problem = fitnessfcn_or_problem; + else + problem.fitnessfcn = fitnessfcn_or_problem; + problem.nvars = nvars; + problem.Aineq = A; + problem.Bineq = b; + problem.Aeq = Aeq; + problem.Beq = beq; + problem.lb = LB; + problem.ub = UB; + problem.nonlcon = nonlcon; + problem.randstate = rand ("state"); + problem.randnstate = randn ("state"); + problem.solver = "ga"; + problem.options = options; endif + ## call the function that manages the problem structure [x fval exitflag output population scores] = __ga_problem__ (problem); endif endfunction Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 19:04:01 UTC (rev 5211) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 20:22:28 UTC (rev 5212) @@ -53,7 +53,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.4 +## Version: 3.6 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. |
From: <sla...@us...> - 2008-08-03 22:15:20
|
Revision: 5213 http://octave.svn.sourceforge.net/octave/?rev=5213&view=rev Author: slackydeb Date: 2008-08-03 22:15:29 +0000 (Sun, 03 Aug 2008) Log Message: ----------- doc of functions ga and gaoptimset improved; gaoptimset reviewed and splitted in 2 functions Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gaoptimset.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 20:22:28 UTC (rev 5212) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 22:15:29 UTC (rev 5213) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4.2 +Version: 0.4.3 Date: 2008-08-03 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 20:22:28 UTC (rev 5212) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 22:15:29 UTC (rev 5213) @@ -18,33 +18,63 @@ ## -*- texinfo -*- ## @deftypefn{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}) -## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{options}) +## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}) +## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}) +## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}) +## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}, @var{nonlcon}) +## @deftypefnx{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}, @var{nonlcon}, @var{options}) ## @deftypefnx{Function File} {@var{x} =} ga (@var{problem}) +## @deftypefnx{Function File} {[@var{x}, @var{fval}] =} ga (@dots{}) +## @deftypefnx{Function File} {[@var{x}, @var{fval}, @var{exitflag}] =} ga (@dots{}) +## @deftypefnx{Function File} {[@var{x}, @var{fval}, @var{exitflag}, @var{output}] =} ga (@dots{}) +## @deftypefnx{Function File} {[@var{x}, @var{fval}, @var{exitflag}, @var{output}, @var{population}] =} ga (@dots{}) +## @deftypefnx{Function File} {[@var{x}, @var{fval}, @var{exitflag}, @var{output}, @var{population}, @var{scores}] =} ga (@dots{}) ## Find minimum of function using genetic algorithm. ## ## @strong{Inputs} ## @table @var ## @item fitnessfcn -## The objective function to minimize. It accepts a vector @var{x} of size 1-by-@var{nvars}, and returns a scalar evaluated at @var{x}. +## The objective function to minimize. It accepts a vector @var{x} of +## size 1-by-@var{nvars}, and returns a scalar evaluated at @var{x}. ## @item nvars -## The number of variables of @var{fitnessfcn}. +## The dimension (number of design variables) of @var{fitnessfcn}. ## @item options -## The structure of the optimization parameters; can be created with using the @code{gaoptimset} function. If not specified, @code{ga} minimizes with the default optimization parameters. +## The structure of the optimization parameters; can be created using +## the @code{gaoptimset} function. If not specified, @code{ga} minimizes +## with the default optimization parameters. ## @item problem -## A structure containing the following fields: @var{fitnessfcn}, @var{nvars} and @var{options}. +## A structure containing the following fields: +## @itemize @bullet +## @item @code{fitnessfcn} +## @item @code{nvars} +## @item @code{Aineq} +## @item @code{Bineq} +## @item @code{Aeq} +## @item @code{Beq} +## @item @code{lb} +## @item @code{ub} +## @item @code{nonlcon} +## @item @code{randstate} +## @item @code{randnstate} +## @item @code{solver} +## @item @code{options} +## @end itemize ## @end table ## ## @strong{Outputs} ## @table @var ## @item x -## The local unconstrained found minimum to the objective function. +## The local unconstrained found minimum to the objective function, +## @var{fitnessfcn}. +## @item fval +## The value of the fitness function at @var{x}. ## @end table ## ## @seealso{gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.5 +## Version: 5.8 function [x, fval, exitflag, output, population, scores] = \ ga (fitnessfcn_or_problem, @@ -53,7 +83,7 @@ Aeq = [], beq = [], LB = [], UB = [], nonlcon = [], - options = gaoptimset) + options = gaoptimset ()) if ((nargout > 6) || (nargin < 1) || (nargin == 3) || Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 20:22:28 UTC (rev 5212) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 22:15:29 UTC (rev 5213) @@ -32,7 +32,8 @@ ## @strong{Outputs} ## @table @var ## @item options -## The options structure. +## Structure that contains the options, or parameters, for the generic +## algorithm. ## @end table ## ## @strong{Options} @@ -53,97 +54,85 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.6 +## Version: 4.0 function options = gaoptimset (varargin) - if (nargout != 1) + if ((nargout != 1) || + (mod (length (varargin), 2) == 1)) print_usage (); else - if (mod (length (varargin), 2) == 1) - print_usage (); - else - %% defining a default_options structure with all default fields - default_options.CreationFcn = @gacreationuniform; - default_options.CrossoverFcn = @crossoverscattered; - default_options.CrossoverFraction = 0.8; - default_options.EliteCount = 2; - default_options.FitnessLimit = -Inf; - default_options.Generations = 100; - default_options.MutationFcn = @mutationsinglepoint; %% TODO: gaussian - default_options.PopInitRange = [0; 1]; - default_options.PopulationSize = 20; - default_options.SelectionFcn = @selectionroulette; %% TODO: stochunif - %% setting the return variable options as the parameters specified in - %% the input of the function - i = 1; - while (length (varargin) >= (i + 1)) - switch (varargin{i}) - case 'CreationFcn' - options.CreationFcn = varargin{i + 1}; - case 'CrossoverFcn' - options.CrossoverFcn = varargin{i + 1}; - case 'CrossoverFraction' - options.CrossoverFraction = varargin{i + 1}; - case 'EliteCount' - options.EliteCount = varargin{i + 1}; - case 'FitnessLimit' - options.FitnessLimit = varargin{i + 1}; - case 'Generations' - options.Generations = varargin{i + 1}; - case 'MutationFcn' - options.MutationFcn = varargin{i + 1}; - case 'PopInitRange' - options.PopInitRange = varargin{i + 1}; - case 'PopulationSize' - options.PopulationSize = varargin{i + 1}; - case 'SelectionFcn' - options.SelectionFcn = varargin{i + 1}; - endswitch - i = i + 2; - endwhile + ## structure with all default fields + default_options = __gaoptimset_default_options__ (); - %% setting default parameters that are not set - if ((! exist ('options', 'var')) || - (! isfield (options, 'CreationFcn'))) - options.CreationFcn = default_options.CreationFcn; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'CrossoverFcn'))) - options.CrossoverFcn = default_options.CrossoverFcn; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'CrossoverFraction'))) - options.CrossoverFraction = default_options.CrossoverFraction; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'EliteCount'))) - options.EliteCount = default_options.EliteCount; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'FitnessLimit'))) - options.FitnessLimit = default_options.FitnessLimit; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'Generations'))) - options.Generations = default_options.Generations; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'MutationFcn'))) - options.MutationFcn = default_options.MutationFcn; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'PopInitRange'))) - options.PopInitRange = default_options.PopInitRange; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'PopulationSize'))) - options.PopulationSize = default_options.PopulationSize; - endif - if ((! exist ('options', 'var')) || - (! isfield (options, 'SelectionFcn'))) - options.SelectionFcn = default_options.SelectionFcn; - endif + ## set options as specified + i = 1; + while (length (varargin) >= (i + 1)) + switch (varargin{i}) + case "CreationFcn" + options.CreationFcn = varargin{i + 1}; + case "CrossoverFcn" + options.CrossoverFcn = varargin{i + 1}; + case "CrossoverFraction" + options.CrossoverFraction = varargin{i + 1}; + case "EliteCount" + options.EliteCount = varargin{i + 1}; + case "FitnessLimit" + options.FitnessLimit = varargin{i + 1}; + case "Generations" + options.Generations = varargin{i + 1}; + case "MutationFcn" + options.MutationFcn = varargin{i + 1}; + case "PopInitRange" + options.PopInitRange = varargin{i + 1}; + case "PopulationSize" + options.PopulationSize = varargin{i + 1}; + case "SelectionFcn" + options.SelectionFcn = varargin{i + 1}; + endswitch + i = i + 2; + endwhile + + ## set not specified options at default values + if ((! exist ("options", "var")) || + (! isfield (options, 'CreationFcn'))) + options.CreationFcn = default_options.CreationFcn; endif + if ((! exist ("options", "var")) || + (! isfield (options, 'CrossoverFcn'))) + options.CrossoverFcn = default_options.CrossoverFcn; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'CrossoverFraction'))) + options.CrossoverFraction = default_options.CrossoverFraction; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'EliteCount'))) + options.EliteCount = default_options.EliteCount; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'FitnessLimit'))) + options.FitnessLimit = default_options.FitnessLimit; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'Generations'))) + options.Generations = default_options.Generations; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'MutationFcn'))) + options.MutationFcn = default_options.MutationFcn; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'PopInitRange'))) + options.PopInitRange = default_options.PopInitRange; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'PopulationSize'))) + options.PopulationSize = default_options.PopulationSize; + endif + if ((! exist ("options", "var")) || + (! isfield (options, 'SelectionFcn'))) + options.SelectionFcn = default_options.SelectionFcn; + endif endif 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. |
From: <sla...@us...> - 2008-08-05 12:24:37
|
Revision: 5215 http://octave.svn.sourceforge.net/octave/?rev=5215&view=rev Author: slackydeb Date: 2008-08-05 12:24:46 +0000 (Tue, 05 Aug 2008) Log Message: ----------- semplified the code Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gaoptimset.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 10:23:22 UTC (rev 5214) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 12:24:46 UTC (rev 5215) @@ -1,6 +1,6 @@ Name: ga -Version: 0.4.3 -Date: 2008-08-03 +Version: 0.4.4 +Date: 2008-08-05 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-05 10:23:22 UTC (rev 5214) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-05 12:24:46 UTC (rev 5215) @@ -74,7 +74,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.8 +## Version: 5.8.1 function [x, fval, exitflag, output, population, scores] = \ ga (fitnessfcn_or_problem, @@ -117,16 +117,18 @@ endif endfunction -%!assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) +%!function retval = test_parabola (x) +%! retval = x ** 2; -%!function retval = test_4_variabili (x) -%! retval = 0; -%! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; -%! retval += x(4) ** 2; +%!assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) -%!assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) +%!function retval = test_f_con_inf_minimi_locali (x) +%! retval = (x ** 2) - (cos (2 * pi * x)) + 1; +%!assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) + +%!assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) + %!function retval = test_rastriginsfcn_traslato (t) %! min = [1, 0]; %! x = t - min; @@ -134,12 +136,10 @@ %!assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) -%!function retval = test_f_con_inf_minimi_locali (x) -%! retval = (x ** 2) - (cos (2 * pi * x)) + 1; +%!function retval = test_4_variabili (x) +%! retval = 0; +%! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); +%! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; +%! retval += x(4) ** 2; -%!assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) - -%!function retval = test_parabola (x) -%! retval = x ** 2; - -%!assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) \ No newline at end of file +%!assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-05 10:23:22 UTC (rev 5214) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-05 12:24:46 UTC (rev 5215) @@ -54,7 +54,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.3 function options = gaoptimset (varargin) if ((nargout != 1) || @@ -62,77 +62,20 @@ print_usage (); else - ## structure with all default fields - default_options = __gaoptimset_default_options__ (); + ## initialize the return variable to a structure with all parameters + ## set to their default value + options = __gaoptimset_default_options__ (); - ## set options as specified - i = 1; - while (length (varargin) >= (i + 1)) - switch (varargin{i}) - case "CreationFcn" - options.CreationFcn = varargin{i + 1}; - case "CrossoverFcn" - options.CrossoverFcn = varargin{i + 1}; - case "CrossoverFraction" - options.CrossoverFraction = varargin{i + 1}; - case "EliteCount" - options.EliteCount = varargin{i + 1}; - case "FitnessLimit" - options.FitnessLimit = varargin{i + 1}; - case "Generations" - options.Generations = varargin{i + 1}; - case "MutationFcn" - options.MutationFcn = varargin{i + 1}; - case "PopInitRange" - options.PopInitRange = varargin{i + 1}; - case "PopulationSize" - options.PopulationSize = varargin{i + 1}; - case "SelectionFcn" - options.SelectionFcn = varargin{i + 1}; - endswitch + ## set custom options + for i = 1:2:length (varargin) + param = varargin{i}; + value = varargin{i + 1}; + if (! isfield (options, param)) + error ("wrong parameter"); + else + options = setfield (options, param, value); + endif i = i + 2; - endwhile - - ## set not specified options at default values - if ((! exist ("options", "var")) || - (! isfield (options, 'CreationFcn'))) - options.CreationFcn = default_options.CreationFcn; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'CrossoverFcn'))) - options.CrossoverFcn = default_options.CrossoverFcn; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'CrossoverFraction'))) - options.CrossoverFraction = default_options.CrossoverFraction; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'EliteCount'))) - options.EliteCount = default_options.EliteCount; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'FitnessLimit'))) - options.FitnessLimit = default_options.FitnessLimit; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'Generations'))) - options.Generations = default_options.Generations; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'MutationFcn'))) - options.MutationFcn = default_options.MutationFcn; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'PopInitRange'))) - options.PopInitRange = default_options.PopInitRange; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'PopulationSize'))) - options.PopulationSize = default_options.PopulationSize; - endif - if ((! exist ("options", "var")) || - (! isfield (options, 'SelectionFcn'))) - options.SelectionFcn = default_options.SelectionFcn; - endif + endfor endif 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. |
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. |
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. |
From: <sla...@us...> - 2008-08-05 20:48:47
|
Revision: 5222 http://octave.svn.sourceforge.net/octave/?rev=5222&view=rev Author: slackydeb Date: 2008-08-05 20:48:56 +0000 (Tue, 05 Aug 2008) Log Message: ----------- fix interface in Crossoverfcn calls and functions Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 19:03:27 UTC (rev 5221) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 20:48:56 UTC (rev 5222) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4.6 +Version: 0.4.7 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 19:03:27 UTC (rev 5221) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-05 20:48:56 UTC (rev 5222) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.1.2 +## Version: 4.2 function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; @@ -50,7 +50,13 @@ popolazione); parents = [popolazione(index_parents(1), :); popolazione(index_parents(2), :)]; - popolazione_futura(i, :) = problem.options.CrossoverFcn (parents); + popolazione_futura(i, :) = \ + problem.options.CrossoverFcn (parents, + problem.options, + problem.nvars, + problem.fitnessfcn, + false, ## unused + popolazione); %% mutation else Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-05 19:03:27 UTC (rev 5221) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-05 20:48:56 UTC (rev 5222) @@ -17,19 +17,18 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}) +## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}, @var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) ## Combine two individuals, or parents, to form a crossover child. ## ## @seealso{ga, gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0 - % different signature from MATLAB - % because of a problem of function - % handle (retry if more spare time) -function xoverKids = crossoverscattered (parents) +function xoverKids = \ + crossoverscattered (parents, + options, nvars, FitnessFcn, unused, thisPopulation) concatenated_parents = [(__ga_doubles2concatenated_bitstring__ \ (parents(1, :))); \ (__ga_doubles2concatenated_bitstring__ \ Modified: trunk/octave-forge/main/ga/inst/crossoversinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-05 19:03:27 UTC (rev 5221) +++ trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-05 20:48:56 UTC (rev 5222) @@ -17,19 +17,18 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoversinglepoint (@var{parents}) +## @deftypefn{Function File} {@var{xoverKids} =} crossoversinglepoint (@var{parents}, @var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) ## Combine two individuals, or parents, to form a crossover child. ## ## @seealso{ga, gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0 - % different signature from MATLAB - % because of a problem of function - % handle (retry if more spare time) -function xoverKids = crossoversinglepoint (parents) +function xoverKids = \ + crossoversinglepoint (parents, + options, nvars, FitnessFcn, unused, thisPopulation) %% constants N_BIT_DOUBLE = 64; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-05 21:14:04
|
Revision: 5223 http://octave.svn.sourceforge.net/octave/?rev=5223&view=rev Author: slackydeb Date: 2008-08-05 21:14:13 +0000 (Tue, 05 Aug 2008) Log Message: ----------- fix interface in MutationFcn call and function Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m trunk/octave-forge/main/ga/inst/mutationsinglepoint.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 20:48:56 UTC (rev 5222) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 21:14:13 UTC (rev 5223) @@ -1,5 +1,5 @@ Name: ga -Version: 0.4.7 +Version: 0.4.8 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 20:48:56 UTC (rev 5222) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-05 21:14:13 UTC (rev 5223) @@ -62,7 +62,15 @@ else index_parent = problem.options.SelectionFcn (problem.fitnessfcn, popolazione); - popolazione_futura(i, :) = problem.options.MutationFcn (popolazione(index_parent(1), :)); + parent = popolazione(index_parent(1), :); + popolazione_futura(i, :) = \ #TODO parent -> parents + problem.options.MutationFcn (parent, + problem.options, + problem.nvars, + problem.fitnessfcn, + false, #TODO false -> state + false, #TODO false -> thisScore + popolazione); endif endfor Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-05 20:48:56 UTC (rev 5222) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-05 21:14:13 UTC (rev 5223) @@ -17,18 +17,19 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}, @var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) +## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) ## Combine two individuals, or parents, to form a crossover child. ## ## @seealso{ga, gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.0.2 function xoverKids = \ crossoverscattered (parents, - options, nvars, FitnessFcn, unused, thisPopulation) + options, nvars, FitnessFcn, unused, + thisPopulation) concatenated_parents = [(__ga_doubles2concatenated_bitstring__ \ (parents(1, :))); \ (__ga_doubles2concatenated_bitstring__ \ Modified: trunk/octave-forge/main/ga/inst/crossoversinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-05 20:48:56 UTC (rev 5222) +++ trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-05 21:14:13 UTC (rev 5223) @@ -17,18 +17,19 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoversinglepoint (@var{parents}, @var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) +## @deftypefn{Function File} {@var{xoverKids} =} crossoversinglepoint (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) ## Combine two individuals, or parents, to form a crossover child. ## ## @seealso{ga, gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.0.2 function xoverKids = \ crossoversinglepoint (parents, - options, nvars, FitnessFcn, unused, thisPopulation) + options, nvars, FitnessFcn, unused, + thisPopulation) %% constants N_BIT_DOUBLE = 64; Modified: trunk/octave-forge/main/ga/inst/mutationsinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationsinglepoint.m 2008-08-05 20:48:56 UTC (rev 5222) +++ trunk/octave-forge/main/ga/inst/mutationsinglepoint.m 2008-08-05 21:14:13 UTC (rev 5223) @@ -17,16 +17,20 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{mutationChildren} =} mutationsinglepoint (@var{parent}) +## @deftypefn{Function File} {@var{mutationChildren} =} mutationsinglepoint (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{state}, @var{thisScore}, @var{thisPopulation}) ## Single point mutation. ## ## @seealso{ga, gaoptimset} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.2 +## Version: 4.0.1 -function mutationChildren = mutationsinglepoint (parent) +function mutationChildren = \ + mutationsinglepoint (parents, + options, nvars, FitnessFcn, state, + thisScore, thisPopulation) + parent = parents; %% constants N_BIT_DOUBLE = 64; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-07 07:34:25
|
Revision: 5224 http://octave.svn.sourceforge.net/octave/?rev=5224&view=rev Author: slackydeb Date: 2008-08-07 07:34:34 +0000 (Thu, 07 Aug 2008) Log Message: ----------- changed meaning of crossoverscattered Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/gacreationuniform.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-05 21:14:13 UTC (rev 5223) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 07:34:34 UTC (rev 5224) @@ -1,6 +1,6 @@ Name: ga -Version: 0.4.8 -Date: 2008-08-05 +Version: 0.4.9 +Date: 2008-08-07 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-05 21:14:13 UTC (rev 5223) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-07 07:34:34 UTC (rev 5224) @@ -24,25 +24,33 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0.2 +## Version: 5.0.1 function xoverKids = \ crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation) - concatenated_parents = [(__ga_doubles2concatenated_bitstring__ \ - (parents(1, :))); \ - (__ga_doubles2concatenated_bitstring__ \ - (parents(2, :)))]; - %% crossover scattered - tmp = concatenated_parents(1, :); - for i = 1:length (tmp) - if (rand () < 0.5) - tmp(1, i) = concatenated_parents(2, i); - endif - endfor - concatenated_xoverKids = tmp; + ## example + ## p1 = [varA varB varC varD] + ## p2 = [var1 var2 var3 var4] + ## b = [1 1 0 1] + ## child1 = [varA varB var3 varD] + p1 = parents (1, 1:nvars); + p2 = parents (2, 1:nvars); + b = fix (rand (1, nvars) + + 0.5 * ones (1, nvars)); + child1 = b .* p1 + (ones (1, nvars) - b) .* p2; - xoverKids = __ga_concatenated_bitstring2doubles__ (concatenated_xoverKids); -endfunction \ No newline at end of file + xoverKids = child1; +endfunction + +%!test +%! parents = [0 4.3 51 -6; 3 -34 5 64.212]; +%! options = gaoptimset (); +%! nvars = 4; +%! FitnessFcn = @rastriginsfcn; +%! unused = false; +%! thisPopulation = false; ## this parameter is unused in the current implementation +%! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); +%! assert (size (xoverKids), [1, nvars]); \ 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 21:14:13 UTC (rev 5223) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-07 07:34:34 UTC (rev 5224) @@ -40,7 +40,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.2.8 +## Version: 4.3 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) [nr, nc] = size (options.PopInitRange); @@ -73,5 +73,4 @@ %! 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 +%! assert (size (Population), [options.PopulationSize, GenomeLength]); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-07 07:39:03
|
Revision: 5225 http://octave.svn.sourceforge.net/octave/?rev=5225&view=rev Author: slackydeb Date: 2008-08-07 07:39:10 +0000 (Thu, 07 Aug 2008) Log Message: ----------- move gaoptimget function outside the inst directory because at the moment it is not mantained Added Paths: ----------- trunk/octave-forge/main/ga/doc/old_stuff/ trunk/octave-forge/main/ga/doc/old_stuff/__gaoptimget__.m Removed Paths: ------------- trunk/octave-forge/main/ga/inst/__gaoptimget__.m Copied: trunk/octave-forge/main/ga/doc/old_stuff/__gaoptimget__.m (from rev 5223, trunk/octave-forge/main/ga/inst/__gaoptimget__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__gaoptimget__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__gaoptimget__.m 2008-08-07 07:39:10 UTC (rev 5225) @@ -0,0 +1,56 @@ +## 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{val} =} gaoptimget (@var{options}, '@var{name}') +## Return the value of the parameter @var{name} from the genetic algorithm options structure. +## +## @seealso{gaoptimset} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.3 + +function val = gaoptimget (options, name) + if (nargin != 2) + print_usage (); + else + switch (name) + case 'CreationFcn' + val = options.CreationFcn; + case 'CrossoverFcn' + val = options.CrossoverFcn; + case 'CrossoverFraction' + val = options.CrossoverFraction; + case 'EliteCount' + val = options.EliteCount; + case 'FitnessLimit' + val = options.FitnessLimit; + case 'Generations' + val = options.Generations; + case 'MutationFcn' + val = options.MutationFcn; + case 'PopInitRange' + val = options.PopInitRange; + case 'PopulationSize' + val = options.PopulationSize; + case 'SelectionFcn' + val = options.SelectionFcn; + endswitch + endif +endfunction \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__gaoptimget__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__gaoptimget__.m 2008-08-07 07:34:34 UTC (rev 5224) +++ trunk/octave-forge/main/ga/inst/__gaoptimget__.m 2008-08-07 07:39:10 UTC (rev 5225) @@ -1,56 +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. - -## -*- texinfo -*- -## @deftypefn{Function File} {@var{val} =} gaoptimget (@var{options}, '@var{name}') -## Return the value of the parameter @var{name} from the genetic algorithm options structure. -## -## @seealso{gaoptimset} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 - -function val = gaoptimget (options, name) - if (nargin != 2) - print_usage (); - else - switch (name) - case 'CreationFcn' - val = options.CreationFcn; - case 'CrossoverFcn' - val = options.CrossoverFcn; - case 'CrossoverFraction' - val = options.CrossoverFraction; - case 'EliteCount' - val = options.EliteCount; - case 'FitnessLimit' - val = options.FitnessLimit; - case 'Generations' - val = options.Generations; - case 'MutationFcn' - val = options.MutationFcn; - case 'PopInitRange' - val = options.PopInitRange; - case 'PopulationSize' - val = options.PopulationSize; - case 'SelectionFcn' - val = options.SelectionFcn; - endswitch - endif -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. |
From: <sla...@us...> - 2008-08-07 08:36:33
|
Revision: 5226 http://octave.svn.sourceforge.net/octave/?rev=5226&view=rev Author: slackydeb Date: 2008-08-07 08:36:41 +0000 (Thu, 07 Aug 2008) Log Message: ----------- clean crossover functions; bumped version because of new dependency on communications package, to use the randint function Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m Removed Paths: ------------- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 08:36:41 UTC (rev 5226) @@ -1,12 +1,12 @@ Name: ga -Version: 0.4.9 +Version: 0.5.0 Date: 2008-08-07 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Description: Genetic optimization code Categories: Optimization -Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.6) +Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.6), communications (>= 1.0.0) Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net Deleted: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -1,39 +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.3 - -function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) - - %% constants - N_BIT_DOUBLE = 64; - - %% aux variable - nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; - - %% obtaining the son of the bitstring - tmp1 = zeros (1, nvars); - for i = 1:nvars - tmp_aux = (i - 1) * N_BIT_DOUBLE; - tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): - (tmp_aux + N_BIT_DOUBLE))); - endfor - - doubles = tmp1; -endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -0,0 +1,39 @@ +## 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.3 + +function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) + + %% constants + N_BIT_DOUBLE = 64; + + %% aux variable + nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; + + %% obtaining the son of the bitstring + tmp1 = zeros (1, nvars); + for i = 1:nvars + tmp_aux = (i - 1) * N_BIT_DOUBLE; + tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): + (tmp_aux + N_BIT_DOUBLE))); + endfor + + doubles = tmp1; +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -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.3 - -function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) - - %% bitstring obtained concating the bitstrings of the single variables - tmp1 = __num2bin__ (doubles(1)); - for i = 2:length(doubles) %% 2:1 is an empty matrix - tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); - endfor - - concatenated_bitstring = tmp1; -endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -0,0 +1,31 @@ +## 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.3 + +function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) + + %% bitstring obtained concating the bitstrings of the single variables + tmp1 = __num2bin__ (doubles(1)); + for i = 2:length(doubles) %% 2:1 is an empty matrix + tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); + endfor + + concatenated_bitstring = tmp1; +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -24,22 +24,21 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.0.1 +## Version: 5.1.1 function xoverKids = \ crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation) - ## example + ## example (nvars == 4) ## p1 = [varA varB varC varD] ## p2 = [var1 var2 var3 var4] ## b = [1 1 0 1] ## child1 = [varA varB var3 varD] - p1 = parents (1, 1:nvars); - p2 = parents (2, 1:nvars); - b = fix (rand (1, nvars) + - 0.5 * ones (1, nvars)); + p1 = parents(1, 1:nvars); + p2 = parents(2, 1:nvars); + b = randint (1, nvars); child1 = b .* p1 + (ones (1, nvars) - b) .* p2; xoverKids = child1; @@ -49,7 +48,7 @@ %! parents = [0 4.3 51 -6; 3 -34 5 64.212]; %! options = gaoptimset (); %! nvars = 4; -%! FitnessFcn = @rastriginsfcn; +%! FitnessFcn = false; ## this parameter is unused in the current implementation %! unused = false; %! thisPopulation = false; ## this parameter is unused in the current implementation %! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); Modified: trunk/octave-forge/main/ga/inst/crossoversinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -24,32 +24,33 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0.2 +## Version: 5.1.1 function xoverKids = \ crossoversinglepoint (parents, options, nvars, FitnessFcn, unused, thisPopulation) - %% constants - N_BIT_DOUBLE = 64; + ## example (nvars == 4) + ## p1 = [varA varB varC varD] + ## p2 = [var1 var2 var3 var4] + ## n = 1 ## integer between 1 and nvars + ## child1 = [varA var2 var3 var4] + p1 = parents(1, 1:nvars); + p2 = parents(2, 1:nvars); + n = randint (1, 1, [1, nvars]); + child1 = horzcat (p1(1, 1:n), + p2(1, n+1:nvars)); - %% aux variable - nvars = columns (parents); + xoverKids = child1; +endfunction - concatenated_parents = [(__ga_doubles2concatenated_bitstring__ (parents(1, :))); - (__ga_doubles2concatenated_bitstring__ (parents(2, :)))]; - - %% n is the single point of the crossover - %% - %% n can be from 1 to ((N_BIT_DOUBLE * nvars) - 1) - n = double (uint64 ((((nvars * N_BIT_DOUBLE) - 2) * rand ()) + 1)); - - %% single point crossover - concatenated_xoverKids = strcat (substr (concatenated_parents (1, :), - 1, n), - substr (concatenated_parents (2, :), - (n + 1))); - - xoverKids = __ga_concatenated_bitstring2doubles__ (concatenated_xoverKids); -endfunction \ No newline at end of file +%!test +%! parents = [0 4.3 51 -6; 3 -34 5 64.212]; +%! options = gaoptimset (); +%! nvars = 4; +%! FitnessFcn = false; ## this parameter is unused in the current implementation +%! unused = false; +%! thisPopulation = false; ## this parameter is unused in the current implementation +%! xoverKids = crossoversinglepoint (parents, options, nvars, FitnessFcn, unused, thisPopulation); +%! assert (size (xoverKids), [1, nvars]); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-07 13:21:04
|
Revision: 5228 http://octave.svn.sourceforge.net/octave/?rev=5228&view=rev Author: slackydeb Date: 2008-08-07 13:21:13 +0000 (Thu, 07 Aug 2008) Log Message: ----------- initial version of mutationgaussian; switch default MutationFcn from mutationsinglepoint to mutationgaussian; performance loss because mutationgaussian is unoptimized Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m trunk/octave-forge/main/ga/inst/ga.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/mutationgaussian.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 11:26:17 UTC (rev 5227) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 13:21:13 UTC (rev 5228) @@ -1,5 +1,5 @@ Name: ga -Version: 0.5.0 +Version: 0.5.1 Date: 2008-08-07 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-07 11:26:17 UTC (rev 5227) +++ trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-07 13:21:13 UTC (rev 5228) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1 +## Version: 1.1.2 function default_options = __gaoptimset_default_options__ () default_options.CreationFcn = @gacreationuniform; @@ -36,8 +36,7 @@ #default_options.MigrationDirection = "forward"; #default_options.MigrationFraction = 0.2; #default_options.MigrationInterval = 20; - default_options.MutationFcn = {@mutationsinglepoint}; - #TODO write default mutationgaussian + default_options.MutationFcn = {@mutationgaussian, 1, 1}; #TODO delete mutationsinglepoint #default_options.OutputFcns = []; #default_options.ParetoFraction = 0.35; Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-07 11:26:17 UTC (rev 5227) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-07 13:21:13 UTC (rev 5228) @@ -74,7 +74,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.8.1 +## Version: 5.8.3 function [x, fval, exitflag, output, population, scores] = \ ga (fitnessfcn_or_problem, @@ -120,21 +120,21 @@ %!function retval = test_parabola (x) %! retval = x ** 2; -%!assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) +%!xtest assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) %!function retval = test_f_con_inf_minimi_locali (x) %! retval = (x ** 2) - (cos (2 * pi * x)) + 1; -%!assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) +%!xtest assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) -%!assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) +%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) %!function retval = test_rastriginsfcn_traslato (t) %! min = [1, 0]; %! x = t - min; %! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%!assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) +%!xtest assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) %!function retval = test_4_variabili (x) %! retval = 0; @@ -142,4 +142,4 @@ %! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; %! retval += x(4) ** 2; -%!assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ No newline at end of file +%!xtest assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m (rev 0) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-07 13:21:13 UTC (rev 5228) @@ -0,0 +1,36 @@ +## 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{mutationChildren} =} mutationgaussian (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{state}, @var{thisScore}, @var{thisPopulation}) +## Single point mutation. +## +## @seealso{ga, gaoptimset} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 0.1 + +function mutationChildren = \ + mutationgaussian (parents, + options, nvars, FitnessFcn, state, + thisScore, thisPopulation) + p1 = parents(1, 1:nvars); + + mutationChildren = p1 + randn (1, nvars); +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. |
From: <sla...@us...> - 2008-08-07 22:12:13
|
Revision: 5229 http://octave.svn.sourceforge.net/octave/?rev=5229&view=rev Author: slackydeb Date: 2008-08-07 22:12:22 +0000 (Thu, 07 Aug 2008) Log Message: ----------- improve mutationscattered Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/mutationgaussian.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 13:21:13 UTC (rev 5228) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 22:12:22 UTC (rev 5229) @@ -1,6 +1,6 @@ Name: ga -Version: 0.5.1 -Date: 2008-08-07 +Version: 0.5.2 +Date: 2008-08-08 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-07 13:21:13 UTC (rev 5228) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-07 22:12:22 UTC (rev 5229) @@ -17,14 +17,14 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.3 +## Version: 4.4 function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; popolazione = __ga_set_initial_population__ (problem); %% in this while, generation is fixed - generazione = 1; + generazione = 1; ## TODO initial generation should be 0 (for state structure) individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); while (! __ga_stop__ (problem, popolazione, generazione)) @@ -63,12 +63,26 @@ index_parent = problem.options.SelectionFcn (problem.fitnessfcn, popolazione); parent = popolazione(index_parent(1), :); + ## start preparing state structure + state.Population = popolazione; + #state.Score + state.Generation = generazione; + #state.StartTime + #state.StopFlag + #state.Selection + #state.Expectation + #state.Best + #state.LastImprovement + #state.LastImprovementTime + #state.NonlinIneq + #state.NonlinEq + ## end preparing state structure popolazione_futura(i, :) = \ #TODO parent -> parents problem.options.MutationFcn{1, 1} (parent, problem.options, problem.nvars, problem.fitnessfcn, - false, #TODO false -> state + state, false, #TODO false -> thisScore popolazione); endif Modified: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-07 13:21:13 UTC (rev 5228) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-07 22:12:22 UTC (rev 5229) @@ -24,13 +24,33 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 0.1 +## Version: 0.2.3 function mutationChildren = \ mutationgaussian (parents, options, nvars, FitnessFcn, state, thisScore, thisPopulation) + [nr, nc] = size (options.PopInitRange); + + if ((nr != 2) + ((nc != 1) && (nc != nvars))) + error ("'PopInitRange' must be 2-by-1 or 2-by-nvars"); + endif + + ## obtain a 2-by-nvars LocalPopInitRange + LocalPopInitRange = options.PopInitRange; + if (nc == 1) + LocalPopInitRange = LocalPopInitRange * ones (1, nvars); + endif + + LB = LocalPopInitRange(1, 1:nvars); + UB = LocalPopInitRange(2, 1:nvars); + + ## mutationgaussian p1 = parents(1, 1:nvars); - - mutationChildren = p1 + randn (1, nvars); + Scale = options.MutationFcn{1, 2}; + initial_std = Scale * (UB - LB); + Shrink = options.MutationFcn{1, 3}; + current_std = initial_std * (1 - Shrink * (state.Generation / options.Generations)); ## TODO consider all generations recursively, not only one + mutationChildren = p1 + current_std .* randn (1, nvars); 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. |
From: <sla...@us...> - 2008-08-08 11:56:52
|
Revision: 5230 http://octave.svn.sourceforge.net/octave/?rev=5230&view=rev Author: slackydeb Date: 2008-08-08 11:56:59 +0000 (Fri, 08 Aug 2008) Log Message: ----------- improve mutationscattered Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/mutationgaussian.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 22:12:22 UTC (rev 5229) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-08 11:56:59 UTC (rev 5230) @@ -1,5 +1,5 @@ Name: ga -Version: 0.5.2 +Version: 0.5.3 Date: 2008-08-08 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-07 22:12:22 UTC (rev 5229) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-08 11:56:59 UTC (rev 5230) @@ -24,7 +24,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 0.2.3 +## Version: 0.3.1 function mutationChildren = \ mutationgaussian (parents, @@ -46,11 +46,25 @@ LB = LocalPopInitRange(1, 1:nvars); UB = LocalPopInitRange(2, 1:nvars); - ## mutationgaussian + ## start mutationgaussian logic p1 = parents(1, 1:nvars); Scale = options.MutationFcn{1, 2}; - initial_std = Scale * (UB - LB); + assert (size (Scale), [1 1]); ## DEBUG Shrink = options.MutationFcn{1, 3}; - current_std = initial_std * (1 - Shrink * (state.Generation / options.Generations)); ## TODO consider all generations recursively, not only one + assert (size (Shrink), [1 1]); ## DEBUG + + ## initial standard deviation (i.e. when state.Generation == 0) + tmp_std = Scale * (UB - LB); ## vector = scalar * vector + + ## recursively compute current standard deviation + for k = 1:state.Generation + tmp_std = \ ## vector = scalar * vector + (1 - Shrink * (k / options.Generations)) * tmp_std; + endfor + + current_std = tmp_std; + assert (size (current_std), [1 nvars]); ## DEBUG + + ## finally add random numbers mutationChildren = p1 + current_std .* randn (1, nvars); 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. |
From: <sla...@us...> - 2008-08-08 16:10:38
|
Revision: 5231 http://octave.svn.sourceforge.net/octave/?rev=5231&view=rev Author: slackydeb Date: 2008-08-08 16:10:40 +0000 (Fri, 08 Aug 2008) Log Message: ----------- improve creation functions and tests Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-08 11:56:59 UTC (rev 5230) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-08 16:10:40 UTC (rev 5231) @@ -1,5 +1,5 @@ Name: ga -Version: 0.5.3 +Version: 0.5.4 Date: 2008-08-08 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-08 11:56:59 UTC (rev 5230) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-08 16:10:40 UTC (rev 5231) @@ -17,11 +17,15 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.4 +## Version: 4.4.2 function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; - popolazione = __ga_set_initial_population__ (problem); + popolazione = __ga_set_initial_population__ (problem.nvars, + problem.fitnessfcn, + problem.options); + #TODO + #consider InitialScores for state structure %% in this while, generation is fixed generazione = 1; ## TODO initial generation should be 0 (for state structure) Modified: trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m 2008-08-08 11:56:59 UTC (rev 5230) +++ trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m 2008-08-08 16:10:40 UTC (rev 5231) @@ -17,55 +17,63 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{Population} =} __ga_set_initial_population__ (@var{problem}) +## @deftypefn{Function File} {@var{Population} =} __ga_set_initial_population__ (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) ## Create an initial population. ## ## @seealso{__ga_problem__} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.1 +## Version: 2.0.10 -function Population = __ga_set_initial_population__ (problem) +function Population = \ + __ga_set_initial_population__ (GenomeLength, FitnessFcn, options) #TODO - # - #consider InitialScores - # #consider PopulationSize as a vector for #multiple subpopolations - - [nr, nc] = size (problem.options.InitialPopulation); - + [nr, nc] = size (options.InitialPopulation); if (nc == 0) - Population = problem.options.CreationFcn (problem.nvars, - problem.fitnessfcn, - problem.options); - elseif (nc == problem.nvars) + Population = options.CreationFcn (GenomeLength, FitnessFcn, options); + elseif (nc == GenomeLength) ## it is impossible to have a matrix with 0 rows and a positive ## number of columns ## ## so, here nr > 0 - if (nr < problem.options.PopulationSize) + if (nr < options.PopulationSize) OptionsWithModifiedPopulationSize = \ - setfield (problem.options, + setfield (options, "PopulationSize", - problem.options.PopulationSize - nr); + options.PopulationSize - nr); CreatedPartialPopulation = \ - problem.options.CreationFcn (problem.nvars, - problem.fitnessfcn, - OptionsWithModifiedPopulationSize); + options.CreationFcn (GenomeLength, + FitnessFcn, + OptionsWithModifiedPopulationSize); Population = \ - vertcat (problem.options.InitialPopulation, - CreatedPartialPopulation); - elseif (nr == problem.options.PopulationSize) - Population = problem.options.InitialPopulation; - else ## nr > problem.options.PopulationSize + vertcat (options.InitialPopulation(1:nr, + 1:GenomeLength), + CreatedPartialPopulation(1:(options.PopulationSize - nr), + 1:GenomeLength)); + elseif (nr == options.PopulationSize) + Population = options.InitialPopulation; + else ## nr > options.PopulationSize error ("nonempty 'InitialPopulation' must have no more than \ 'PopulationSize' rows"); endif else - error ("nonempty 'InitialPopulation' must have 'number of \ - variables' columns"); + error ("nonempty 'InitialPopulation' must have 'GenomeLength' \ + columns"); endif -endfunction \ No newline at end of file +endfunction + +%!test +%! GenomeLength = 2; +%! options = gaoptimset (); +%! Population = __ga_set_initial_population__ (GenomeLength, @rastriginsfcn, options); +%! assert (size (Population), [options.PopulationSize, GenomeLength]); + +%!test +%! GenomeLength = 2; +%! options = gaoptimset ("InitialPopulation", [1, 2; 3, 4; 5, 6]); +%! Population = __ga_set_initial_population__ (GenomeLength, @rastriginsfcn, options); +%! assert (size (Population), [options.PopulationSize, GenomeLength]); \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-08 11:56:59 UTC (rev 5230) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-08 16:10:40 UTC (rev 5231) @@ -24,7 +24,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.1.1 +## Version: 5.1.3 function xoverKids = \ crossoverscattered (parents, @@ -44,12 +44,13 @@ xoverKids = child1; endfunction -%!test -%! parents = [0 4.3 51 -6; 3 -34 5 64.212]; +%!shared nvars, xoverKids +%! parents = [3.2 -34 51 64.21; 3.2 -34 51 64.21]; %! options = gaoptimset (); %! nvars = 4; %! FitnessFcn = false; ## this parameter is unused in the current implementation %! unused = false; %! thisPopulation = false; ## this parameter is unused in the current implementation %! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); -%! assert (size (xoverKids), [1, nvars]); \ No newline at end of file +%!assert (size (xoverKids), [1, nvars]); +%!assert (xoverKids(1, 1:nvars), [3.2 -34 51 64.21]); \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/crossoversinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-08 11:56:59 UTC (rev 5230) +++ trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-08 16:10:40 UTC (rev 5231) @@ -24,7 +24,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.1.1 +## Version: 5.1.2 function xoverKids = \ crossoversinglepoint (parents, @@ -45,12 +45,13 @@ xoverKids = child1; endfunction -%!test -%! parents = [0 4.3 51 -6; 3 -34 5 64.212]; +%!shared nvars, xoverKids +%! parents = [3.2 -34 51 64.21; 3.2 -34 51 64.21]; %! options = gaoptimset (); %! nvars = 4; %! FitnessFcn = false; ## this parameter is unused in the current implementation %! unused = false; %! thisPopulation = false; ## this parameter is unused in the current implementation -%! xoverKids = crossoversinglepoint (parents, options, nvars, FitnessFcn, unused, thisPopulation); -%! assert (size (xoverKids), [1, nvars]); \ No newline at end of file +%! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); +%!assert (size (xoverKids), [1, nvars]); +%!assert (xoverKids(1, 1:nvars), [3.2 -34 51 64.21]); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-09 18:57:24
|
Revision: 5232 http://octave.svn.sourceforge.net/octave/?rev=5232&view=rev Author: slackydeb Date: 2008-08-09 18:57:32 +0000 (Sat, 09 Aug 2008) Log Message: ----------- better use of the state structure Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-08 16:10:40 UTC (rev 5231) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-09 18:57:32 UTC (rev 5232) @@ -1,6 +1,6 @@ Name: ga -Version: 0.5.4 -Date: 2008-08-08 +Version: 0.5.5 +Date: 2008-08-09 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-08 16:10:40 UTC (rev 5231) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-09 18:57:32 UTC (rev 5232) @@ -17,20 +17,20 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.4.2 +## Version: 4.5.1 function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; - popolazione = __ga_set_initial_population__ (problem.nvars, - problem.fitnessfcn, - problem.options); + state.Population = __ga_set_initial_population__ (problem.nvars, + problem.fitnessfcn, + problem.options); #TODO #consider InitialScores for state structure %% in this while, generation is fixed - generazione = 1; ## TODO initial generation should be 0 (for state structure) - individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); - while (! __ga_stop__ (problem, popolazione, generazione)) + 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)) %% doing this initialization here to make the variable %% popolazione_futura visible at the end of the next while @@ -39,7 +39,7 @@ %% elitist selection for i = 1:problem.options.EliteCount - popolazione_futura(i, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(i, :); + popolazione_futura(i, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, state.Population))(i, :); endfor %% in this while the individual of the new generation is fixed @@ -51,26 +51,26 @@ %% crossover if (aux_operatore < problem.options.CrossoverFraction) index_parents = problem.options.SelectionFcn (problem.fitnessfcn, - popolazione); - parents = [popolazione(index_parents(1), :); - popolazione(index_parents(2), :)]; + state.Population); + parents = [state.Population(index_parents(1), :); + state.Population(index_parents(2), :)]; popolazione_futura(i, :) = \ problem.options.CrossoverFcn (parents, problem.options, problem.nvars, problem.fitnessfcn, false, ## unused - popolazione); + state.Population); %% mutation else index_parent = problem.options.SelectionFcn (problem.fitnessfcn, - popolazione); - parent = popolazione(index_parent(1), :); + state.Population); + parent = state.Population(index_parent(1), :); ## start preparing state structure - state.Population = popolazione; + #DONE state.Population #state.Score - state.Generation = generazione; + #DONE state.Generation #state.StartTime #state.StopFlag #state.Selection @@ -88,14 +88,14 @@ problem.fitnessfcn, state, false, #TODO false -> thisScore - popolazione); + state.Population); endif endfor - popolazione = popolazione_futura; - generazione++; - individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); + state.Population = popolazione_futura; + state.Generation++; + individui_migliori(state.Generation, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, state.Population))(1, :); endwhile - x = individui_migliori(generazione, :); + x = individui_migliori(state.Generation, :); 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. |
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. |
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. |
From: <sla...@us...> - 2008-08-12 21:37:42
|
Revision: 5238 http://octave.svn.sourceforge.net/octave/?rev=5238&view=rev Author: slackydeb Date: 2008-08-12 21:37:49 +0000 (Tue, 12 Aug 2008) Log Message: ----------- worse performance; total restructure; move unmantained files to old_stuff/; add standard functions Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/INDEX trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_scores__.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/crossoverscattered.m trunk/octave-forge/main/ga/inst/fitscalingrank.m trunk/octave-forge/main/ga/inst/gacreationuniform.m trunk/octave-forge/main/ga/inst/gaoptimset.m trunk/octave-forge/main/ga/inst/mutationgaussian.m Added Paths: ----------- trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m trunk/octave-forge/main/ga/doc/old_stuff/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/doc/old_stuff/__ga_doubles2concatenated_bitstring__.m trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m trunk/octave-forge/main/ga/doc/old_stuff/crossoversinglepoint.m trunk/octave-forge/main/ga/doc/old_stuff/mutationsinglepoint.m trunk/octave-forge/main/ga/doc/old_stuff/selectionroulette.m trunk/octave-forge/main/ga/inst/__ga_initial_population__.m trunk/octave-forge/main/ga/inst/selectionstochunif.m Removed Paths: ------------- trunk/octave-forge/main/ga/inst/__bin2hex__.m trunk/octave-forge/main/ga/inst/__bin2num__.m trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m trunk/octave-forge/main/ga/inst/__hex2bin__.m trunk/octave-forge/main/ga/inst/__num2bin__.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m trunk/octave-forge/main/ga/inst/mutationsinglepoint.m trunk/octave-forge/main/ga/inst/selectionroulette.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,6 +1,6 @@ Name: ga -Version: 0.6.1 -Date: 2008-08-11 +Version: 0.7.3 +Date: 2008-08-12 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Modified: trunk/octave-forge/main/ga/INDEX =================================================================== --- trunk/octave-forge/main/ga/INDEX 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/INDEX 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,13 +1,12 @@ ga >> Genetic Algorithm Genetic Algorithm ga - gaoptimget gaoptimset Utility crossoverscattered - crossoversinglepoint + fitscalingrank gacreationuniform - mutationsinglepoint + mutationgaussian rastriginsfcn - selectionroulette \ No newline at end of file + selectionstochunif \ No newline at end of file Copied: trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__bin2hex__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,46 @@ +## 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} {} __bin2hex__ (@var{s}) +## Return the hexadecimal number corresponding to the binary number stored in the string @var{s}. For example, +## +## @example +## __bin2hex__ ("1101110") +## @result{} 6E +## @end example +## +## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}. +## +## @example +## __bin2hex__ (["1101110"; "1110"]) +## @result{} [6E; E] +## @end example +## @seealso{__hex2bin__, bin2dec, dec2hex} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.5 + +function h = __bin2hex__ (b) + h = dec2hex (bin2dec (b)); +endfunction + +%!assert (__bin2hex__ ("1101110"), "6E") + +%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]) \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/__bin2hex__.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__bin2num__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,46 @@ +## 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} {} __bin2num__ (@var{b}) +## Return the IEEE 754 double precision number represented by the binary number stored in the string @var{b}. For example, +## +## @example +## __bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000") +## @result{} 1 +## @end example +## +## If @var{b} is a string matrix, returns a column vector of converted numbers, one per row of @var{b}. +## +## @example +## __bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) +## @result{} [1; -3] +## @end example +## @seealso{__num2bin__, __bin2hex__, hex2num} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.3 + +function n = __bin2num__ (b) + n = hex2num (__bin2hex__ (b)); +endfunction + +%!assert (__bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000"), 1) + +%!assert (__bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]), [1; -3]) \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/__bin2num__.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/__ga_concatenated_bitstring2doubles__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__ga_concatenated_bitstring2doubles__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__ga_concatenated_bitstring2doubles__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,39 @@ +## 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.3 + +function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) + + %% constants + N_BIT_DOUBLE = 64; + + %% aux variable + nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; + + %% obtaining the son of the bitstring + tmp1 = zeros (1, nvars); + for i = 1:nvars + tmp_aux = (i - 1) * N_BIT_DOUBLE; + tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): + (tmp_aux + N_BIT_DOUBLE))); + endfor + + doubles = tmp1; +endfunction \ No newline at end of file Copied: trunk/octave-forge/main/ga/doc/old_stuff/__ga_doubles2concatenated_bitstring__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__ga_doubles2concatenated_bitstring__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__ga_doubles2concatenated_bitstring__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,31 @@ +## 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.3 + +function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) + + %% bitstring obtained concating the bitstrings of the single variables + tmp1 = __num2bin__ (doubles(1)); + for i = 2:length(doubles) %% 2:1 is an empty matrix + tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); + endfor + + concatenated_bitstring = tmp1; +endfunction \ No newline at end of file Copied: trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__hex2bin__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,57 @@ +## 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} {} __hex2bin__ (@var{s}, @var{len}) +## Return the binary number corresponding to the hexadecimal number stored in the string @var{s}. For example, +## +## @example +## __hex2bin__ ("6E") +## @result{} 1101110 +## @end example +## +## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}, padded with leading zeros to the width of the largest value. +## +## @example +## __hex2bin__ (["6E"; "E"]) +## @result{} [1101110; 0001110] +## @end example +## +## The optional third argument, @var{len}, specifies the minimum +## number of digits in the result. + +## @seealso{__bin2hex__, hex2dec, dec2bin} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.7 + +function b = __hex2bin__ (h, len) + d = hex2dec (h); + + switch nargin + case {1} + b = dec2bin (d); + case {2} + b = dec2bin (d, len); + endswitch +endfunction + +%!assert (__hex2bin__ ("6E"), "1101110") + +%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]) \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/__hex2bin__.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__num2bin__.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,47 @@ +## 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} {} __num2bin__ (@var{n}) +## Return the binary representation of the IEEE 754 double precision number @var{n}. For example, +## +## @example +## __num2bin__ (1) +## @result{} 0011111111110000000000000000000000000000000000000000000000000000 +## @end example +## +## If @var{n} is a number matrix, returns a column vector of converted numbers, one per row of @var{n}. +## +## @example +## __num2bin__ (["1"; "-3"]) +## @result{} [0011111111110000000000000000000000000000000000000000000000000000; 1100000000001000000000000000000000000000000000000000000000000000] +## @end example +## @seealso{__bin2num__, num2hex, __hex2bin__} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.4 + +function b = __num2bin__ (n) + ## a double precision number is always 64 bits long + b = __hex2bin__ (num2hex (n), 64); +endfunction + +%!assert (__num2bin__ (1), "0011111111110000000000000000000000000000000000000000000000000000") + +%!assert (__num2bin__ ([1; -3]), ["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/__num2bin__.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/crossoversinglepoint.m (from rev 5236, trunk/octave-forge/main/ga/inst/crossoversinglepoint.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/crossoversinglepoint.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/crossoversinglepoint.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,57 @@ +## 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{xoverKids} =} crossoversinglepoint (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) +## Combine two individuals, or parents, to form a crossover child. +## +## @seealso{ga, gaoptimset} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 5.1.2 + +function xoverKids = \ + crossoversinglepoint (parents, + options, nvars, FitnessFcn, unused, + thisPopulation) + + ## example (nvars == 4) + ## p1 = [varA varB varC varD] + ## p2 = [var1 var2 var3 var4] + ## n = 1 ## integer between 1 and nvars + ## child1 = [varA var2 var3 var4] + p1 = parents(1, 1:nvars); + p2 = parents(2, 1:nvars); + n = randint (1, 1, [1, nvars]); + child1 = horzcat (p1(1, 1:n), + p2(1, n+1:nvars)); + + xoverKids = child1; +endfunction + +%!shared nvars, xoverKids +%! parents = [3.2 -34 51 64.21; 3.2 -34 51 64.21]; +%! options = gaoptimset (); +%! nvars = 4; +%! FitnessFcn = false; ## this parameter is unused in the current implementation +%! unused = false; +%! thisPopulation = false; ## this parameter is unused in the current implementation +%! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); +%!assert (size (xoverKids), [1, nvars]); +%!assert (xoverKids(1, 1:nvars), [3.2 -34 51 64.21]); \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/crossoversinglepoint.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/mutationsinglepoint.m (from rev 5236, trunk/octave-forge/main/ga/inst/mutationsinglepoint.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/mutationsinglepoint.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/mutationsinglepoint.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,55 @@ +## 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{mutationChildren} =} mutationsinglepoint (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{state}, @var{thisScore}, @var{thisPopulation}) +## Single point mutation. +## +## @seealso{ga, gaoptimset} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 4.0.1 + +function mutationChildren = \ + mutationsinglepoint (parents, + options, nvars, FitnessFcn, state, + thisScore, thisPopulation) + parent = parents; + + %% constants + N_BIT_DOUBLE = 64; + + %% n is the single point of the mutation + %% + %% n can go from 1 to (N_BIT_DOUBLE * length (parent)) + n = double (uint64 (1 + (((N_BIT_DOUBLE * length (parent)) - 1) * rand()))); + + %% mutation in a single point + concatenated_mutationChildren = __ga_doubles2concatenated_bitstring__ (parent); + switch (concatenated_mutationChildren (n)) + case '0' + concatenated_mutationChildren (n) = '1'; + case '1' + concatenated_mutationChildren (n) = '0'; + otherwise + error ("A bitstring must have only characters 0 and 1."); + endswitch + + mutationChildren = __ga_concatenated_bitstring2doubles__ (concatenated_mutationChildren); +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/mutationsinglepoint.m ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/octave-forge/main/ga/doc/old_stuff/selectionroulette.m (from rev 5236, trunk/octave-forge/main/ga/inst/selectionroulette.m) =================================================================== --- trunk/octave-forge/main/ga/doc/old_stuff/selectionroulette.m (rev 0) +++ trunk/octave-forge/main/ga/doc/old_stuff/selectionroulette.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,67 @@ +## 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{parents} =} selectionroulette (@var{fitnessfcn}, @var{popolazione}) +## Choose parents. +## +## @strong{Outputs} +## @table @var +## @item parents +## A row vector of length 2 containing the indices of the parents that you select. +## @end table +## +## @seealso{ga} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.2 + +function parents = selectionroulette (fitnessfcn, popolazione) + + %% aux variable + n_individui = rows (popolazione); + + %% assegno le "probabilita'" linearmente e decrescenti; ad esempio, se + %% gli individui sono 3 le "probabilita'" saranno, da quello a + %% fitnessfcn minore (cioe' migliore), rispettivamente 3, 2 e 1 + probabilita = zeros (n_individui, 1); + for i = 1:n_individui; + probabilita(i) = n_individui + 1 - i; + endfor + + %% greater probability for the first elements + probabilita_cumulative = cumsum (probabilita); + + %% appling roulette + aux_roulette = probabilita_cumulative(n_individui) * rand (1, 2); + index_individui_scelti = zeros (1, 2); + for i = 1:n_individui + if ((aux_roulette(1) <= probabilita_cumulative(i)) && (index_individui_scelti(1) == 0)) + index_individui_scelti(1) = i; + endif + if ((aux_roulette(2) <= probabilita_cumulative(i)) && (index_individui_scelti(2) == 0)) + index_individui_scelti(2) = i; + endif + endfor + + %% ordered images of fitnessfcn on population + [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 Property changes on: trunk/octave-forge/main/ga/doc/old_stuff/selectionroulette.m ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/octave-forge/main/ga/inst/__bin2hex__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,46 +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. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __bin2hex__ (@var{s}) -## Return the hexadecimal number corresponding to the binary number stored in the string @var{s}. For example, -## -## @example -## __bin2hex__ ("1101110") -## @result{} 6E -## @end example -## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}. -## -## @example -## __bin2hex__ (["1101110"; "1110"]) -## @result{} [6E; E] -## @end example -## @seealso{__hex2bin__, bin2dec, dec2hex} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.5 - -function h = __bin2hex__ (b) - h = dec2hex (bin2dec (b)); -endfunction - -%!assert (__bin2hex__ ("1101110"), "6E") - -%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__bin2num__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__bin2num__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__bin2num__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,46 +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. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __bin2num__ (@var{b}) -## Return the IEEE 754 double precision number represented by the binary number stored in the string @var{b}. For example, -## -## @example -## __bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000") -## @result{} 1 -## @end example -## -## If @var{b} is a string matrix, returns a column vector of converted numbers, one per row of @var{b}. -## -## @example -## __bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) -## @result{} [1; -3] -## @end example -## @seealso{__num2bin__, __bin2hex__, hex2num} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 - -function n = __bin2num__ (b) - n = hex2num (__bin2hex__ (b)); -endfunction - -%!assert (__bin2num__ ("0011111111110000000000000000000000000000000000000000000000000000"), 1) - -%!assert (__bin2num__ (["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]), [1; -3]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,39 +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.3 - -function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) - - %% constants - N_BIT_DOUBLE = 64; - - %% aux variable - nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; - - %% obtaining the son of the bitstring - tmp1 = zeros (1, nvars); - for i = 1:nvars - tmp_aux = (i - 1) * N_BIT_DOUBLE; - tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): - (tmp_aux + N_BIT_DOUBLE))); - endfor - - doubles = tmp1; -endfunction \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -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.3 - -function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) - - %% bitstring obtained concating the bitstrings of the single variables - tmp1 = __num2bin__ (doubles(1)); - for i = 2:length(doubles) %% 2:1 is an empty matrix - tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); - endfor - - concatenated_bitstring = tmp1; -endfunction \ No newline at end of file Copied: trunk/octave-forge/main/ga/inst/__ga_initial_population__.m (from rev 5236, trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m) =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_initial_population__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_initial_population__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -0,0 +1,79 @@ +## 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_initial_population__ (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) +## Create an initial population. +## +## @seealso{__ga_problem__} +## @end deftypefn + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.0.1 + + #TODO consider PopulationSize as a + #vector for multiple subpopolations + +function Population = \ + __ga_initial_population__ (GenomeLength, FitnessFcn, options) + [nr, nc] = size (options.InitialPopulation); + if (nc == 0) + Population = options.CreationFcn (GenomeLength, FitnessFcn, options); + elseif (nc == GenomeLength) + + ## it is impossible to have a matrix with 0 rows and a positive + ## number of columns + ## + ## so, here nr > 0 + if (nr < options.PopulationSize) + OptionsWithModifiedPopulationSize = \ + setfield (options, + "PopulationSize", + options.PopulationSize - nr); + CreatedPartialPopulation = \ + options.CreationFcn (GenomeLength, + FitnessFcn, + OptionsWithModifiedPopulationSize); + Population = \ + vertcat (options.InitialPopulation(1:nr, + 1:GenomeLength), + CreatedPartialPopulation(1:(options.PopulationSize - nr), + 1:GenomeLength)); + elseif (nr == options.PopulationSize) + Population = options.InitialPopulation; + else ## nr > options.PopulationSize + error ("nonempty 'InitialPopulation' must have no more than \ + 'PopulationSize' rows"); + endif + else + error ("nonempty 'InitialPopulation' must have 'GenomeLength' \ + columns"); + endif +endfunction + +%!test +%! GenomeLength = 2; +%! options = gaoptimset (); +%! Population = __ga_initial_population__ (GenomeLength, @rastriginsfcn, options); +%! assert (size (Population), [options.PopulationSize, GenomeLength]); + +%!test +%! GenomeLength = 2; +%! options = gaoptimset ("InitialPopulation", [1, 2; 3, 4; 5, 6]); +%! Population = __ga_initial_population__ (GenomeLength, @rastriginsfcn, options); +%! assert (size (Population), [options.PopulationSize, GenomeLength]); \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_initial_population__.m ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -17,90 +17,136 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.14.2 +## Version: 5.2 + #state structure fields + #DONE state.Population + #DONE state.Score + #DONE state.Generation + #DONE state.StartTime + #state.StopFlag + #DONE state.Selection + #DONE state.Expectation + #DONE state.Best + #state.LastImprovement + #state.LastImprovementTime + #state.NonlinIneq + #state.NonlinEq + function [x fval exitflag output population scores] = __ga_problem__ (problem) - output.randstate = rand ("state"); - output.randnstate = randn ("state"); + + ## first instruction state.StartTime = time (); + ## second instruction + output = struct ("randstate", rand ("state"), + "randnstate", randn ("state")); + + ## start "instructions not to be executed at each generation" state.Population(1:problem.options.PopulationSize, 1:problem.nvars) = \ - __ga_set_initial_population__ (problem.nvars, - problem.fitnessfcn, - problem.options); - + __ga_initial_population__ (problem.nvars, + problem.fitnessfcn, + problem.options); 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__ + __ga_scores__ (problem.fitnessfcn, + state.Population, + problem.options.InitialScores); + state.Generation = 0; - state.Generation = 0; + ReproductionCount.elite = problem.options.EliteCount; + ReproductionCount.crossover = \ + fix (problem.options.CrossoverFraction * + (problem.options.PopulationSize - problem.options.EliteCount)); + ReproductionCount.mutation = \ + problem.options.PopulationSize - (ReproductionCount.elite + + ReproductionCount.crossover); + #assert (ReproductionCount.elite + + # ReproductionCount.crossover + + # ReproductionCount.mutation, problem.options.PopulationSize); ## DEBUG + + state.Selection.elite = 1:ReproductionCount.elite; + state.Selection.crossover = \ + ReproductionCount.elite + (1:ReproductionCount.crossover); + state.Selection.mutation = \ + ReproductionCount.elite + ReproductionCount.crossover + \ + (1:ReproductionCount.mutation); + #assert (length (state.Selection.elite) + + # length (state.Selection.crossover) + + # length (state.Selection.mutation), + # problem.options.PopulationSize); ##DEBUG + + parentsCount.crossover = 2 * ReproductionCount.crossover; + parentsCount.mutation = 1 * ReproductionCount.mutation; + nParents = parentsCount.crossover + parentsCount.mutation; + + parentsSelection.crossover = 1:parentsCount.crossover; + parentsSelection.mutation = \ + parentsCount.crossover + (1:parentsCount.mutation); + #assert (length (parentsSelection.crossover) + + # length (parentsSelection.mutation), nParents); ## DEBUG + ## end "instructions not to be executed at each generation" + + ## start "instructions to be executed at each generation" + state.Expectation(1, 1:problem.options.PopulationSize) = \ + problem.options.FitnessScalingFcn (state.Score, nParents); state.Best(state.Generation + 1, 1) = min (state.Score); + ## end "instructions to be executed at each generation" - ## in this while, generation is fixed - while (! __ga_stop__ (problem, state)) + while (! __ga_stop__ (problem, state)) ## fix a generation - ## elitist selection - [trash IndexSortedScores] = sort (state.Score); - popolazione_futura(1:problem.options.EliteCount, - 1:problem.nvars) = \ - state.Population(IndexSortedScores(1:problem.options.EliteCount, 1), - 1:problem.nvars); + ## elite + if (ReproductionCount.elite > 0) + [trash IndexSortedScores] = sort (state.Score); + NextPopulation(state.Selection.elite, 1:problem.nvars) = \ + state.Population(IndexSortedScores(1:ReproductionCount.elite, 1), + 1:problem.nvars); + #assert (size (NextPopulation), + # [ReproductionCount.elite, problem.nvars]); ## DEBUG + endif - %% in this while the individual of the new generation is fixed - for i = (1 + problem.options.EliteCount):problem.options.PopulationSize + ## selection for crossover and mutation + parents = problem.options.SelectionFcn (state.Expectation, + nParents, + problem.options); + #assert (size (parents), [1, nParents]); ## DEBUG - %% stochastically choosing the genetic operator to apply - aux_operatore = rand (); + ## crossover + if (ReproductionCount.crossover > 0) + NextPopulation(state.Selection.crossover, 1:problem.nvars) = \ + problem.options.CrossoverFcn (parents(1, parentsSelection.crossover), + problem.options, + problem.nvars, + problem.fitnessfcn, + false, ## unused + state.Population); + tmp = ReproductionCount.elite + ReproductionCount.crossover; + #assert (size (NextPopulation), [tmp, problem.nvars]); ## DEBUG + endif - %% crossover - if (aux_operatore < problem.options.CrossoverFraction) - index_parents = problem.options.SelectionFcn (problem.fitnessfcn, - state.Population); - parents = [state.Population(index_parents(1), :); - state.Population(index_parents(2), :)]; - popolazione_futura(i, :) = \ - problem.options.CrossoverFcn (parents, - problem.options, - problem.nvars, - problem.fitnessfcn, - false, ## unused - state.Population); + ## mutation + if (ReproductionCount.mutation > 0) + NextPopulation(state.Selection.mutation, 1:problem.nvars) = \ + problem.options.MutationFcn{1, 1} (parents(1, + parentsSelection.mutation), + problem.options, + problem.nvars, + problem.fitnessfcn, + state, + state.Score, + state.Population); + #assert (size (NextPopulation), + # [problem.options.PopulationSize, problem.nvars]); ## DEBUG + endif - %% mutation - else - index_parent = problem.options.SelectionFcn (problem.fitnessfcn, - state.Population); - parent = state.Population(index_parent(1), :); - ## start preparing state structure - #DONE state.Population - #DONE state.Score - #DONE state.Generation - #DONE state.StartTime - #state.StopFlag - #state.Selection - #state.Expectation - #DONE state.Best - #state.LastImprovement - #state.LastImprovementTime - #state.NonlinIneq - #state.NonlinEq - ## end preparing state structure - popolazione_futura(i, :) = \ #TODO parent -> parents - problem.options.MutationFcn{1, 1} (parent, - problem.options, - problem.nvars, - problem.fitnessfcn, - state, - false, #TODO false -> thisScore - state.Population); - endif - endfor - - state.Population = popolazione_futura; - state.Score = __ga_scores__ (problem.fitnessfcn, state.Population); + ## update state structure + state.Population(1:problem.options.PopulationSize, + 1:problem.nvars) = NextPopulation; + clear -v NextPopulation; + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, state.Population); state.Generation++; + state.Expectation(1, 1:problem.options.PopulationSize) = \ + problem.options.FitnessScalingFcn (state.Score, nParents); state.Best(state.Generation + 1, 1) = min (state.Score); endwhile @@ -116,8 +162,9 @@ ## output.randstate and output.randnstate must be assigned at the ## start of the algorithm output.generations = state.Generation; - #TODO output (funccount, message, - #maxconstraint) + #TODO output.funccount + #TODO output.message + #TODO output.maxconstraint population = state.Population; Modified: trunk/octave-forge/main/ga/inst/__ga_scores__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -17,12 +17,18 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 5.2 -function Scores = __ga_scores__ (fitnessfcn, Population) - [nr nc] = size (Population); - - for i = 1:nr - Scores(i, 1) = fitnessfcn (Population (i, 1:nc)); +function Scores = __ga_scores__ (fitnessfcn, Population, InitialScores = []) + [nrP ncP] = size (Population); + [nrIS ncIS] = size (InitialScores); + #assert ((ncIS == 0) || (ncIS == 1)); ## DEBUG + #assert (nrIS <= nrP); ## DEBUG + if (nrIS > 0) + Scores(1:nrIS, 1) = InitialScores(1:nrIS, 1); + endif + for index = (nrIS + 1):nrP + Scores(index, 1) = fitnessfcn (Population(index, 1:ncP)); endfor + #assert (size (Scores), [nrP 1]); ## DEBUG endfunction \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_set_initial_population__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,79 +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. - -## -*- texinfo -*- -## @deftypefn{Function File} {@var{Population} =} __ga_set_initial_population__ (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) -## Create an initial population. -## -## @seealso{__ga_problem__} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 2.0.10 - -function Population = \ - __ga_set_initial_population__ (GenomeLength, FitnessFcn, options) - #TODO - #consider PopulationSize as a vector for - #multiple subpopolations - [nr, nc] = size (options.InitialPopulation); - if (nc == 0) - Population = options.CreationFcn (GenomeLength, FitnessFcn, options); - elseif (nc == GenomeLength) - - ## it is impossible to have a matrix with 0 rows and a positive - ## number of columns - ## - ## so, here nr > 0 - if (nr < options.PopulationSize) - OptionsWithModifiedPopulationSize = \ - setfield (options, - "PopulationSize", - options.PopulationSize - nr); - CreatedPartialPopulation = \ - options.CreationFcn (GenomeLength, - FitnessFcn, - OptionsWithModifiedPopulationSize); - Population = \ - vertcat (options.InitialPopulation(1:nr, - 1:GenomeLength), - CreatedPartialPopulation(1:(options.PopulationSize - nr), - 1:GenomeLength)); - elseif (nr == options.PopulationSize) - Population = options.InitialPopulation; - else ## nr > options.PopulationSize - error ("nonempty 'InitialPopulation' must have no more than \ - 'PopulationSize' rows"); - endif - else - error ("nonempty 'InitialPopulation' must have 'GenomeLength' \ - columns"); - endif -endfunction - -%!test -%! GenomeLength = 2; -%! options = gaoptimset (); -%! Population = __ga_set_initial_population__ (GenomeLength, @rastriginsfcn, options); -%! assert (size (Population), [options.PopulationSize, GenomeLength]); - -%!test -%! GenomeLength = 2; -%! options = gaoptimset ("InitialPopulation", [1, 2; 3, 4; 5, 6]); -%! Population = __ga_set_initial_population__ (GenomeLength, @rastriginsfcn, options); -%! assert (size (Population), [options.PopulationSize, GenomeLength]); \ 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-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -17,16 +17,16 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} {@var{x} =} __ga_stop__ (@var{problem}, @var{state}) +## @deftypefn{Function File} {@var{stop} =} __ga_stop__ (@var{problem}, @var{state}) ## Determine whether the genetic algorithm should stop. ## ## @seealso{__ga_problem__} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.0 +## Version: 5.0.1 -function retval = __ga_stop__ (problem, state) +function stop = __ga_stop__ (problem, state) Generations = \ (state.Generation >= problem.options.Generations); @@ -36,7 +36,7 @@ FitnessLimit = \ (state.Best(state.Generation + 1, 1) <= problem.options.FitnessLimit); - retval = (Generations || - TimeLimit || - FitnessLimit); + stop = (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-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.3 +## Version: 1.1.7 function default_options = __gaoptimset_default_options__ () default_options.CreationFcn = @gacreationuniform; @@ -27,12 +27,12 @@ #default_options.DistanceMeasureFcn gamultiobj default_options.EliteCount = 2; default_options.FitnessLimit = -Inf; - #default_options.FitnessScalingFcn = @fitscalingrank; + default_options.FitnessScalingFcn = @fitscalingrank; default_options.Generations = 100; #default_options.HybridFcn = []; #default_options.InitialPenalty = 10; default_options.InitialPopulation = []; - #default_options.InitialScores = []; + default_options.InitialScores = []; #default_options.MigrationDirection = "forward"; #default_options.MigrationFraction = 0.2; #default_options.MigrationInterval = 20; @@ -45,9 +45,8 @@ #default_options.PlotInterval = 1; default_options.PopInitRange = [0; 1]; default_options.PopulationSize = 20; - #default_options.PopulationType = "doubleVector"; - default_options.SelectionFcn = @selectionroulette; - #TODO write default selectionstochunif + default_options.PopulationType = "doubleVector"; + default_options.SelectionFcn = @selectionstochunif; #default_options.StallGenLimit = 50; #default_options.StallTimeLimit = Inf; default_options.TimeLimit = Inf; Deleted: trunk/octave-forge/main/ga/inst/__hex2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,57 +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. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __hex2bin__ (@var{s}, @var{len}) -## Return the binary number corresponding to the hexadecimal number stored in the string @var{s}. For example, -## -## @example -## __hex2bin__ ("6E") -## @result{} 1101110 -## @end example -## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}, padded with leading zeros to the width of the largest value. -## -## @example -## __hex2bin__ (["6E"; "E"]) -## @result{} [1101110; 0001110] -## @end example -## -## The optional third argument, @var{len}, specifies the minimum -## number of digits in the result. - -## @seealso{__bin2hex__, hex2dec, dec2bin} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.7 - -function b = __hex2bin__ (h, len) - d = hex2dec (h); - - switch nargin - case {1} - b = dec2bin (d); - case {2} - b = dec2bin (d, len); - endswitch -endfunction - -%!assert (__hex2bin__ ("6E"), "1101110") - -%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]) \ No newline at end of file Deleted: trunk/octave-forge/main/ga/inst/__num2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -1,47 +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. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __num2bin__ (@var{n}) -## Return the binary representation of the IEEE 754 double precision number @var{n}. For example, -## -## @example -## __num2bin__ (1) -## @result{} 0011111111110000000000000000000000000000000000000000000000000000 -## @end example -## -## If @var{n} is a number matrix, returns a column vector of converted numbers, one per row of @var{n}. -## -## @example -## __num2bin__ (["1"; "-3"]) -## @result{} [0011111111110000000000000000000000000000000000000000000000000000; 1100000000001000000000000000000000000000000000000000000000000000] -## @end example -## @seealso{__bin2num__, num2hex, __hex2bin__} -## @end deftypefn - -## Author: Luca Favatella <sla...@gm...> -## Version: 1.4 - -function b = __num2bin__ (n) - ## a double precision number is always 64 bits long - b = __hex2bin__ (num2hex (n), 64); -endfunction - -%!assert (__num2bin__ (1), "0011111111110000000000000000000000000000000000000000000000000000") - -%!assert (__num2bin__ ([1; -3]), ["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-12 13:39:34 UTC (rev 5237) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-12 21:37:49 UTC (rev 5238) @@ -24,33 +24,28 @@ ## @end deftypefn... [truncated message content] |
From: <sla...@us...> - 2008-08-13 22:12:05
|
Revision: 5240 http://octave.svn.sourceforge.net/octave/?rev=5240&view=rev Author: slackydeb Date: 2008-08-13 22:12:12 +0000 (Wed, 13 Aug 2008) Log Message: ----------- modularize to semplify debug Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_scores__.m trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/fitscalingrank.m trunk/octave-forge/main/ga/inst/mutationgaussian.m trunk/octave-forge/main/ga/inst/selectionstochunif.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-13 22:12:12 UTC (rev 5240) @@ -1,6 +1,6 @@ Name: ga -Version: 0.7.3 -Date: 2008-08-12 +Version: 0.8.0 +Date: 2008-08-14 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Added: trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,38 @@ +## 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: 1.1.4 + +function xoverKids = __ga_crossoverfcn__ (parents, options, nvars, FitnessFcn, + unused, + thisPopulation) + + ## preconditions + [nr_parents nc_parents] = size (parents); + assert (nr_parents, 1); ## DEBUG + assert (rem (nc_parents, 2), 0); ## DEBUG + assert (columns (thisPopulation), nvars); ## DEBUG + + xoverKids = options.CrossoverFcn (parents, options, nvars, FitnessFcn, + unused, + thisPopulation); + + ## postconditions + assert (size (xoverKids), [(nc_parents / 2) nvars]); ## DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,45 @@ +## 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: 1.0.4 + +function mutationChildren = \ + __ga_mutationfcn__ (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation) + + ## preconditions + [nr_parents nc_parents] = size (parents); + assert (nr_parents, 1); ## DEBUG + #TODO move controls on + #options.PopInitRange in a more general + #function + [nrPopInitRange, ncPopInitRange] = size (options.PopInitRange); + assert (nrPopInitRange, 2); ## DEBUG + assert ((ncPopInitRange == 1) || (ncPopInitRange == nvars)); ## DEBUG + assert (columns (thisPopulation), nvars); ## DEBUG + + mutationChildren = \ + options.MutationFcn{1, 1} (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation); + + ## postconditions + assert (size (mutationChildren), [nc_parents, nvars]); ## DEBUG +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-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -17,22 +17,8 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.2 +## Version: 5.7.1 - #state structure fields - #DONE state.Population - #DONE state.Score - #DONE state.Generation - #DONE state.StartTime - #state.StopFlag - #DONE state.Selection - #DONE state.Expectation - #DONE state.Best - #state.LastImprovement - #state.LastImprovementTime - #state.NonlinIneq - #state.NonlinEq - function [x fval exitflag output population scores] = __ga_problem__ (problem) ## first instruction @@ -47,126 +33,83 @@ __ga_initial_population__ (problem.nvars, problem.fitnessfcn, problem.options); - state.Score(1:problem.options.PopulationSize, 1) = \ - __ga_scores__ (problem.fitnessfcn, - state.Population, - problem.options.InitialScores); state.Generation = 0; - - ReproductionCount.elite = problem.options.EliteCount; - ReproductionCount.crossover = \ - fix (problem.options.CrossoverFraction * - (problem.options.PopulationSize - problem.options.EliteCount)); - ReproductionCount.mutation = \ - problem.options.PopulationSize - (ReproductionCount.elite + - ReproductionCount.crossover); - #assert (ReproductionCount.elite + - # ReproductionCount.crossover + - # ReproductionCount.mutation, problem.options.PopulationSize); ## DEBUG - - state.Selection.elite = 1:ReproductionCount.elite; - state.Selection.crossover = \ - ReproductionCount.elite + (1:ReproductionCount.crossover); - state.Selection.mutation = \ - ReproductionCount.elite + ReproductionCount.crossover + \ - (1:ReproductionCount.mutation); - #assert (length (state.Selection.elite) + - # length (state.Selection.crossover) + - # length (state.Selection.mutation), - # problem.options.PopulationSize); ##DEBUG - - parentsCount.crossover = 2 * ReproductionCount.crossover; - parentsCount.mutation = 1 * ReproductionCount.mutation; - nParents = parentsCount.crossover + parentsCount.mutation; - - parentsSelection.crossover = 1:parentsCount.crossover; - parentsSelection.mutation = \ - parentsCount.crossover + (1:parentsCount.mutation); - #assert (length (parentsSelection.crossover) + - # length (parentsSelection.mutation), nParents); ## DEBUG + private_state = __ga_problem_private_state__ (problem.options); + state.Selection = __ga_problem_state_selection__ (private_state, + problem.options); ## end "instructions not to be executed at each generation" ## start "instructions to be executed at each generation" - state.Expectation(1, 1:problem.options.PopulationSize) = \ - problem.options.FitnessScalingFcn (state.Score, nParents); - state.Best(state.Generation + 1, 1) = min (state.Score); + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); ## end "instructions to be executed at each generation" while (! __ga_stop__ (problem, state)) ## fix a generation ## elite - if (ReproductionCount.elite > 0) + if (private_state.ReproductionCount.elite > 0) [trash IndexSortedScores] = sort (state.Score); NextPopulation(state.Selection.elite, 1:problem.nvars) = \ - state.Population(IndexSortedScores(1:ReproductionCount.elite, 1), - 1:problem.nvars); - #assert (size (NextPopulation), - # [ReproductionCount.elite, problem.nvars]); ## DEBUG + state.Population \ + (IndexSortedScores(1:private_state.ReproductionCount.elite, 1), + 1:problem.nvars); + assert (size (NextPopulation), + [private_state.ReproductionCount.elite, problem.nvars]); ## DEBUG endif ## selection for crossover and mutation - parents = problem.options.SelectionFcn (state.Expectation, - nParents, - problem.options); - #assert (size (parents), [1, nParents]); ## DEBUG + parents = __ga_selectionfcn__ \ + (state.Expectation, private_state.nParents, problem.options); ## crossover - if (ReproductionCount.crossover > 0) + if (private_state.ReproductionCount.crossover > 0) NextPopulation(state.Selection.crossover, 1:problem.nvars) = \ - problem.options.CrossoverFcn (parents(1, parentsSelection.crossover), - problem.options, - problem.nvars, - problem.fitnessfcn, - false, ## unused - state.Population); - tmp = ReproductionCount.elite + ReproductionCount.crossover; - #assert (size (NextPopulation), [tmp, problem.nvars]); ## DEBUG + __ga_crossoverfcn__ \ + (parents(1, private_state.parentsSelection.crossover), + problem.options, problem.nvars, problem.fitnessfcn, + false, ## unused + state.Population); + tmp = \ + private_state.ReproductionCount.elite + \ + private_state.ReproductionCount.crossover; + assert (size (NextPopulation), [tmp, problem.nvars]); ## DEBUG endif ## mutation - if (ReproductionCount.mutation > 0) + if (private_state.ReproductionCount.mutation > 0) NextPopulation(state.Selection.mutation, 1:problem.nvars) = \ - problem.options.MutationFcn{1, 1} (parents(1, - parentsSelection.mutation), - problem.options, - problem.nvars, - problem.fitnessfcn, - state, - state.Score, - state.Population); - #assert (size (NextPopulation), - # [problem.options.PopulationSize, problem.nvars]); ## DEBUG + __ga_mutationfcn__ \ + (parents(1, private_state.parentsSelection.mutation), + problem.options, problem.nvars, problem.fitnessfcn, + state, state.Score, + state.Population); + assert (size (NextPopulation), + [problem.options.PopulationSize, problem.nvars]); ## DEBUG endif ## update state structure state.Population(1:problem.options.PopulationSize, 1:problem.nvars) = NextPopulation; clear -v NextPopulation; - state.Score(1:problem.options.PopulationSize, 1) = \ - __ga_scores__ (problem.fitnessfcn, state.Population); state.Generation++; - state.Expectation(1, 1:problem.options.PopulationSize) = \ - problem.options.FitnessScalingFcn (state.Score, nParents); - state.Best(state.Generation + 1, 1) = min (state.Score); + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); endwhile - ## return variables - ## - [trash IndexMinScore] = min (state.Score); - x = state.Population(IndexMinScore, 1:problem.nvars); + [x fval exitflag output population scores] = \ + __ga_problem_return_variables__ (state, problem); +endfunction - 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 - #TODO output.message - #TODO output.maxconstraint - - population = state.Population; - - scores = state.Score; -endfunction \ No newline at end of file + #state structure fields + #DONE state.Population + #DONE state.Score + #DONE state.Generation + #DONE state.StartTime + #state.StopFlag + #DONE state.Selection + #DONE state.Expectation + #DONE state.Best + #state.LastImprovement + #state.LastImprovementTime + #state.NonlinIneq + #state.NonlinEq \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,53 @@ +## 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: 1.0 + +function private_state = __ga_problem_private_state__ (options) + #start private_state + private_state.ReproductionCount.elite = options.EliteCount; + private_state.ReproductionCount.crossover = \ + fix (options.CrossoverFraction * + (options.PopulationSize - options.EliteCount)); + private_state.ReproductionCount.mutation = \ + options.PopulationSize - \ + (private_state.ReproductionCount.elite + + private_state.ReproductionCount.crossover); + assert (private_state.ReproductionCount.elite + + private_state.ReproductionCount.crossover + + private_state.ReproductionCount.mutation, + options.PopulationSize); ## DEBUG + + private_state.parentsCount.crossover = \ + 2 * private_state.ReproductionCount.crossover; + private_state.parentsCount.mutation = \ + 1 * private_state.ReproductionCount.mutation; + private_state.nParents = \ + private_state.parentsCount.crossover + \ + private_state.parentsCount.mutation; + + private_state.parentsSelection.crossover = \ + 1:private_state.parentsCount.crossover; + private_state.parentsSelection.mutation = \ + private_state.parentsCount.crossover + \ + (1:private_state.parentsCount.mutation); + assert (length (private_state.parentsSelection.crossover) + + length (private_state.parentsSelection.mutation), + private_state.nParents); ## DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,41 @@ +## 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: 1.0 + +function [x fval exitflag output population scores] = \ + __ga_problem_return_variables__ (state, problem) + [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 + #TODO output.message + #TODO output.maxconstraint + + population = state.Population; + + scores = state.Score; +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,35 @@ +## 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: 1.0 + +function Selection = __ga_problem_state_selection__ (private_state, options) + Selection.elite = 1:private_state.ReproductionCount.elite; + Selection.crossover = \ + private_state.ReproductionCount.elite + \ + (1:private_state.ReproductionCount.crossover); + Selection.mutation = \ + private_state.ReproductionCount.elite + \ + private_state.ReproductionCount.crossover + \ + (1:private_state.ReproductionCount.mutation); + assert (length (Selection.elite) + + length (Selection.crossover) + + length (Selection.mutation), + options.PopulationSize); ##DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,36 @@ +## 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: 1.1 + +function state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state) + if (state.Generation > 0) + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, state.Population); + else ## state.Generation == 0 + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, + state.Population, + problem.options.InitialScores); + endif + state.Expectation(1, 1:problem.options.PopulationSize) = \ + problem.options.FitnessScalingFcn (state.Score, private_state.nParents); + state.Best(state.Generation + 1, 1) = min (state.Score); +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_scores__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -17,18 +17,18 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.2 +## Version: 5.2.1 function Scores = __ga_scores__ (fitnessfcn, Population, InitialScores = []) - [nrP ncP] = size (Population); - [nrIS ncIS] = size (InitialScores); - #assert ((ncIS == 0) || (ncIS == 1)); ## DEBUG - #assert (nrIS <= nrP); ## DEBUG - if (nrIS > 0) - Scores(1:nrIS, 1) = InitialScores(1:nrIS, 1); + [nrPopulation ncPopulation] = size (Population); + [nrInitialScores ncInitialScores] = size (InitialScores); + #assert ((ncInitialScores == 0) || (ncInitialScores == 1)); ## DEBUG + #assert (nrInitialScores <= nrPopulation); ## DEBUG + if (nrInitialScores > 0) + Scores(1:nrInitialScores, 1) = InitialScores(1:nrInitialScores, 1); endif - for index = (nrIS + 1):nrP - Scores(index, 1) = fitnessfcn (Population(index, 1:ncP)); + for index = (nrInitialScores + 1):nrPopulation + Scores(index, 1) = fitnessfcn (Population(index, 1:ncPopulation)); endfor - #assert (size (Scores), [nrP 1]); ## DEBUG + #assert (size (Scores), [nrPopulation 1]); ## DEBUG endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,31 @@ +## 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: 1.0.2 + +function parents = __ga_selectionfcn__ (expectation, nParents, options) + + ## preconditions + assert (rows (expectation), 1); ## DEBUG + + parents = options.SelectionFcn (expectation, nParents, options); + + ## postconditions + assert (size (parents), [1 nParents]); ## DEBUG +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,24 +16,13 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) -## Combine two individuals, or parents, to form a crossover child. -## -## @seealso{ga, gaoptimset} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 6.2 +## Version: 6.2.5 -function xoverKids = \ - crossoverscattered (parents, - options, nvars, FitnessFcn, unused, - thisPopulation) - [nr_parents nc_parents] = size (parents); - #assert (nr_parents, 1); ## DEBUG - #assert (rem (nc_parents, 2), 0); ## DEBUG - #assert (columns (thisPopulation), nvars); ## DEBUG +function xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, + unused, + thisPopulation) + nc_parents = columns (parents); ## simplified example (nvars == 4) ## p1 = [varA varB varC varD] Modified: trunk/octave-forge/main/ga/inst/fitscalingrank.m =================================================================== --- trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,17 +16,8 @@ ## 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.1 +## Version: 1.1.1 function expectation = fitscalingrank (scores, nParents) [nr nc] = size (scores); Modified: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,26 +16,15 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{mutationChildren} =} mutationgaussian (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{state}, @var{thisScore}, @var{thisPopulation}) -## Single point mutation. -## -## @seealso{ga, gaoptimset} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 +## Version: 1.4.4 function mutationChildren = \ - mutationgaussian (parents, - options, nvars, FitnessFcn, state, - thisScore, thisPopulation) - [nr_parents nc_parents] = size (parents); - #assert (nr_parents, 1); ## DEBUG - [nrPopInitRange, ncPopInitRange] = size (options.PopInitRange); - #assert (nrPopInitRange, 2); ## DEBUG - #assert ((ncPopInitRange == 1) || (ncPopInitRange == nvars)); ## DEBUG - #assert (columns (thisPopulation), nvars); ## DEBUG + mutationgaussian (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation) + nc_parents = columns (parents); + ncPopInitRange = columns (options.PopInitRange); ## obtain a 2-by-nvars LocalPopInitRange LocalPopInitRange = options.PopInitRange; Modified: trunk/octave-forge/main/ga/inst/selectionstochunif.m =================================================================== --- trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,32 +16,22 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{parents} =} selectionstochunif (@var{expectation}, @var{nParents}, @var{options}) -## Choose parents. -## -## @seealso{ga} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 1.2 +## Version: 1.2.4 function parents = selectionstochunif (expectation, nParents, options) - [nr nc] = size (expectation); - #assert (nr, 1); ## DEBUG - line(1, 1:nc) = cumsum (expectation(1, 1:nc)); - max_step_size = line(1, nc); + nc_expectation = columns (expectation); + line(1, 1:nc_expectation) = cumsum (expectation(1, 1:nc_expectation)); + max_step_size = line(1, nc_expectation); step_size = max_step_size * rand (); steps(1, 1:nParents) = rem (step_size * ones (1, nParents), max_step_size); - for index_steps = 1:nParents ## fix an entry of the steps (or parents) vector #assert (steps(1, index_steps) < max_step_size); ## DEBUG index_line = 1; while (steps(1, index_steps) >= line(1, index_line)) - #assert ((index_line >= 1) && (index_line < nc)); ## DEBUG + #assert ((index_line >= 1) && (index_line < nc_expectation)); ## DEBUG index_line++; endwhile parents(1, index_steps) = index_line; endfor - #assert (size (parents), [1 nParents]); ## 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. |
From: <sla...@us...> - 2008-08-14 15:06:45
|
Revision: 5242 http://octave.svn.sourceforge.net/octave/?rev=5242&view=rev Author: slackydeb Date: 2008-08-14 15:06:51 +0000 (Thu, 14 Aug 2008) Log Message: ----------- performance gain; fix a bug in selectionstochunif function; clean license; clean ga function tests Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/INDEX trunk/octave-forge/main/ga/doc/todo.txt trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m trunk/octave-forge/main/ga/inst/__ga_initial_population__.m trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m trunk/octave-forge/main/ga/inst/__ga_scores__.m trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.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/crossoverscattered.m trunk/octave-forge/main/ga/inst/fitscalingrank.m trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gacreationuniform.m trunk/octave-forge/main/ga/inst/gaoptimset.m trunk/octave-forge/main/ga/inst/mutationgaussian.m trunk/octave-forge/main/ga/inst/rastriginsfcn.m trunk/octave-forge/main/ga/inst/selectionstochunif.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,5 +1,5 @@ Name: ga -Version: 0.8.0 +Version: 0.9.0 Date: 2008-08-14 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/INDEX =================================================================== --- trunk/octave-forge/main/ga/INDEX 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/INDEX 2008-08-14 15:06:51 UTC (rev 5242) @@ -3,10 +3,20 @@ ga gaoptimset -Utility +Creation + gacreationuniform + +Fitness Scaling + fitscalingrank + +Selection + selectionstochunif + +Crossover crossoverscattered - fitscalingrank - gacreationuniform + +Mutation mutationgaussian - rastriginsfcn - selectionstochunif \ No newline at end of file + +Utility + rastriginsfcn \ No newline at end of file Modified: trunk/octave-forge/main/ga/doc/todo.txt =================================================================== --- trunk/octave-forge/main/ga/doc/todo.txt 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/doc/todo.txt 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,28 +1,5 @@ ##### -fare gacreationuniform come matlab, ma non fare generalizzazione in gaoptimset e get perché octave non sa passare handle di funzione a funzione caricata con handle - -ricontrollare -##### - -##### gaoptimset: -StallGenLimit? -StallTimeLimit? -TimeLimit? //tic toc utile ma non nested - -NO InitialPopulation? //no, consentire solo intervallo -NO PopulationType? //no, solo vettori di double -NO PlotFcns? //no, plot non sono priorita' -NO PlotInterval? //no, solo alla fine +TimeLimit? //tic toc useful but not nested? ##### - - -##### -eventuale uscita con x,fval oltre che solo x? -##### - - -##### -forse matlab fissa pure la frazione di crossover e mutazione, cioè non sceglie l'operatore con probabilità -##### \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.4 +## Version: 1.2 function xoverKids = __ga_crossoverfcn__ (parents, options, nvars, FitnessFcn, unused, Modified: trunk/octave-forge/main/ga/inst/__ga_initial_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_initial_population__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_initial_population__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {@var{Population} =} __ga_initial_population__ (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) @@ -24,7 +21,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.0.1 +## Version: 3.1 #TODO consider PopulationSize as a #vector for multiple subpopolations Modified: trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.0.4 +## Version: 1.1 function mutationChildren = \ __ga_mutationfcn__ (parents, options, nvars, FitnessFcn, Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.7.1 +## Version: 5.8 function [x fval exitflag output population scores] = __ga_problem__ (problem) @@ -58,7 +55,7 @@ endif ## selection for crossover and mutation - parents = __ga_selectionfcn__ \ + parents(1, 1:private_state.nParents) = __ga_selectionfcn__ \ (state.Expectation, private_state.nParents, problem.options); ## crossover Modified: trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.0 +## Version: 1.1 function private_state = __ga_problem_private_state__ (options) #start private_state Modified: trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.0 +## Version: 1.1 function [x fval exitflag output population scores] = \ __ga_problem_return_variables__ (state, problem) Modified: trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.0 +## Version: 1.1 function Selection = __ga_problem_state_selection__ (private_state, options) Selection.elite = 1:private_state.ReproductionCount.elite; Modified: trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1 +## Version: 1.2 function state = __ga_problem_update_state_at_each_generation__ (state, problem, private_state) Modified: trunk/octave-forge/main/ga/inst/__ga_scores__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.2.1 +## Version: 5.3 function Scores = __ga_scores__ (fitnessfcn, Population, InitialScores = []) [nrPopulation ncPopulation] = size (Population); Modified: trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.0.2 +## Version: 1.1 function parents = __ga_selectionfcn__ (expectation, nParents, options) Modified: trunk/octave-forge/main/ga/inst/__ga_stop__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__ga_stop__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {@var{stop} =} __ga_stop__ (@var{problem}, @var{state}) @@ -24,7 +21,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.0.1 +## Version: 5.1 function stop = __ga_stop__ (problem, state) Generations = \ Modified: trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/__gaoptimset_default_options__.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.7 +## Version: 1.2 function default_options = __gaoptimset_default_options__ () default_options.CreationFcn = @gacreationuniform; Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 6.2.5 +## Version: 6.3 function xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, Modified: trunk/octave-forge/main/ga/inst/fitscalingrank.m =================================================================== --- trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1.1 +## Version: 1.2 function expectation = fitscalingrank (scores, nParents) [nr nc] = size (scores); Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {@var{x} =} ga (@var{fitnessfcn}, @var{nvars}) @@ -74,9 +71,9 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.8.3 +## Version: 5.10 -function [x, fval, exitflag, output, population, scores] = \ +function [x fval exitflag output population scores] = \ ga (fitnessfcn_or_problem, nvars, A = [], b = [], @@ -117,29 +114,26 @@ endif endfunction -%!function retval = test_parabola (x) -%! retval = x ** 2; +%!xtest assert (ga (@(x) x ** 2, 1, [], [], [], [], [], [], [], gaoptimset ('EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) -%!xtest assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) - -%!function retval = test_f_con_inf_minimi_locali (x) +%!function retval = test_pseudo_rastriginsfcn (x) %! retval = (x ** 2) - (cos (2 * pi * x)) + 1; -%!xtest assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) +%!xtest assert (ga (@test_pseudo_rastriginsfcn, 1, [], [], [], [], [], [], [], gaoptimset ('EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) %!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) -%!function retval = test_rastriginsfcn_traslato (t) +%!function retval = test_bias_rastriginsfcn (t) %! min = [1, 0]; %! x = t - min; %! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%!xtest assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) +%!xtest assert (ga (@test_bias_rastriginsfcn, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) -%!function retval = test_4_variabili (x) +%!function retval = test_4_variables (x) %! retval = 0; %! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); %! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; %! retval += x(4) ** 2; -%!xtest assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ No newline at end of file +%!xtest assert (ga (@test_4_variables, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ 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-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {@var{Population} =} gacreationuniform (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) @@ -40,7 +37,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.4 +## Version: 4.5 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) [nr, nc] = size (options.PopInitRange); Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {@var{options} =} gaoptimset @@ -59,7 +56,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.3.5 +## Version: 4.4 function options = gaoptimset (varargin) if ((nargout != 1) || Modified: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,23 +1,20 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.4.4 +## Version: 1.5 function mutationChildren = \ mutationgaussian (parents, options, nvars, FitnessFcn, Modified: trunk/octave-forge/main/ga/inst/rastriginsfcn.m =================================================================== --- trunk/octave-forge/main/ga/inst/rastriginsfcn.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/rastriginsfcn.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,20 +1,17 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} {} rastriginsfcn (@var{x}) @@ -22,7 +19,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1 +## Version: 1.2 function retval = rastriginsfcn (x) retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + Modified: trunk/octave-forge/main/ga/inst/selectionstochunif.m =================================================================== --- trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-14 14:23:52 UTC (rev 5241) +++ trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-14 15:06:51 UTC (rev 5242) @@ -1,30 +1,27 @@ ## 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 of the License, or +## (at your option) any later version. ## -## 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. ## -## 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. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.2.4 +## Version: 1.3 function parents = selectionstochunif (expectation, nParents, options) nc_expectation = columns (expectation); line(1, 1:nc_expectation) = cumsum (expectation(1, 1:nc_expectation)); max_step_size = line(1, nc_expectation); step_size = max_step_size * rand (); - steps(1, 1:nParents) = rem (step_size * ones (1, nParents), max_step_size); + steps(1, 1:nParents) = rem (step_size * (1:nParents), max_step_size); for index_steps = 1:nParents ## fix an entry of the steps (or parents) vector #assert (steps(1, index_steps) < max_step_size); ## DEBUG index_line = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2008-08-15 22:47:17
|
Revision: 5244 http://octave.svn.sourceforge.net/octave/?rev=5244&view=rev Author: slackydeb Date: 2008-08-15 22:47:24 +0000 (Fri, 15 Aug 2008) Log Message: ----------- cleaned ga function tests; modified the invocation of the creation function in the __ga_initial_population__ function to prevent bugs (a modified PopulationSize can be misunderstood by the creation function); hardcode some expectations removing asserts Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_initial_population__.m trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gacreationuniform.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-15 12:54:44 UTC (rev 5243) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-15 22:47:24 UTC (rev 5244) @@ -1,12 +1,12 @@ Name: ga -Version: 0.9.0 -Date: 2008-08-14 +Version: 0.9.1 +Date: 2008-08-16 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Description: Genetic optimization code Categories: Optimization -Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.6), communications (>= 1.0.0) +Depends: octave (>= 2.9.7), communications (>= 1.0.0) Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net Modified: trunk/octave-forge/main/ga/inst/__ga_initial_population__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_initial_population__.m 2008-08-15 12:54:44 UTC (rev 5243) +++ trunk/octave-forge/main/ga/inst/__ga_initial_population__.m 2008-08-15 22:47:24 UTC (rev 5244) @@ -21,43 +21,38 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.1 +## Version: 3.2 #TODO consider PopulationSize as a #vector for multiple subpopolations function Population = \ __ga_initial_population__ (GenomeLength, FitnessFcn, options) - [nr, nc] = size (options.InitialPopulation); - if (nc == 0) - Population = options.CreationFcn (GenomeLength, FitnessFcn, options); + [nr nc] = size (options.InitialPopulation); + if ((nr == 0) || (nc == 0)) + Population(1:options.PopulationSize, 1:GenomeLength) = \ + options.CreationFcn (GenomeLength, FitnessFcn, options); elseif (nc == GenomeLength) - ## it is impossible to have a matrix with 0 rows and a positive - ## number of columns - ## - ## so, here nr > 0 + ## nr > 0 if (nr < options.PopulationSize) - OptionsWithModifiedPopulationSize = \ - setfield (options, - "PopulationSize", - options.PopulationSize - nr); - CreatedPartialPopulation = \ - options.CreationFcn (GenomeLength, - FitnessFcn, - OptionsWithModifiedPopulationSize); - Population = \ - vertcat (options.InitialPopulation(1:nr, - 1:GenomeLength), - CreatedPartialPopulation(1:(options.PopulationSize - nr), - 1:GenomeLength)); + + ## create a complete new population, and then select only needed + ## individuals (creating only a partial population is difficult) + CreatedPopulation(1:options.PopulationSize, 1:GenomeLength) = \ + options.CreationFcn (GenomeLength, FitnessFcn, options); + Population(1:options.PopulationSize, 1:GenomeLength) = \ + vertcat (options.InitialPopulation(1:nr, 1:GenomeLength), + CreatedPopulation(1:(options.PopulationSize - nr), + 1:GenomeLength)); elseif (nr == options.PopulationSize) - Population = options.InitialPopulation; + Population(1:options.PopulationSize, 1:GenomeLength) = \ + options.InitialPopulation; else ## nr > options.PopulationSize error ("nonempty 'InitialPopulation' must have no more than \ 'PopulationSize' rows"); endif - else + else ## (nc != 0) && (nc != GenomeLength) error ("nonempty 'InitialPopulation' must have 'GenomeLength' \ columns"); endif Modified: trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-15 12:54:44 UTC (rev 5243) +++ trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-15 22:47:24 UTC (rev 5244) @@ -14,7 +14,7 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1 +## Version: 1.2.1 function mutationChildren = \ __ga_mutationfcn__ (parents, options, nvars, FitnessFcn, @@ -22,21 +22,15 @@ thisPopulation) ## preconditions - [nr_parents nc_parents] = size (parents); - assert (nr_parents, 1); ## DEBUG #TODO move controls on #options.PopInitRange in a more general #function [nrPopInitRange, ncPopInitRange] = size (options.PopInitRange); assert (nrPopInitRange, 2); ## DEBUG assert ((ncPopInitRange == 1) || (ncPopInitRange == nvars)); ## DEBUG - assert (columns (thisPopulation), nvars); ## DEBUG - mutationChildren = \ - options.MutationFcn{1, 1} (parents, options, nvars, FitnessFcn, + mutationChildren(1:(columns (parents)), 1:nvars) = \ + options.MutationFcn{1, 1} (parents(1, :), options, nvars, FitnessFcn, state, thisScore, - thisPopulation); - - ## postconditions - assert (size (mutationChildren), [nc_parents, nvars]); ## DEBUG + thisPopulation(:, 1:nvars)); endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-15 12:54:44 UTC (rev 5243) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-15 22:47:24 UTC (rev 5244) @@ -71,7 +71,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.10 +## Version: 5.19.1 function [x fval exitflag output population scores] = \ ga (fitnessfcn_or_problem, @@ -114,26 +114,33 @@ endif endfunction -%!xtest assert (ga (@(x) x ** 2, 1, [], [], [], [], [], [], [], gaoptimset ('EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) +%!# nvars == 2 +%!# min != zeros (1, nvars) -%!function retval = test_pseudo_rastriginsfcn (x) -%! retval = (x ** 2) - (cos (2 * pi * x)) + 1; +%!xtest +%! min = [-1, 2]; +%! assert (ga (struct ("fitnessfcn", @(x) rastriginsfcn (x - min), "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "Generations", 1000, "PopInitRange", [-5; 5], "PopulationSize", 200))), min, 1e-6) -%!xtest assert (ga (@test_pseudo_rastriginsfcn, 1, [], [], [], [], [], [], [], gaoptimset ('EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) -%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-6) +%!# nvars == 1 +%!# min == zeros (1, nvars) -%!function retval = test_bias_rastriginsfcn (t) -%! min = [1, 0]; -%! x = t - min; -%! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); +%!test assert (ga (@(x) x ** 2, 1), 0, 1e-3) -%!xtest assert (ga (@test_bias_rastriginsfcn, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) +%!test assert (ga (@(x) (x ** 2) - (cos (2 * pi * x)) + 1, 1), 0, 1e-3) -%!function retval = test_4_variables (x) -%! retval = 0; -%! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; -%! retval += x(4) ** 2; -%!xtest assert (ga (@test_4_variables, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) \ No newline at end of file +%!# nvars == 2 +%!# min == zeros (1, nvars) + +%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-3) + +%!xtest assert (ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "Generations", 1000))), zeros (1, 2), 1e-6) + +%!xtest assert (ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "PopulationSize", 200))), zeros (1, 2), 1e-6) + + +%!# nvars == 4 +%!# min == zeros (1, nvars) + +%!xtest assert (ga (struct ("fitnessfcn", @(x) rastriginsfcn (x(1:2)) + ((x(3) ** 2) - (cos (2 * pi * x(3))) + 1) + (x(4) ** 2), "nvars", 4, "options", gaoptimset ("EliteCount", 5, "FitnessLimit", 1e-7, "PopInitRange", [-2; 2], "PopulationSize", 200))), zeros (1, 4), 1e-6) \ 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-15 12:54:44 UTC (rev 5243) +++ trunk/octave-forge/main/ga/inst/gacreationuniform.m 2008-08-15 22:47:24 UTC (rev 5244) @@ -37,37 +37,28 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.5 +## Version: 4.7.2 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) - [nr, nc] = size (options.PopInitRange); - #if ((nr != 2) - # ((nc != 1) && (nc != GenomeLength))) - # error ("'PopInitRange' must be 2-by-1 or 2-by-GenomeLength"); - #endif - ## obtain a 2-by-GenomeLength LocalPopInitRange - LocalPopInitRange = options.PopInitRange; - if (nc == 1) - LocalPopInitRange = LocalPopInitRange * ones (1, GenomeLength); - endif + switch (columns (options.PopInitRange)) + case 1 + LocalPopInitRange(1:2, 1:GenomeLength) = \ + options.PopInitRange(1:2, 1) * ones (1, GenomeLength); + case GenomeLength + LocalPopInitRange(1:2, 1:GenomeLength) = \ + options.PopInitRange(1:2, 1:GenomeLength); + endswitch - LB = LocalPopInitRange(1, 1:GenomeLength); - UB = LocalPopInitRange(2, 1:GenomeLength); + LB(1, 1:GenomeLength) = LocalPopInitRange(1, 1:GenomeLength); + UB(1, 1:GenomeLength) = LocalPopInitRange(2, 1:GenomeLength); ## pseudocode ## ## Population = Delta * RandomPopulationBetween0And1 + Offset - Population = \ + Population(1:options.PopulationSize, 1:GenomeLength) = \ ((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); -%! assert (size (Population), [options.PopulationSize, GenomeLength]); \ No newline at end of file +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. |