function [tcost, vcost] = jFitnessFunction(feat,label,X,HO)
if sum(X == 1) == 0
    tcost = 1;  % Set a default value for the training cost if no features are selected
    vcost = 1;  % Set a default value for the validation cost if no features are selected
else
    [tcost, vcost] = jwrapperKNN(feat(:, X == 1),label,HO);
end
end

function [terror, verror] = jwrapperKNN(sFeat,label,HO)
%---// Parameter setting for k-value of KNN //
k = 5; 
xtrain = sFeat(HO.training == 1,:);
ytrain = label(HO.training == 1); 
xvalid = sFeat(HO.test == 1,:); 
yvalid = label(HO.test == 1); 
Model     = fitcknn(xtrain,ytrain,'NumNeighbors',k); 
pred      = predict(Model,xtrain);  % Predictions on the training set
num_train = length(ytrain); 
correct_train = sum(pred == ytrain);  % Count correctly classified instances in the training set
terror = 1 - correct_train / num_train;  % Training error

pred      = predict(Model,xvalid);  % Predictions on the validation set
num_valid = length(yvalid); 
correct_valid = sum(pred == yvalid);  % Count correctly classified instances in the validation set
verror = 1 - correct_valid / num_valid;  % Validation error
end