With help from Arthur B. I finally understood the concept. Here is my implementation of it. Although I used the Plus l Take away r algorithm (Sequential Forwards Backward Search) Ill post that as it is basically the same once the Backward Search is removed. The below implementation is in matlab but very simple to understand:
S=zeros(Size,1); %Initial the binary array feature list with all zeros implying no feature selected
k=0;
while k<n %Begin SFS. n is the number of features that need to be extracted
t=k+l; %l is the number of features to be added in each iteration
while k<t
R=zeros(Size,1); %Size is the total number of features
for i=1:Size
if S(i)==0 %If the feature has not been selected. S is a binary array which puts a one against each feature that is selected
S_copy=S;
S_copy(i)=1;
R=OperateBhattacharrya(Matrices,S_copy,i,e,R); %The result of each iteration is stored in R
end
end
k=k+1; %increment k
[~,N]=max(R); %take the index of the maximum element in R as the best feature to be selected
S(N)=1; % put the index of selected feature as 1
end
t=k-r; %r is the number of features to be removed after selecting l features. l>r
while k>t %start Sequential Backward Search
R=zeros(Size,1);
for i=1:Size
if S(i)==1
S_copy=S;
S_copy(i)=0;
R=OperateBhattacharrya(Matrices,S_copy,i,1,R);
end
end
k=k-1;
[~,N]=max(R);
S(N)=0;
end
fprintf('Iteration :%d--%d\n',k,t);
end
I hope this helps anyone who has a similar problem.