From: <sla...@us...> - 2008-08-13 22:12:05
|
Revision: 5240 http://octave.svn.sourceforge.net/octave/?rev=5240&view=rev Author: slackydeb Date: 2008-08-13 22:12:12 +0000 (Wed, 13 Aug 2008) Log Message: ----------- modularize to semplify debug Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/__ga_scores__.m trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/fitscalingrank.m trunk/octave-forge/main/ga/inst/mutationgaussian.m trunk/octave-forge/main/ga/inst/selectionstochunif.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-13 22:12:12 UTC (rev 5240) @@ -1,6 +1,6 @@ Name: ga -Version: 0.7.3 -Date: 2008-08-12 +Version: 0.8.0 +Date: 2008-08-14 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Added: trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_crossoverfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,38 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.1.4 + +function xoverKids = __ga_crossoverfcn__ (parents, options, nvars, FitnessFcn, + unused, + thisPopulation) + + ## preconditions + [nr_parents nc_parents] = size (parents); + assert (nr_parents, 1); ## DEBUG + assert (rem (nc_parents, 2), 0); ## DEBUG + assert (columns (thisPopulation), nvars); ## DEBUG + + xoverKids = options.CrossoverFcn (parents, options, nvars, FitnessFcn, + unused, + thisPopulation); + + ## postconditions + assert (size (xoverKids), [(nc_parents / 2) nvars]); ## DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_mutationfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,45 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0.4 + +function mutationChildren = \ + __ga_mutationfcn__ (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation) + + ## preconditions + [nr_parents nc_parents] = size (parents); + assert (nr_parents, 1); ## DEBUG + #TODO move controls on + #options.PopInitRange in a more general + #function + [nrPopInitRange, ncPopInitRange] = size (options.PopInitRange); + assert (nrPopInitRange, 2); ## DEBUG + assert ((ncPopInitRange == 1) || (ncPopInitRange == nvars)); ## DEBUG + assert (columns (thisPopulation), nvars); ## DEBUG + + mutationChildren = \ + options.MutationFcn{1, 1} (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation); + + ## postconditions + assert (size (mutationChildren), [nc_parents, nvars]); ## DEBUG +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -17,22 +17,8 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.2 +## Version: 5.7.1 - #state structure fields - #DONE state.Population - #DONE state.Score - #DONE state.Generation - #DONE state.StartTime - #state.StopFlag - #DONE state.Selection - #DONE state.Expectation - #DONE state.Best - #state.LastImprovement - #state.LastImprovementTime - #state.NonlinIneq - #state.NonlinEq - function [x fval exitflag output population scores] = __ga_problem__ (problem) ## first instruction @@ -47,126 +33,83 @@ __ga_initial_population__ (problem.nvars, problem.fitnessfcn, problem.options); - state.Score(1:problem.options.PopulationSize, 1) = \ - __ga_scores__ (problem.fitnessfcn, - state.Population, - problem.options.InitialScores); state.Generation = 0; - - ReproductionCount.elite = problem.options.EliteCount; - ReproductionCount.crossover = \ - fix (problem.options.CrossoverFraction * - (problem.options.PopulationSize - problem.options.EliteCount)); - ReproductionCount.mutation = \ - problem.options.PopulationSize - (ReproductionCount.elite + - ReproductionCount.crossover); - #assert (ReproductionCount.elite + - # ReproductionCount.crossover + - # ReproductionCount.mutation, problem.options.PopulationSize); ## DEBUG - - state.Selection.elite = 1:ReproductionCount.elite; - state.Selection.crossover = \ - ReproductionCount.elite + (1:ReproductionCount.crossover); - state.Selection.mutation = \ - ReproductionCount.elite + ReproductionCount.crossover + \ - (1:ReproductionCount.mutation); - #assert (length (state.Selection.elite) + - # length (state.Selection.crossover) + - # length (state.Selection.mutation), - # problem.options.PopulationSize); ##DEBUG - - parentsCount.crossover = 2 * ReproductionCount.crossover; - parentsCount.mutation = 1 * ReproductionCount.mutation; - nParents = parentsCount.crossover + parentsCount.mutation; - - parentsSelection.crossover = 1:parentsCount.crossover; - parentsSelection.mutation = \ - parentsCount.crossover + (1:parentsCount.mutation); - #assert (length (parentsSelection.crossover) + - # length (parentsSelection.mutation), nParents); ## DEBUG + private_state = __ga_problem_private_state__ (problem.options); + state.Selection = __ga_problem_state_selection__ (private_state, + problem.options); ## end "instructions not to be executed at each generation" ## start "instructions to be executed at each generation" - state.Expectation(1, 1:problem.options.PopulationSize) = \ - problem.options.FitnessScalingFcn (state.Score, nParents); - state.Best(state.Generation + 1, 1) = min (state.Score); + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); ## end "instructions to be executed at each generation" while (! __ga_stop__ (problem, state)) ## fix a generation ## elite - if (ReproductionCount.elite > 0) + if (private_state.ReproductionCount.elite > 0) [trash IndexSortedScores] = sort (state.Score); NextPopulation(state.Selection.elite, 1:problem.nvars) = \ - state.Population(IndexSortedScores(1:ReproductionCount.elite, 1), - 1:problem.nvars); - #assert (size (NextPopulation), - # [ReproductionCount.elite, problem.nvars]); ## DEBUG + state.Population \ + (IndexSortedScores(1:private_state.ReproductionCount.elite, 1), + 1:problem.nvars); + assert (size (NextPopulation), + [private_state.ReproductionCount.elite, problem.nvars]); ## DEBUG endif ## selection for crossover and mutation - parents = problem.options.SelectionFcn (state.Expectation, - nParents, - problem.options); - #assert (size (parents), [1, nParents]); ## DEBUG + parents = __ga_selectionfcn__ \ + (state.Expectation, private_state.nParents, problem.options); ## crossover - if (ReproductionCount.crossover > 0) + if (private_state.ReproductionCount.crossover > 0) NextPopulation(state.Selection.crossover, 1:problem.nvars) = \ - problem.options.CrossoverFcn (parents(1, parentsSelection.crossover), - problem.options, - problem.nvars, - problem.fitnessfcn, - false, ## unused - state.Population); - tmp = ReproductionCount.elite + ReproductionCount.crossover; - #assert (size (NextPopulation), [tmp, problem.nvars]); ## DEBUG + __ga_crossoverfcn__ \ + (parents(1, private_state.parentsSelection.crossover), + problem.options, problem.nvars, problem.fitnessfcn, + false, ## unused + state.Population); + tmp = \ + private_state.ReproductionCount.elite + \ + private_state.ReproductionCount.crossover; + assert (size (NextPopulation), [tmp, problem.nvars]); ## DEBUG endif ## mutation - if (ReproductionCount.mutation > 0) + if (private_state.ReproductionCount.mutation > 0) NextPopulation(state.Selection.mutation, 1:problem.nvars) = \ - problem.options.MutationFcn{1, 1} (parents(1, - parentsSelection.mutation), - problem.options, - problem.nvars, - problem.fitnessfcn, - state, - state.Score, - state.Population); - #assert (size (NextPopulation), - # [problem.options.PopulationSize, problem.nvars]); ## DEBUG + __ga_mutationfcn__ \ + (parents(1, private_state.parentsSelection.mutation), + problem.options, problem.nvars, problem.fitnessfcn, + state, state.Score, + state.Population); + assert (size (NextPopulation), + [problem.options.PopulationSize, problem.nvars]); ## DEBUG endif ## update state structure state.Population(1:problem.options.PopulationSize, 1:problem.nvars) = NextPopulation; clear -v NextPopulation; - state.Score(1:problem.options.PopulationSize, 1) = \ - __ga_scores__ (problem.fitnessfcn, state.Population); state.Generation++; - state.Expectation(1, 1:problem.options.PopulationSize) = \ - problem.options.FitnessScalingFcn (state.Score, nParents); - state.Best(state.Generation + 1, 1) = min (state.Score); + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); endwhile - ## return variables - ## - [trash IndexMinScore] = min (state.Score); - x = state.Population(IndexMinScore, 1:problem.nvars); + [x fval exitflag output population scores] = \ + __ga_problem_return_variables__ (state, problem); +endfunction - fval = problem.fitnessfcn (x); - - #TODO exitflag - - ## output.randstate and output.randnstate must be assigned at the - ## start of the algorithm - output.generations = state.Generation; - #TODO output.funccount - #TODO output.message - #TODO output.maxconstraint - - population = state.Population; - - scores = state.Score; -endfunction \ No newline at end of file + #state structure fields + #DONE state.Population + #DONE state.Score + #DONE state.Generation + #DONE state.StartTime + #state.StopFlag + #DONE state.Selection + #DONE state.Expectation + #DONE state.Best + #state.LastImprovement + #state.LastImprovementTime + #state.NonlinIneq + #state.NonlinEq \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_private_state__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,53 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0 + +function private_state = __ga_problem_private_state__ (options) + #start private_state + private_state.ReproductionCount.elite = options.EliteCount; + private_state.ReproductionCount.crossover = \ + fix (options.CrossoverFraction * + (options.PopulationSize - options.EliteCount)); + private_state.ReproductionCount.mutation = \ + options.PopulationSize - \ + (private_state.ReproductionCount.elite + + private_state.ReproductionCount.crossover); + assert (private_state.ReproductionCount.elite + + private_state.ReproductionCount.crossover + + private_state.ReproductionCount.mutation, + options.PopulationSize); ## DEBUG + + private_state.parentsCount.crossover = \ + 2 * private_state.ReproductionCount.crossover; + private_state.parentsCount.mutation = \ + 1 * private_state.ReproductionCount.mutation; + private_state.nParents = \ + private_state.parentsCount.crossover + \ + private_state.parentsCount.mutation; + + private_state.parentsSelection.crossover = \ + 1:private_state.parentsCount.crossover; + private_state.parentsSelection.mutation = \ + private_state.parentsCount.crossover + \ + (1:private_state.parentsCount.mutation); + assert (length (private_state.parentsSelection.crossover) + + length (private_state.parentsSelection.mutation), + private_state.nParents); ## DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_return_variables__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,41 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0 + +function [x fval exitflag output population scores] = \ + __ga_problem_return_variables__ (state, problem) + [trash IndexMinScore] = min (state.Score); + x = state.Population(IndexMinScore, 1:problem.nvars); + + fval = problem.fitnessfcn (x); + + #TODO exitflag + + ## output.randstate and output.randnstate must be assigned at the + ## start of the algorithm + output.generations = state.Generation; + #TODO output.funccount + #TODO output.message + #TODO output.maxconstraint + + population = state.Population; + + scores = state.Score; +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_state_selection__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,35 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0 + +function Selection = __ga_problem_state_selection__ (private_state, options) + Selection.elite = 1:private_state.ReproductionCount.elite; + Selection.crossover = \ + private_state.ReproductionCount.elite + \ + (1:private_state.ReproductionCount.crossover); + Selection.mutation = \ + private_state.ReproductionCount.elite + \ + private_state.ReproductionCount.crossover + \ + (1:private_state.ReproductionCount.mutation); + assert (length (Selection.elite) + + length (Selection.crossover) + + length (Selection.mutation), + options.PopulationSize); ##DEBUG +endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_problem_update_state_at_each_generation__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,36 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.1 + +function state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state) + if (state.Generation > 0) + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, state.Population); + else ## state.Generation == 0 + state.Score(1:problem.options.PopulationSize, 1) = \ + __ga_scores__ (problem.fitnessfcn, + state.Population, + problem.options.InitialScores); + endif + state.Expectation(1, 1:problem.options.PopulationSize) = \ + problem.options.FitnessScalingFcn (state.Score, private_state.nParents); + state.Best(state.Generation + 1, 1) = min (state.Score); +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__ga_scores__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -17,18 +17,18 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 5.2 +## Version: 5.2.1 function Scores = __ga_scores__ (fitnessfcn, Population, InitialScores = []) - [nrP ncP] = size (Population); - [nrIS ncIS] = size (InitialScores); - #assert ((ncIS == 0) || (ncIS == 1)); ## DEBUG - #assert (nrIS <= nrP); ## DEBUG - if (nrIS > 0) - Scores(1:nrIS, 1) = InitialScores(1:nrIS, 1); + [nrPopulation ncPopulation] = size (Population); + [nrInitialScores ncInitialScores] = size (InitialScores); + #assert ((ncInitialScores == 0) || (ncInitialScores == 1)); ## DEBUG + #assert (nrInitialScores <= nrPopulation); ## DEBUG + if (nrInitialScores > 0) + Scores(1:nrInitialScores, 1) = InitialScores(1:nrInitialScores, 1); endif - for index = (nrIS + 1):nrP - Scores(index, 1) = fitnessfcn (Population(index, 1:ncP)); + for index = (nrInitialScores + 1):nrPopulation + Scores(index, 1) = fitnessfcn (Population(index, 1:ncPopulation)); endfor - #assert (size (Scores), [nrP 1]); ## DEBUG + #assert (size (Scores), [nrPopulation 1]); ## DEBUG endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_selectionfcn__.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -0,0 +1,31 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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, 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; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## Author: Luca Favatella <sla...@gm...> +## Version: 1.0.2 + +function parents = __ga_selectionfcn__ (expectation, nParents, options) + + ## preconditions + assert (rows (expectation), 1); ## DEBUG + + parents = options.SelectionFcn (expectation, nParents, options); + + ## postconditions + assert (size (parents), [1 nParents]); ## DEBUG +endfunction \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,24 +16,13 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{xoverKids} =} crossoverscattered (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{unused}, @var{thisPopulation}) -## Combine two individuals, or parents, to form a crossover child. -## -## @seealso{ga, gaoptimset} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 6.2 +## Version: 6.2.5 -function xoverKids = \ - crossoverscattered (parents, - options, nvars, FitnessFcn, unused, - thisPopulation) - [nr_parents nc_parents] = size (parents); - #assert (nr_parents, 1); ## DEBUG - #assert (rem (nc_parents, 2), 0); ## DEBUG - #assert (columns (thisPopulation), nvars); ## DEBUG +function xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, + unused, + thisPopulation) + nc_parents = columns (parents); ## simplified example (nvars == 4) ## p1 = [varA varB varC varD] Modified: trunk/octave-forge/main/ga/inst/fitscalingrank.m =================================================================== --- trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/fitscalingrank.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,17 +16,8 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{expectation} =} fitscalingrank (@var{scores}, @var{nParents}) -## Convert the raw fitness scores that are returned by the fitness -## function to values in a range that is suitable for the selection -## function. -## -## @seealso{ga, gaoptimset} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 1.1 +## Version: 1.1.1 function expectation = fitscalingrank (scores, nParents) [nr nc] = size (scores); Modified: trunk/octave-forge/main/ga/inst/mutationgaussian.m =================================================================== --- trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/mutationgaussian.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,26 +16,15 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{mutationChildren} =} mutationgaussian (@var{parents}, @var{options}, @var{nvars}, @var{FitnessFcn}, @var{state}, @var{thisScore}, @var{thisPopulation}) -## Single point mutation. -## -## @seealso{ga, gaoptimset} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 +## Version: 1.4.4 function mutationChildren = \ - mutationgaussian (parents, - options, nvars, FitnessFcn, state, - thisScore, thisPopulation) - [nr_parents nc_parents] = size (parents); - #assert (nr_parents, 1); ## DEBUG - [nrPopInitRange, ncPopInitRange] = size (options.PopInitRange); - #assert (nrPopInitRange, 2); ## DEBUG - #assert ((ncPopInitRange == 1) || (ncPopInitRange == nvars)); ## DEBUG - #assert (columns (thisPopulation), nvars); ## DEBUG + mutationgaussian (parents, options, nvars, FitnessFcn, + state, thisScore, + thisPopulation) + nc_parents = columns (parents); + ncPopInitRange = columns (options.PopInitRange); ## obtain a 2-by-nvars LocalPopInitRange LocalPopInitRange = options.PopInitRange; Modified: trunk/octave-forge/main/ga/inst/selectionstochunif.m =================================================================== --- trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-13 14:03:22 UTC (rev 5239) +++ trunk/octave-forge/main/ga/inst/selectionstochunif.m 2008-08-13 22:12:12 UTC (rev 5240) @@ -16,32 +16,22 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -## -*- texinfo -*- -## @deftypefn{Function File} {@var{parents} =} selectionstochunif (@var{expectation}, @var{nParents}, @var{options}) -## Choose parents. -## -## @seealso{ga} -## @end deftypefn - ## Author: Luca Favatella <sla...@gm...> -## Version: 1.2 +## Version: 1.2.4 function parents = selectionstochunif (expectation, nParents, options) - [nr nc] = size (expectation); - #assert (nr, 1); ## DEBUG - line(1, 1:nc) = cumsum (expectation(1, 1:nc)); - max_step_size = line(1, nc); + nc_expectation = columns (expectation); + line(1, 1:nc_expectation) = cumsum (expectation(1, 1:nc_expectation)); + max_step_size = line(1, nc_expectation); step_size = max_step_size * rand (); steps(1, 1:nParents) = rem (step_size * ones (1, nParents), max_step_size); - for index_steps = 1:nParents ## fix an entry of the steps (or parents) vector #assert (steps(1, index_steps) < max_step_size); ## DEBUG index_line = 1; while (steps(1, index_steps) >= line(1, index_line)) - #assert ((index_line >= 1) && (index_line < nc)); ## DEBUG + #assert ((index_line >= 1) && (index_line < nc_expectation)); ## DEBUG index_line++; endwhile parents(1, index_steps) = index_line; endfor - #assert (size (parents), [1 nParents]); ## DEBUG 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. |