Optimization of Artificial Immune system using Genetic algorithm

조회 수: 4 (최근 30일)
BR
BR 2018년 10월 15일
편집: BR 2018년 10월 18일
The defined problem for DCA (AIS) gives an output function,
providing three different ouputs for a matrix of input weights.
The condition for the output is
if C(csm)>thr && C(mDC)>C(smDC)
C=1;
else
C=0;
end
Where Cp = data(target,1)
Cs = data(target,2)
Cd= data(target,3) for target to be a logical vector for labels
Obviously, I have a target data for which this condition should meet, only if I optimize the weights properly.
So, in order to do this I created the following code for GA fitness function
function [s,c]=DCA_weights(W, data, targets)
c(1)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
c(2)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
c(3)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
s=c(2)./c(3); % minimizing the ratio of C(smDC)/(CmDC)
and constraint function as (After solving the C(csm) < thr)
function [c, ceq] = DCA_constraint_GA(W, data, target)
c = (9.6 - data(target,1))*W(1) + (9.6 - data(target,2))*W(2) + (9.6 - data(target,3))*W(3);
ceq=[];
I have defined both upper and lower bounds for weights as [-6 -6 -6] and upper bounds as [6 6 6]
and the final code is
ObjectiveFunction = @DCA_weights;
nvars = 3; % Number of variables
LB = [-6 -6 -6]; % Lower bound
UB = [6 6 6]; % Upper bound
ConstraintFunction = @DCA_constraint_GA;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction);
But I always get the following response,
'Not enough input arguments'
I assume there may be one small error that I am missing, Please help.
Thanks in advance

채택된 답변

Stephan
Stephan 2018년 10월 15일
편집: Stephan 2018년 10월 15일
Hi,
solvers like ga only pass only one argument to their objective functions - in your case W. If your function needs additional arguments you have to pass them in another way. See passing extra parameters and look which is the best method for you. I prefer nested functions - but there are also other methods. The use of global variables is not recommended.
If you fix this, it should work.
General example:
% call outer function to start the calculation
outer_fcn
% define outer function containing the additional variables / values:
function outer_fcn
data = ...;
targets = ...;
% call ga inside the outer function:
ObjectiveFunction = @DCA_weights;
nvars = 3; % Number of variables
LB = [-6 -6 -6]; % Lower bound
UB = [6 6 6]; % Upper bound
ConstraintFunction = @DCA_constraint_GA;
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,ConstraintFunction);
% nonlinear constraints function (1. inner function)
function [c, ceq] = DCA_constraint_GA(W, data, target)
c = (9.6 - data(target,1))*W(1) + (9.6 - data(target,2))*W(2) + (9.6 - data(target,3))*W(3);
ceq=[];
end
% objective function (2. inner function)
function [s,c]=DCA_weights(W, data, targets)
c(1)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
c(2)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
c(3)=0.5*(W(1) * data(targets,1) + W(3) * data(targets,3) + W(2) * data(targets,2))/(W(1) + W(2) + W(3));
s=c(2)./c(3); % minimizing the ratio of C(smDC)/(CmDC)
end
% end of outer function
end
Best regards
Stephan
  댓글 수: 28
Stephan
Stephan 2018년 10월 18일
So i may conclude we are finished here?
BR
BR 2018년 10월 18일
편집: BR 2018년 10월 18일
Yeah mate, Think so. Thanks a tonne.
Best Regards
Baqar

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by