nonlinear constraint problem with genetic algorithm

1视图(最近30天)
我正在尝试使用MATLAB的GA函数来解决以下优化问题:给定MXNUM_COLUMNS矩阵X,选择K列(k
functionloss = minimum_ls(x,X)
%提取回归矩阵,使用x中的整数作为x中的索引
S = X(:,x);
% Calculate associated projection matrix which is optimal in the least
% square error sense
Phi = S*(inv(S'*S))*S';
% Calculate optimal linear reconstruction of X for given arbitrary
% regressor matrix
Xr = Phi*X;
% Get loss associated with this lead selection
loss = norm(X - Xr,'fro');
end
I use the function minimum_ls as the objective function
num_columns = size(X,2)
fork = 1:num_columns
% set options
options = optimoptions('ga','CrossoverFrac',0.8,...
'UseParallel',true,...
'UseVectorized',错误的);
nvars = k;
lb = ones(l,k); ub = num_columns*ones(l,k);
IntCon = 1:k;
nonlcon = @unique_columns;
[~,loss(k)] = ga(@(x)minimum_ls(x,X),...
nvars,[],[],[],[],lb,ub,nonlcon,IntCon,options);
end
Where nonlcon requires that the integers in the variable x are unique,:
function[c,ceq] = unique_columns(x)
c = ~(length(x) == length(unique(x)));
ceq = [];
end
The problem arises as k, the number of columns being selected grows bigger. As an example, X is a 306x193 matrix, and the nonlinear constraint is often not satisfied for k > 30, when I start to receive the following message:
Optimization terminated: average change in the penalty fitness value less than options.FunctionTolerance
but constraints are not satisfied.
What's going on here? For k < 30, the constraint is always satisfied, and it can be satisfied easily with the following lines of code:
x = randi(num_columns,k,1)
while(length(x) ~= length(unique(x)))
x = randi(num_columns,k,1)
end
上述循环可能需要很长时间的大量K,但最终它将找到解决方案。有没有办法强迫MATLAB花更多时间来满足约束?有更好的方法来满足约束吗?

Answers (0)

Community Treasure Hunt

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

开始狩猎!