DaveM@25: function [linkList, featureList]= treeLinkFeatures(data, depthThresh, featureNames) DaveM@28: %% [linkList, featureList]= treeLinkFeatures(data, depthThresh, featureNames) DaveM@10: % given a dataset, a hierarchical cluster of the data is produced, and then DaveM@10: % the data is traversed, such that, for each split in the data, a set of DaveM@10: % features are produced, which are the ranked features that can be used to DaveM@10: % separate the given dataset at that point. DaveM@28: % data is the nxm matrix of content, n is the number of samples and m is DaveM@28: % the number of features. DaveM@28: % depthThresh is a list of the range of tree depths to traverse from the DaveM@28: % aglomerative clustering tree. A single value of depthThresh, will assume DaveM@28: % 1:depthThresh. For analysis of a single layer of the tree, pass a list of DaveM@28: % two values, both of which are the layer to be analysed. DaveM@28: % feature names is the list of features, so that grown trees have suitable DaveM@28: % names. No feature names will result in the feature number being returned. DaveM@28: % featureList corresponds to the rows in linkList, with the form column 1 DaveM@28: % is the 5 most relevant features, column 2 is the depth and column 3 is a DaveM@28: % decision classification tree for the decision - perhaps this should be in DaveM@28: % the form of a struct instead? DaveM@28: DaveM@10: DaveM@9: DaveM@25: if(nargin < 3) DaveM@25: featureNames = 1:size(data,2); DaveM@25: end DaveM@16: if(nargin < 2) DaveM@19: depthThresh = 999; DaveM@16: end DaveM@27: DaveM@31: if (length(depthThresh) == 1) DaveM@27: depthThresh = 1:depthThresh; DaveM@27: end DaveM@27: DaveM@9: linkList = aglomCluster(data); DaveM@16: linkList = depthCheck(linkList); DaveM@10: listSize = size(data,1); DaveM@9: DaveM@10: % linkList(:,4) = 0; DaveM@24: featureList = cell(listSize-1,3); DaveM@10: currentRow = [2*listSize-1]; DaveM@9: DaveM@12: %% DaveM@15: while (~isempty(currentRow)) DaveM@16: if(currentRow(1) > listSize) DaveM@30: row = currentRow(1) - listSize DaveM@17: % rD = linkList(row,4); DaveM@27: if any(linkList(row,4)==depthThresh) DaveM@16: classList = traceLinkageToBinary(linkList, row); DaveM@23: featureList{row,1} = rfFeatureSelection(data(classList>0,:), classList(classList>0)); DaveM@17: featureList{row,2} = linkList(row,4); DaveM@24: featureList{row,3} = fitctree(data(classList>0,featureList{row,1}),classList(classList>0),'PredictorNames',featureNames(featureList{row,1})); DaveM@16: end DaveM@17: currentRow = [currentRow; linkList(row,1); linkList(row,2)]; DaveM@10: end DaveM@17: currentRow = currentRow(2:end); DaveM@29: save('partialResults.mat'); DaveM@9: end DaveM@9: DaveM@9: end