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] |