How can I fix SOLVE ignores UseParallel when derivatives calculated automatic differentiation warning for parallel computing?
조회 수: 1 (최근 30일)
이전 댓글 표시
I coded an NLP version of the p-median problem which I am solving by fmincon. I wanted to use UseParallel to speed up the process. But I get the fallowing warning: SOLVE ignores UseParallel when derivatives calculated using Automatic Differentiation. Could you please show me how to use parallel computing with such a code?
A = readmatrix("Iris.csv");
A = A(:,1:5);
A = normalize(A);
dist_mat = pdist(A);
dist_mat = squareform(dist_mat);
x0x = zeros(150,150) + 1/150;
x0y = zeros(150,1) + 1/150;
% Create optimization variables
x = optimvar("x",150,150,"LowerBound",0,"UpperBound",1);
y = optimvar("y",150,1,"LowerBound",0,"UpperBound",1);
% Set initial starting point for the solver
initialPoint.x = x0x;
initialPoint.y = x0y;
% Create problem
problem = optimproblem;
% Define problem objective
problem.Objective = sum(dist_mat.*x,...
'all')+ sum(50.*(y.^2)./((y.^2) + 0.001));
% Define problem constraints
problem.Constraints.Xeq = sum(x,2)==1;
problem.Constraints.Yeq = sum(y)==2;
problem.Constraints.XYineq = x - repmat(y',150,1) <= 0;
% Set nondefault solver options
options = optimoptions("fmincon","Algorithm","interior-point", ...
"HessianApproximation","lbfgs","UseParallel",true,"MaxIterations",10000,"MaxFunctionEvaluations",10000,"Display","iter");
% Display problem information
%show(problem);
% Solve problem
[solution,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint,...
"Solver","fmincon","Options",options);
댓글 수: 0
답변 (1개)
Matt J
2022년 8월 21일
It's not something to fix. It's what you want. Analytical differentiation is the fastest option, when it is available.
댓글 수: 2
Matt J
2022년 8월 21일
You might be able to do a little better if you use fmincon directly and use SpecifyObjectiveGradient=true. I wouldn't expect a huge improvement.
In either case, UseParallel is not the path to optimal speed here. Your gradients are nice and simple and can be computed analytically.
참고 항목
카테고리
Help Center 및 File Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!