MATLAB Answers

Is fmincon appropriate for optimizing vector-valued optimization variables (scalar obj. function)?

23 views (last 30 days)
I'm currently attempting to solve the following optimization problem:
subject to:
Where I (eye) is the identity matrix, q_1, q_2 are the optimization variables two-dimensional or greater (dimensionality isn't important, just that they are not scalars). C_1 and C_2 are data matrices. I'm wondering if fmincon is appropriate to use for finding the optimal q1,q2, given they are vector-valued. Below is the code I have currently, in case it is helpful.
%% simulated neural activity
numClusters = 163;
prepActivity = randn(200, 163); % (time, number of neurons)
moveActivity = randn(400, 163); % (time, number of neurons)
Cprep = (1/(size(prepActivity,1)-1)) * (prepActivity' * prepActivity); % cov matrix
Cmove = (1/(size(moveActivity,1)-1)) * (moveActivity' * moveActivity);
% get singular values of Cprep and Cmove in descending order
prepSigmas = svd(Cprep);
moveSigmas = svd(Cmove);
%% setup optimization prob
% dimensionality of Qprep and Qmove
d_prep = 2;
d_move = 2;
% terms needed in cost function
prepSigma = sum(prepSigmas(1:d_prep));
moveSigma = sum(moveSigmas(1:d_move));
% define optimization vars
Qprep = optimvar('Qprep', numClusters, d_prep);
Qmove = optimvar('Qmove', numClusters, d_move);
% cost / objective function
cost = @(Qprep, Qmove) 0.5 * ( trace(Qprep'*(Cprep*Qprep))/prepSigma + ...
trace(Qmove'*(Cmove*Qmove))/moveSigma );
cost = fcn2optimexpr(cost, Qprep, Qmove); % needed to convert cost function to appropriate type
prob = optimproblem('Objective',cost, 'ObjectiveSense', 'maximize'); % maximize
% constraints
cons1 = Qprep' * Qmove == zeros(d_prep,d_move); % orthogonality between subspaces
cons2 = Qprep' * Qprep == eye(d_prep); % subspaces should be orthonormal
cons3 = Qmove' * Qmove == eye(d_move);
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
prob.Constraints.cons3 = cons3;
% show the optimization problem
%% solve
x0.Qprep = ones(numClusters, d_prep) * 5; % initial conditions
x0.Qmove = ones(numClusters, d_move) * 5;
options = optimoptions(@fmincon,'MaxFunctionEvaluations',200000); % increase iterations
[sol,fval,exitflag,output] = solve(prob,x0,'Options', options); % solve


Walter Roberson
Walter Roberson on 12 Jan 2021
It is not clear to me that your function is continuous in the variables. Maybe it is, but that is not obvious to me. If it is not continuous with continuous first and second derivatives, then you cannot use fmincon.
Munib Hasnain
Munib Hasnain on 12 Jan 2021
Thanks, Walter. That information is helpful. I haven't checked myself if the function is continuous, but I will do that.
Bruno Luong
Bruno Luong on 12 Jan 2021
All the operations used here are multiplications and additions. Thus there is no reason to worry about continuity, in fact at any derivative order.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 12 Jan 2021
Yes fmincon supposes to handle optimization problems on objective function that depends on vector of real values. There is no reason whatsoever to concern about this aspect.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!