From: <sla...@us...> - 2012-03-24 16:33:20
|
Revision: 10029 http://octave.svn.sourceforge.net/octave/?rev=10029&view=rev Author: slackydeb Date: 2012-03-24 16:33:14 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: style fix Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:02 UTC (rev 10028) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:14 UTC (rev 10029) @@ -133,6 +133,7 @@ # TODO # TODO: test that each field in the user-specified "problem" structure is checked + ## flawless execution with right arguments %!shared f, nvars %! f = @rastriginsfcn; @@ -264,6 +265,7 @@ %! options = gaoptimset ("Vectorized", "on"); %! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, options); + ## error with conflicting optimization parameters: population size et al. %!shared f, nvars %! f = @rastriginsfcn; @@ -335,6 +337,7 @@ %! "Vectorized", "garbage"); %! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, bad_options); + # TODO: structure/add tests below %!test x = ga (struct ("fitnessfcn", @(x) rastriginsfcn (x(1:2)) + ((x(3) ** 2) - (cos (2 * pi * x(3))) + 1) + (x(4) ** 2), "nvars", 4, "options", gaoptimset ())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2012-03-24 16:33:37
|
Revision: 10030 http://octave.svn.sourceforge.net/octave/?rev=10030&view=rev Author: slackydeb Date: 2012-03-24 16:33:31 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: fix bad examples of objective functions Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:14 UTC (rev 10029) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:31 UTC (rev 10030) @@ -159,15 +159,17 @@ %! x = ga (problem); ## flawless execution with any nvars +%!function f = ff (nvars) +%! f = @(x) sum (x(:, 1:nvars) .** 2, 2); %!test %! nvars = 1; -%! x = ga (@(x) x(1, 1) ** 2, nvars); +%! x = ga (ff (nvars), nvars); %!test %! nvars = 2; -%! x = ga (@(x) (x(:, 1) ** 2) + (x(:, 2) ** 2), nvars); +%! x = ga (ff (nvars), nvars); %!test %! nvars = 3; -%! x = ga (@(x) (x(:, 1) ** 2) + (x(:, 2) ** 2) + (x(:, 3) ** 2), nvars); +%! x = ga (ff (nvars), nvars); ## flawless execution with any supported optimization parameter ## different from the default value This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2012-03-24 16:33:50
|
Revision: 10031 http://octave.svn.sourceforge.net/octave/?rev=10031&view=rev Author: slackydeb Date: 2012-03-24 16:33:44 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: add unit tests about vectorized evaluation of fitness function Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:31 UTC (rev 10030) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:33:44 UTC (rev 10031) @@ -294,6 +294,35 @@ %! "InitialScores", zeros (ip + 1, 1)); %! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, bad_options); +## error with vectorized evaluation of objective function. Vectorized +## objective functions are better because can be evaluated both as +## serial and vectorized. +%!shared nvars +%! nvars = 2; +%!function [C, Ceq] = nonlcon (x) +%! C = []; +%! Ceq = []; +%!function f = ff (nvars) +%! f = @(x) sum (x(:, 1:nvars) .** 2, 2); +%!function f_not_vectorized = ff_not_vectorized (nvars) +%! f_not_vectorized = @(x) sum (x(1:nvars) .** 2); +%!test # A non-vectorized objective function works when no vectorization is required +%! f = ff_not_vectorized (nvars); +%! options = gaoptimset ("Vectorized", "off"); +%! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, options); +%!error # A non-vectorized objective function does not work when vectorization is required +%! f = ff_not_vectorized (nvars); +%! options = gaoptimset ("Vectorized", "on"); +%! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, options); +%!test # A vectorized objective function works when no vectorization is required +%! f = ff (nvars); +%! options = gaoptimset ("Vectorized", "off"); +%! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, options); +%!test # A vectorized objective function works when vectorization is required +%! f = ff (nvars); +%! options = gaoptimset ("Vectorized", "on"); +%! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, options); + ## error with conflicting optimization parameters: parallel and ## vectorized evaluation of objective function %!shared f, nvars This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2012-03-24 16:34:29
|
Revision: 10034 http://octave.svn.sourceforge.net/octave/?rev=10034&view=rev Author: slackydeb Date: 2012-03-24 16:34:23 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: test error when function requires more nvars than specified Trivial error. Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:34:10 UTC (rev 10033) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:34:23 UTC (rev 10034) @@ -130,6 +130,9 @@ # TODO ## type of arguments +%!function f = ff (nvars) +%! f = @(x) sum (x(:, 1:nvars) .** 2, 2); +%!error x = ga (ff (3), 2); # TODO # TODO: test that each field in the user-specified "problem" structure is checked This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sla...@us...> - 2012-03-24 16:34:59
|
Revision: 10036 http://octave.svn.sourceforge.net/octave/?rev=10036&view=rev Author: slackydeb Date: 2012-03-24 16:34:53 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: test optimization result Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:34:40 UTC (rev 10035) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-24 16:34:53 UTC (rev 10036) @@ -372,14 +372,69 @@ %! x = ga (f, nvars, [], [], [], [], [], [], @nonlcon, bad_options); -# TODO: structure/add tests below - -%!test x = ga (struct ("fitnessfcn", @(x) rastriginsfcn (x(1:2)) + ((x(3) ** 2) - (cos (2 * pi * x(3))) + 1) + (x(4) ** 2), "nvars", 4, "options", gaoptimset ())); - - -# TODO: convert to simple xtests -## nvars == 1 and min == zeros (1, nvars) - -%!test assert (ga (@(x) x ** 2, 1), 0, 1e-3); - -%!test assert (ga (@(x) (x ** 2) - (cos (2 * pi * x)) + 1, 1), 0, 1e-3); +## simple optimization result checks. Failures here could happen because +## of non-determinism in the result but if one of these tests always +## fails for you, plese consider dropping an email to the octave-forge +## mailing list <oct...@li...>. +%!function f = ff (min) +%! f = @(x) sum ((x(:, 1:(columns (min))) - repmat (min, +%! rows (x), 1)) .** 2, 2); +%!function [C, Ceq] = nonlcon (x) +%! C = []; +%! Ceq = []; +%!function r = rand_porcelain (interval_min, interval_max, nvars) +%! assert (interval_min < interval_max); +%! r = interval_min + ((interval_max - interval_min) * rand (1, nvars)); +%!function t = tol (nvars) +%! t = repelems (0.15, [1; nvars]); +%!xtest +%! nvars = 1; +%! minimum = zeros (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 2; +%! minimum = zeros (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 3; +%! minimum = zeros (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 1; +%! minimum = ones (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 2; +%! minimum = ones (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 3; +%! minimum = ones (1, nvars); +%! assert (ga (ff (minimum), nvars), minimum, tol (nvars)); +%!xtest +%! nvars = 1; +%! interval_min = -10; +%! interval_max = 10; +%! minimum = - rand_porcelain (interval_min, interval_max, nvars); +%! options = gaoptimset ("PopInitRange", 2 .* [interval_min; interval_max], +%! "CrossoverFraction", 0.2); +%! x = ga (ff (minimum), nvars, [], [], [], [], [], [], @nonlcon, options); +%! assert (x, minimum, 4 .* tol (nvars)); +%!xtest +%! nvars = 2; +%! interval_min = -10; +%! interval_max = 10; +%! minimum = - rand_porcelain (interval_min, interval_max, nvars); +%! options = gaoptimset ("PopInitRange", 2 .* [interval_min; interval_max], +%! "CrossoverFraction", 0.2); +%! x = ga (ff (minimum), nvars, [], [], [], [], [], [], @nonlcon, options); +%! assert (x, minimum, 4 .* tol (nvars)); +%!xtest +%! nvars = 3; +%! interval_min = -10; +%! interval_max = 10; +%! minimum = - rand_porcelain (interval_min, interval_max, nvars); +%! options = gaoptimset ("PopInitRange", 2 .* [interval_min; interval_max], +%! "CrossoverFraction", 0.2); +%! x = ga (ff (minimum), nvars, [], [], [], [], [], [], @nonlcon, options); +%! assert (x, minimum, 4 .* tol (nvars)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |