Evaluate several objective functions in parallel (parfor)
조회 수: 2 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Walter Roberson
2019년 4월 1일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!