Optimization of Artificial Immune system using Genetic algorithm

4 Ansichten (letzte 30 Tage)
BR
BR am 15 Okt. 2018
Bearbeitet: BR am 18 Okt. 2018
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

Akzeptierte Antwort

Stephan
Stephan am 15 Okt. 2018
Bearbeitet: Stephan am 15 Okt. 2018
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 Kommentare
Stephan
Stephan am 18 Okt. 2018
So i may conclude we are finished here?
BR
BR am 18 Okt. 2018
Bearbeitet: BR am 18 Okt. 2018
Yeah mate, Think so. Thanks a tonne.
Best Regards
Baqar

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by