view phase2/treeLinkFeatures.m @ 27:f9fceb869865

update to range of depthThresh permitted
author DaveM
date Sun, 12 Mar 2017 19:56:52 +0000
parents 2a77dd12582f
children 7710e44f432a
line wrap: on
line source
function [linkList, featureList]= treeLinkFeatures(data, depthThresh, featureNames)
%% linkList = treeLinkFeatures(data)
% given a dataset, a hierarchical cluster of the data is produced, and then
% the data is traversed, such that, for each split in the data, a set of
% features are produced, which are the ranked features that can be used to
% separate the given dataset at that point.


if(nargin < 3)
    featureNames = 1:size(data,2);
end
if(nargin < 2)
    depthThresh = 999;
end

if (len(depthThresh) == 1)
    depthThresh = 1:depthThresh;
end
    
linkList = aglomCluster(data);
linkList = depthCheck(linkList);
listSize = size(data,1);

% linkList(:,4) = 0;
featureList = cell(listSize-1,3);
currentRow = [2*listSize-1];

%%
while (~isempty(currentRow))
    if(currentRow(1) > listSize)
        row = currentRow(1) - listSize;
%         rD = linkList(row,4);
        if any(linkList(row,4)==depthThresh)
            classList = traceLinkageToBinary(linkList, row);
            featureList{row,1} = rfFeatureSelection(data(classList>0,:), classList(classList>0));
            featureList{row,2} = linkList(row,4);
            featureList{row,3} = fitctree(data(classList>0,featureList{row,1}),classList(classList>0),'PredictorNames',featureNames(featureList{row,1}));
        end
        currentRow = [currentRow; linkList(row,1); linkList(row,2)];
    end
    currentRow = currentRow(2:end);
end

end