PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/R2008-08-24/main/ga/inst/gacreationuniform.m

#
MATLAB | 53 lines | 49 code | 4 blank | 0 comment | 3 complexity | dc0f62c0282113bd856578c4bf2932ac MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. ## Copyright (C) 2008 Luca Favatella <slackydeb@gmail.com>
  2. ##
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2 of the License, or
  6. ## (at your option) any later version.
  7. ##
  8. ## This program is distributed in the hope that it will be useful,
  9. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ## GNU General Public License for more details.
  12. ##
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this program; If not, see <http://www.gnu.org/licenses/>.
  15. ## -*- texinfo -*-
  16. ## @deftypefn{Function File} {@var{Population} =} gacreationuniform (@var{GenomeLength}, @var{FitnessFcn}, @var{options})
  17. ## Create a random initial population with a uniform distribution.
  18. ##
  19. ## @strong{Inputs}
  20. ## @table @var
  21. ## @item GenomeLength
  22. ## The number of indipendent variables for the fitness function.
  23. ## @item FitnessFcn
  24. ## The fitness function.
  25. ## @item options
  26. ## The options structure.
  27. ## @end table
  28. ##
  29. ## @strong{Outputs}
  30. ## @table @var
  31. ## @item Population
  32. ## The initial population for the genetic algorithm.
  33. ## @end table
  34. ##
  35. ## @seealso{ga, gaoptimset}
  36. ## @end deftypefn
  37. ## Author: Luca Favatella <slackydeb@gmail.com>
  38. ## Version: 4.9
  39. function Population = gacreationuniform (GenomeLength, FitnessFcn, options)
  40. [LB(1, 1:GenomeLength) UB(1, 1:GenomeLength)] = \
  41. __ga_popinitrange__ (options.PopInitRange, GenomeLength);
  42. ## pseudocode
  43. ##
  44. ## Population = Delta * RandomPopulationBetween0And1 + Offset
  45. Population(1:options.PopulationSize, 1:GenomeLength) = \
  46. ((ones (options.PopulationSize, 1) * (UB - LB)) .* \
  47. rand (options.PopulationSize, GenomeLength)) + \
  48. (ones (options.PopulationSize, 1) * LB);
  49. endfunction