help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Watching the best fitness in each generation in ga


From: Hamed Abdy
Subject: Re: Watching the best fitness in each generation in ga
Date: Wed, 9 May 2012 12:07:49 +0430



On Wed, May 9, 2012 at 10:33 AM, Hamed Abdy <address@hidden> wrote:

On Wed, May 9, 2012 at 3:17 AM, Jordi Gutiérrez Hermoso <address@hidden> wrote:
On 8 May 2012 16:53, Hamed Abdy <address@hidden> wrote:
> My question is about the ga command:
> Is it possible to get the best fitness of each generation in ga (for example
> for ploting it)?

From my understanding of it, the 6th output argument of ga contains
this information. So you can do,

   [x, ~, ~, ~, ~, fitness] = ga(stuff, more, stuff)

to get those values.

HTH,
- Jordi G. H.


Thank you, Jordi.
But the 6th output argument of ga just contains fitness of the last generation.
If you had 500 generations, it will only show the fitnesses (containing the best one) of all particles in the 500th generation.
My question is: how can we get the best fitness of all 500 generations?

Hamed Abdy

Thanks to everybody, specially Jordie,
I did it with a little hack in ga package:

-----------------------------------------------------------------------------------
1. In "ga.m":

change this:
function [x fval exitflag output population scores] = \
into this:
function [x fval exitflag output population scores bestscores] = \

this:
  if ((nargout > 6) ||
into this:
  if ((nargout > 7) ||

and this:
    [x fval exitflag output population scores] = __ga_problem__ (problem);
into this:
    [x fval exitflag output population scores bestscores] = __ga_problem__ (problem);

2. In "__ga_problem__.m":

change this:
function [x fval exitflag output population scores] = __ga_problem__ (problem)
into this:
function [x fval exitflag output population scores bestscores] = __ga_problem__ (problem)

and add this before "endwhile":
    bestscores(state.Generation) = min(state.Score);
-----------------------------------------------------------------------------------
By applying these changes, you can get the best scores in each generation as the 7th output of ga function.
For example, you can use it like this:

[x, bestfit, exitflag, output, population, scores, bestscores] = ga(@fitnessfunc, numofdims, [], [], [], [], Xmininit, Xmaxinit, [], options);



These changes may slow down evaluating ga command.
Please do these changes at your own risk.
I won't be responsible for breaking or slowing down your ga package.

Best regards,

Hamed Abdy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]