Clear Filters
Clear Filters

I'm trying to create a classification system using artificial immune systems but I don't know how to create the loop properly.

1 view (last 30 days)
So, I need to create a set of random detectors and then compare them with the real cases using "pdist2". When "pdist2" is under a certain value (0.5), the case is atributed as being part of the respective detector. However, this detector is only valid if it reaches a minimum number of "detections" ((size(percentage,1)/size(X,1))*3).
X=zeros(50,16);
for k=1:size(X,2)
for j=1:size(X,1)
X(j,k)=percentage_min(1,k)+rand(1,1)*(percentage_max(1,k)-percentage_min(1,k));
end
end
D=pdist2(X,percentage);
T=zeros(size(D,1),1);
U=zeros(size(X));
for k=1:size(D,1)
for j=1:size(D,2)
if D(k,j)<0.5
T(k)=T(k)+1;
end
if T(k)>(size(percentage,1)/size(X,1))*3
U(k,:)=X(k,:);
end
end
end
This part of the code is working properly. However, now I need to delete the already atributed cases, create another set of detectors (overwriting X) and use "pdist2" again, until almost all cases are atributed (lets say, per example, while size(percentage,1)>500). When I say to delete a case, I mean to delete a row of "percentage". However, when I do this inside the loop, it never stops. And I also already tried to make the loop backwards but I have the same problem.
while size(percentage,1)>500
for k=1:size(D,1)
for j=1:size(D,2)
if D(k,j)<0.5
T(k)=T(k)+1;
percentage(k,:)=[];
end
if T(k)>(size(percentage,1)/size(X,1))*3
U(k,:)=X(k,:);
end
for m=1:size(X,2)
for n=1:size(X,1)
X(n,m)=percentage_min(1,m)+rand(1,1)*(percentage_max(1,m)-percentage_min(1,m));
end
end
D=pdist2(X,percentage);
T=zeros(size(D,1),1);
end
end
end
This part of the code is not working, but I hope you can understand what I want. Can somebody please help me? And I have 2 other minor problems: when a case is atributed to a detector, it shouldn't be atributed to another one (T should be incremented only once by each case, so total sum should be size(percentage,1)). And when a detector is saved on U, that position shouldn't be overwritten by a new detector.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!