Is fmincon appropriate for optimizing vector-valued optimization variables (scalar obj. function)?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Munib Hasnain
el 12 de En. de 2021
Comentada: Munib Hasnain
el 12 de En. de 2021
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
show(prob)
%% 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
3 comentarios
Bruno Luong
el 12 de En. de 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.
Respuesta aceptada
Bruno Luong
el 12 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!