matlaboptimizationconstraintsparticle-swarmcost-based-optimizer

Huge nb of parameters, constraint and objective function : how to deal with this in Matlab?


I would like find the Alpha coefficients which minimize this objective function:

fun_Obj = @(Alpha) norm(A- sum(Alpha.*B(:,:),2),2)

With :

A= vector 1d (69X1)

B= matrice 2d (69X1000)

Alpha_i a vector (1X1000) of unknown parameters, where 0 < Alpha < 1 and sum(Alpha) = 1

What is the best optimization method to deal with such a number of parameters (I can try to reduce it will remain still a lot)? How can I introduce the second constraint i.e sum(Alpha_i) = 1 during the optimization?

Thanks a lot for your precious help.

Best,

Benjamin


Solution

  • You can use the constrained optimisation function fmincon:

    % sample data
    nvars = 1000;
    A = rand(69,1);
    B = rand(69,nvars);
    
    % Objective function
    fun_Obj = @(Alpha,A,B) norm(A- sum(Alpha.*B(:,:),2),2);
    
    % Nonlinear constraint function. The first linear equality is set to -1 to make it alway true. 
    %    The second induces the constraint that sum(Alpha) == 1
    confuneq = @(Alpha)deal(-1, sum(Alpha)-1);
    
    % starting values
    x0 = ones(1,nvars)/nvars;
    
    % lower and upper bounds
    lb = zeros(1,nvars);
    ub = ones(1,nvars);
    
    % Finally apply constrained minimisation
    Alpha = fmincon(@(x)fun_Obj(x,A,B),x0,[],[],[],[],lb,ub,@(x)confuneq(x));
    

    It only takes a few seconds on my laptop with the default number of iterations, but you should consider increasing that number drastically to get a better result. Also, the default algorithm might not be the right choice in this scenario, 'sqp' is probably better. See documentation.

    You can do those things with:

    options = optimoptions(@fmincon,'Algorithm','sqp','MaxFunctionEvaluations',1e6);
    Alpha = fmincon(@(x)fun_Obj(x,A,B),x0,[],[],[],[],lb,ub,@(x)confuneq(x),options);