function [ bestx,resultingSubsets ] = findbestx( features,labels )
% Hassan Nahas
%This function takes a set of features and their labels, determines the
%most discriminating x (relative position in teh ring) and outputs the
%partioned space of features according to this choice of x.
    scores = getFeatureScores(features,labels);
    bestx = calculateEntropyForEachClass(scores,labels);
    resultingSubsets = cell(3,3);
    
    Pb = features(:,features(bestx,:) == 1);
    Pb_labels = labels(features(bestx,:) == 1);
    H_Pb = EntropyOfSet(sum(Pb_labels == 1),sum(Pb_labels == 0));
    
    resultingSubsets{3,1} = H_Pb;
    resultingSubsets{3,2} = Pb;
    resultingSubsets{3,3} = Pb_labels;

    
    Ps = features(:,features(bestx,:) == 0);
    Ps_labels = labels(features(bestx,:) == 0);
    H_Ps = EntropyOfSet(sum(Ps_labels == 1),sum(Ps_labels == 0));

    resultingSubsets{2,1} = H_Ps;
    resultingSubsets{2,2} = Ps;
    resultingSubsets{2,3} = Ps_labels;
    
    
    Pd = features(:,features(bestx,:) == -1);
    Pd_labels = labels(features(bestx,:) == -1);
    H_Pd = EntropyOfSet(sum(Pd_labels == 1),sum(Pd_labels == 0));
    
    resultingSubsets{1,1} = H_Pd;
    resultingSubsets{1,2} = Pd;
    resultingSubsets{1,3} = Pd_labels;


end

