function [cleanedSelectedInstances] = gacPruner(tree, startPoint)

% this will be the GAC2 tree's code
[allSubtrees] = getSubtreesForGAC2(tree, startPoint);

% find variance of all subtrees
variancesOfAllSubtrees = zeros(size(allSubtrees,1),1);
for i = 1:size(allSubtrees,1)
   variancesOfAllSubtrees(i) = var(allSubtrees(i).features(:,size(allSubtrees(i).features,2))); 
end

% convert variance to log(var)/max(log(var))
convertedVar = log(variancesOfAllSubtrees);
tempMax = max(convertedVar);
convertedVar = convertedVar/tempMax;

% now select instances from GAC tree 1 at random
selectedInstances = []; % keeps selected instances from GAC tree1
tempCounter = 0;    % counts how many times selectedInstances were added
for i = 1:size(allSubtrees,1)
    if convertedVar(i) <= (0.1 * tempMax)
        selectedInstances = [selectedInstances;allSubtrees(i).features];
        tempCounter = tempCounter + 1;
    end
end

% since there are multiple nodes from multiple levels that contribute to
% our tree, we need to remove the duplicates from selected instances if
% there are any
% delete the copies of it from the messed up values
cleanedSelectedInstances = [];  % keeps the unique instances within selectedInstances
while size(selectedInstances,1) > 0
    tempInstance = selectedInstances(1,:);
    head = 1;                           % keeps track of the head as deletion
    tail = size(selectedInstances,1);    % keeps track of the tail as deletion
    while 1==1
        if sum(selectedInstances(head,:) - tempInstance) == 0
            selectedInstances(head,:) = [];
            tail = tail -1;
        else
            head = head + 1;
        end
        
        % when we processed them all
        if head > tail
            break;
        end
    end
    cleanedSelectedInstances = [cleanedSelectedInstances;tempInstance];
end