Path: news.mathworks.com!not-for-mail
From: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: output function figure not updating after each iteration
Date: Sat, 6 Sep 2008 16:31:02 +0000 (UTC)
Organization: L &#38; D Engineering LLC
Lines: 48
Message-ID: <g9ub86$kjp$1@fred.mathworks.com>
References: <g9uald$ekt$1@fred.mathworks.com>
Reply-To: "Donn Shull" <donn.shull.no_spam@aetoolbox.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220718662 21113 172.30.248.38 (6 Sep 2008 16:31:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 6 Sep 2008 16:31:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 219306
Xref: news.mathworks.com comp.soft-sys.matlab:488954



Try following your plot statement with a drawnow statement.

Donn

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <g9uald$ekt$1@fred.mathworks.com>...
> I have a ga which is hybridised with fminunc:
> 
> hybrid_options=optimset('OutputFcn',@fminuncOut,'Display','iter','MaxFunEvals',1000,'MaxIter',1000,'TolFun',1e-6,'TolX',1e-6);
> 
> options=gaoptimset('HybridFcn',{@fminunc,hybrid_options},'UseParallel','always','PopInitRange',variable_range,'PopulationSize',25,'CrossoverFraction',0.5,'Generations',10,'StallGenLimit',50,'StallTimeLimit',40,'SelectionFcn',@selectionstochunif,'MutationFcn',{@mutationuniform,0.7},'CrossoverFcn',@crossoverscattered,'PlotFcns',@gaplotbestf},'PlotInterval',1);
> 
> [x,fval,exitflag,output,final_pop]=ga(fitness_fcn,no_variables,[],[],[],[],lower_bound,upper_bound,[],options);
> 
> 
> I have used fminuncOut.m as an output function from the matlab ga toolbox webinar with this intention of getting this:
> http://www.mathworks.com/company/newsletters/digest/sept04/images/results5b_wl.jpg
> 
> This then produces a plot of the GA history followed by the fminunc history. However, it only updates the figure once the optimisation has ended whereas I want it to update after each iteration. Does anyone know how I can make it do so? Thanks.
> 
> 
> fminuncOut.m consists of the following code (with the annotation part removed):
> 
> function stop = fminuncOut(x,optimvalues,state)
> 
> persistent fig gaIter
> stop = false;
> 
> switch state
> 
>     case 'init'
>         fig = findobj(0,'type','figure','name','Genetic Algorithm');
>         limits = get(gca,'XLim');
>         gaIter = limits(2);
>         hold on;
>     case 'iter'
>         set(gca,'Xlim', [1 optimvalues.iteration + gaIter]);
>         fval = optimvalues.fval;
>         iter = gaIter + optimvalues.iteration;
>         plot(iter,fval,'dr')
>         title(['Best function value: ',num2str(fval)],'interp','none')
>     case 'done'
>         fval = optimvalues.fval;
>         iter = gaIter + optimvalues.iteration;
>         hold off
> end
> 
>