Evaluate several objective functions in parallel (parfor)

2 visualizzazioni (ultimi 30 giorni)
Hello Matlab community,
I am looking for help because I have an issue with parfor and optimization algorithms.
I have an optimization written as follows:
[x,fval] = patternsearch(@ObjFunc,start_par,[],[],[],[],min_par,max_par,@constraints,opts);
I need to optimize the parameters to separately fit an ensemble of curves, stored in an array. To speed the calculation up, I would like to use "parfor".
In my ObjFunc, I have the following code:
load('file.mat');
exp_curve = file(:,li);
where "li" is the loop variable.
Working with a normal "for cycle", I would pass "li" as global. Global variables do not work while using "parfor", and I haven't yet found a way to pass the loop variable to my ObjFunc.
Do you have suggestion that can help me?
Best regards.

Risposta accettata

Walter Roberson
Walter Roberson il 1 Apr 2019
You should avoid loading data inside an objective function, as that function will be called many times. You should instead http://www.mathworks.com/help/matlab/math/parameterizing-functions.html parameterize
That could include,
filestruct = load('file.mat', 'file');
file = filestruct.file;
for li = 1 : whatever
func{i} = @(x) Objfunc(x, file(:,li));
end
parfor li = 1 : whatever
patternsearch(func{i}, ....)
end
or you could
filestruct = load('file.mat', 'file');
file = filestruct.file;
parfor li = 1 : whatever
patternsearch( @(x) Objfunc(x, file(:,li)), ...)
end

Più risposte (0)

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by