X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Fga-0.10.0%2Fgaoptimset.m;fp=octave_packages%2Fga-0.10.0%2Fgaoptimset.m;h=dbc70afe6f9ba891c331c522baa70f4cf30087d9;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/ga-0.10.0/gaoptimset.m b/octave_packages/ga-0.10.0/gaoptimset.m new file mode 100644 index 0000000..dbc70af --- /dev/null +++ b/octave_packages/ga-0.10.0/gaoptimset.m @@ -0,0 +1,121 @@ +## Copyright (C) 2008, 2009, 2010 Luca Favatella +## +## 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 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; If not, see . + +## -*- texinfo -*- +## @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. +## +## @strong{Inputs} +## @table @var +## @item param +## Parameter to set. Unspecified parameters are set to their default +## values; specifying no parameters is allowed. +## @item value +## Value of @var{param}. +## @end table +## +## @strong{Outputs} +## @table @var +## @item options +## Structure containing the options, or parameters, for the genetic algorithm. +## @end table +## +## @strong{Options} +## @table @code +## @item CreationFcn +## @item CrossoverFcn +## @item CrossoverFraction +## @item EliteCount +## @item FitnessLimit +## @item FitnessScalingFcn +## @item Generations +## @item InitialPopulation +## Can be partial. +## @item InitialScores +## column vector | [] (default) . Can be partial. +## @item MutationFcn +## @item PopInitRange +## @item PopulationSize +## @item SelectionFcn +## @item TimeLimit +## @item UseParallel +## "always" | "never" (default) . Parallel evaluation of objective function. TODO: parallel evaluation of nonlinear constraints +## @item Vectorized +## "on" | "off" (default) . Vectorized evaluation of objective function. TODO: vectorized evaluation of nonlinear constraints +## @end table +## +## @seealso{ga} +## @end deftypefn + +## Author: Luca Favatella +## Version: 4.4.7 + +function options = gaoptimset (varargin) + if ((nargout != 1) || + (mod (length (varargin), 2) == 1)) + print_usage (); + else + + ## initialize the return variable to a structure with all parameters + ## set to their default value + options = __gaoptimset_default_options__ (); + + ## 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 + endfor + endif +endfunction + + +## number of input arguments +%!error options = gaoptimset ("odd number of arguments") +%!error options = gaoptimset ("Generations", 123, "odd number of arguments") + +## number of output arguments +%!error gaoptimset ("Generations", 123) +%!error [a, b] = gaoptimset ("Generations", 123) + +## type of arguments +# TODO +%!#error options = gaoptimset ("Vectorized", "bad value") # TODO: fix +%!#error options = gaoptimset ("UseParallel", "bad value") # TODO: fix + +# TODO: structure/add tests below + +%!assert (getfield (gaoptimset ("Generations", 123), "Generations"), 123) + +%!test +%! options = gaoptimset ("EliteCount", 1, +%! "FitnessLimit", 1e-7, +%! "Generations", 1000, +%! "PopInitRange", [-5; 5], +%! "PopulationSize", 200); +%! +%! ## "CrossoverFraction" is not specified, so gaoptimset should put the default value: testing this too +%! assert ([(getfield (options, "CrossoverFraction")); +%! (getfield (options, "EliteCount")); +%! (getfield (options, "FitnessLimit")); +%! (getfield (options, "Generations")); +%! (getfield (options, "PopInitRange")); +%! (getfield (options, "PopulationSize"))], +%! [0.8; 1; 1e-7; 1000; [-5; 5]; 200])