Thread Subject: GA parallel computing toolbox error

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 20 Aug, 2008 14:16:03

Message: 1 of 4

Hi, I have a genetic algorithm optimization function which
I am trying to run using the parallel computing toolbox as
explained here:
http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html&http
://www.google.co.uk/search?
hl=en&q=matlab+custom+plot+function&meta=

The GA works fine without running it in parallel, but when
I open the matlabpool, the GA then returns the following
error: ??? Error using ==> makeState at 50
GA cannot continue because user supplied fitness function
failed with the following error:
Error using ==> reshape
To RESHAPE the number of elements must not change.

From the debugger, this appears to be happening when it is
trying to score each member of the population:

% Score each member of the population
    if strcmpi(options.Vectorized, 'off')
        try
            Score = fcnvectorizer(state.Population
(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserF
cn);
        catch
            error('gads:makestate:fitnessCheck', ...
                'GA cannot continue because user supplied
fitness function failed with the following error:\n%s',
lasterr)
        end

Anyone any ideas why this would be happening? I'm not sure
what details of my code are needed so feel free to ask for
additional information. My version is 2008a (7.6.0.324).

Thanks.

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 20 Aug, 2008 15:47:02

Message: 2 of 4

> I am trying to run using the parallel computing toolbox
as
> explained here:
>
http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
>
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html&http
> ://www.google.co.uk/search?
> hl=en&q=matlab+custom+plot+function&meta=

Sorry, the correct url for this is

http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html


Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 21 Aug, 2008 10:09:02

Message: 3 of 4

As i am using global variables i wonder if it is related to
this:

"Persistent or global variables. If your objective or
constraint functions use persistent or global variables,
these variables may take different values on different
worker processors. Furthermore, they may not be cleared
properly on the worker processors."

Does anyone know how to use local variables with the GA
objective function?

Subject: GA parallel computing toolbox error

From: Dave Brackett

Date: 26 Aug, 2008 13:25:03

Message: 4 of 4

> Does anyone know how to use local variables with the GA
> objective function?

I have since solved this problem myself. To pass variables
to a GA the fitness function must be specified as shown in
the example below:

FitnessFcn=@(x)m_file_fitness_calc(x,other variables...)

then the ga is called using as: ga(FitnessFcn,other
options...) etc.

Global variables was indeed causing the initial problem and
once changed into local varibles using this method, the
errors were eliminated.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
ga Dave Brackett 20 Aug, 2008 10:20:03
parallel Dave Brackett 20 Aug, 2008 10:20:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com