How can I fix SOLVE ignores UseParallel when derivatives calculated automatic differentiation warning for parallel computing?

1 visualización (últimos 30 días)
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);

Respuestas (1)

Matt J
Matt J el 21 de Ag. de 2022
It's not something to fix. It's what you want. Analytical differentiation is the fastest option, when it is available.
  2 comentarios
Matt J
Matt J el 21 de Ag. de 2022
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.

Iniciar sesión para comentar.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by