Mercurial > forge
changeset 9712:4f0440200a4a octave-forge
ga: rename ga_{test,demo}.m to {test,demo}_ga.m
Mimic the naming scheme of test_control.m from the control package,
as there is no official best practice yet for exposing the unit
test suite.
References:
http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/main/control/inst/test_control.m?revision=9663&view=markup
http://sourceforge.net/mailarchive/message.php?msg_id=28977037
author | slackydeb |
---|---|
date | Thu, 15 Mar 2012 02:24:02 +0000 |
parents | d221e75701b0 |
children | abb5a5595993 |
files | main/ga/inst/demo_ga.m main/ga/inst/ga_demo.m main/ga/inst/ga_test.m main/ga/inst/test_ga.m |
diffstat | 4 files changed, 111 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/ga/inst/demo_ga.m Thu Mar 15 02:24:02 2012 +0000 @@ -0,0 +1,62 @@ +## Copyright (C) 2012 Luca Favatella <slackydeb@gmail.com> +## +## 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 <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn{Script File} {} demo_ga +## Run a demo of the genetic algorithm package. The current +## implementation is only a placeholder. +## @end deftypefn + +## Author: Luca Favatella <slackydeb@gmail.com> +## Created: March 2012 +## Version: 0.0.3 + +demo ga_demo + + +%!demo +%! % TODO + + +## This code is a simple example of the usage of ga + # TODO: convert to demo +%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-3) + + +## This code shows that ga optimizes also functions whose minimum is not +## in zero + # TODO: convert to demo +%!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-5) + + +## This code shows that the "Vectorize" option usually speeds up execution + # TODO: convert to demo +%!test +%! +%! tic (); +%! ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("Generations", 10, "PopulationSize", 200))); +%! elapsed_time = toc (); +%! +%! tic (); +%! ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("Generations", 10, "PopulationSize", 200, "Vectorized", "on"))); +%! elapsed_time_with_vectorized = toc (); +%! +%! assert (elapsed_time > elapsed_time_with_vectorized); + +## The "UseParallel" option should speed up execution + # TODO: write demo (after implementing + # UseParallel) - low priority
--- a/main/ga/inst/ga_demo.m Thu Mar 15 02:23:42 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -## Copyright (C) 2012 Luca Favatella <slackydeb@gmail.com> -## -## 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 <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn{Script File} {} ga_demo -## Run a demo of the genetic algorithm package. The current -## implementation is only a placeholder. -## @end deftypefn - -## Author: Luca Favatella <slackydeb@gmail.com> -## Created: March 2012 -## Version: 0.0.2 - -demo ga_demo - - -%!demo -%! % TODO - - -## This code is a simple example of the usage of ga - # TODO: convert to demo -%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-3) - - -## This code shows that ga optimizes also functions whose minimum is not -## in zero - # TODO: convert to demo -%!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-5) - - -## This code shows that the "Vectorize" option usually speeds up execution - # TODO: convert to demo -%!test -%! -%! tic (); -%! ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("Generations", 10, "PopulationSize", 200))); -%! elapsed_time = toc (); -%! -%! tic (); -%! ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("Generations", 10, "PopulationSize", 200, "Vectorized", "on"))); -%! elapsed_time_with_vectorized = toc (); -%! -%! assert (elapsed_time > elapsed_time_with_vectorized); - -## The "UseParallel" option should speed up execution - # TODO: write demo (after implementing - # UseParallel) - low priority
--- a/main/ga/inst/ga_test.m Thu Mar 15 02:23:42 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -## Copyright (C) 2012 Luca Favatella <slackydeb@gmail.com> -## -## 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 <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn{Script File} {} ga_test -## Execute all available tests at once. -## @end deftypefn - -## Author: Luca Favatella <slackydeb@gmail.com> -## Created: March 2012 -## Version: 0.1.1 - -## Creation -test gacreationuniform - -## Fitness Scaling -test fitscalingrank - -## Selection -test selectionstochunif - -## Crossover -test crossoverscattered - -## Mutation -test mutationgaussian - -## Utility -test rastriginsfcn - -## Genetic Algorithm -test gaoptimset -test ga -## TODO: split performance tests - -## TODO: review all unit tests (DONE: rastriginsfcn) -## TODO: write missing unit tests, or write per-function TODOs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/ga/inst/test_ga.m Thu Mar 15 02:24:02 2012 +0000 @@ -0,0 +1,49 @@ +## Copyright (C) 2012 Luca Favatella <slackydeb@gmail.com> +## +## 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 <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn{Script File} {} test_ga +## Execute all available tests at once. +## @end deftypefn + +## Author: Luca Favatella <slackydeb@gmail.com> +## Created: March 2012 +## Version: 0.2 + +## Creation +test gacreationuniform + +## Fitness Scaling +test fitscalingrank + +## Selection +test selectionstochunif + +## Crossover +test crossoverscattered + +## Mutation +test mutationgaussian + +## Utility +test rastriginsfcn + +## Genetic Algorithm +test gaoptimset +test ga +## TODO: split performance tests + +## TODO: review all unit tests (DONE: rastriginsfcn) +## TODO: write missing unit tests, or write per-function TODOs