changeset 16:4a8ec6c461a0

adding depth checking for recursive tree - feature search - though has a bug where it sometimes get stuck in an infinite loop and I dont know why
author DaveM
date Thu, 16 Feb 2017 10:07:42 +0000
parents 0718e03cb36d
children c674bf769d82
files phase2/depthCheck.m phase2/runme.m phase2/treeLinkFeatures.m
diffstat 3 files changed, 72 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phase2/depthCheck.m	Thu Feb 16 10:07:42 2017 +0000
@@ -0,0 +1,48 @@
+function linkList = depthCheck(linkList)
+
+listSize = size(linkList,1)+1;
+
+linkList = cat(2,linkList, zeros(size(linkList,1),1));
+currentRow = size(linkList,1);
+r = [0;0];
+% depth = 1;
+
+linkList(currentRow,end) = 1;
+% depth = depth + 1;
+%%
+while (~isempty(currentRow))
+    row = currentRow(1);
+    for i = 1:2
+        r(i) = linkList(row,i);
+        if(r(i) > listSize)
+            r(i) = linkList(row,i) - listSize;
+            linkList(r(i),end) = linkList(currentRow(1),end)+1;
+            currentRow = [currentRow; r(i)];
+        end
+    end
+    currentRow = currentRow(2:end);
+end
+end
+
+
+
+% linkList = aglomCluster(data);
+% listSize = size(data,1);
+% 
+% % linkList(:,4) = 0;
+% featureList = cell(listSize-1,1);
+% currentRow = [2*listSize-1];
+% 
+% %%
+% while (~isempty(currentRow))
+%     if(currentRow(1) > listSize) 
+%         row = currentRow(1) - listSize
+%         classList = traceLinkageToBinary(linkList, row);
+%         featureList{row} = rfFeatureSelection(data(classList>0,:), classList(classList>0));
+%         currentRow = [currentRow(2:end); linkList(row,1); linkList(row,2)];
+%     else
+%         currentRow = currentRow(2:end);
+%     end
+% end
+% 
+% end
\ No newline at end of file
--- a/phase2/runme.m	Wed Feb 15 11:07:32 2017 +0000
+++ b/phase2/runme.m	Thu Feb 16 10:07:42 2017 +0000
@@ -1,5 +1,13 @@
 
-load('adobeDataNorm.mat')
-[linkList, featureList]= treeLinkFeatures(AdobeNormalised);
-save('adobeResults.mat','linkList','featureList');
-exit
\ No newline at end of file
+%%
+load('testData.mat');
+[linkList, featureList]= treeLinkFeatures(data,5);
+save('testResults.mat','linkList','featureList');
+
+%%
+% load('adobeDataNorm.mat')
+% [linkList, featureList]= treeLinkFeatures(AdobeNormalised,5);
+% save('adobeResults.mat','linkList','featureList');
+% exit
+
+%%
--- a/phase2/treeLinkFeatures.m	Wed Feb 15 11:07:32 2017 +0000
+++ b/phase2/treeLinkFeatures.m	Thu Feb 16 10:07:42 2017 +0000
@@ -1,4 +1,4 @@
-function [linkList, featureList]= treeLinkFeatures(data)
+function [linkList, featureList]= treeLinkFeatures(data, depthThresh)
 %% 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
@@ -6,7 +6,12 @@
 % separate the given dataset at that point.
 
 
+
+if(nargin < 2)
+    depthThresh = 9999999;
+end
 linkList = aglomCluster(data);
+linkList = depthCheck(linkList);
 listSize = size(data,1);
 
 % linkList(:,4) = 0;
@@ -15,11 +20,13 @@
 
 %%
 while (~isempty(currentRow))
-    if(currentRow(1) > listSize) 
+    if(currentRow(1) > listSize)
         row = currentRow(1) - listSize
-        classList = traceLinkageToBinary(linkList, row);
-        featureList{row} = rfFeatureSelection(data(classList>0,:), classList(classList>0));
-        currentRow = [currentRow(2:end); linkList(row,1); linkList(row,2)];
+        if(linkList(row,4) < depthThresh)
+            classList = traceLinkageToBinary(linkList, row);
+            featureList{row} = rfFeatureSelection(data(classList>0,:), classList(classList>0));
+            currentRow = [currentRow(2:end); linkList(row,1); linkList(row,2)];
+        end
     else
         currentRow = currentRow(2:end);
     end