Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: output function figure not updating after each iteration
Date: Sat, 6 Sep 2008 16:21:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <g9uald$ekt$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1220718062 15005 172.30.248.38 (6 Sep 2008 16:21:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 6 Sep 2008 16:21:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1338633
Xref: news.mathworks.com comp.soft-sys.matlab:488951



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