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