As said in the title, I have a recursive function and I am trying to build a tree data structure out of it to save my results. Every node consists in just one single number. The problem is that when I input the tree to the next call of the function, it seems that only the value of the tree is passed along, not the actual tree. Does anyone know how to pass a reference to the tree instead?
Initial Call:
tree = struct('left', 'empty','right', 'empty','feature','empty');
decisiontree_train(AttributeSet, LabelSet, 50, tree, 'node');
Recursive Function:
function decisiontree_train( data, labels, before_split_purity_percentage, tree, branch )
% a1 is 0, a2 is 1
[ a1_split_data, a2_split_data, a1_split_labels, a2_split_labels, ...
split_feature ] = decisiontree_split( data, labels );
new_tree = struct('left', 'empty','right', 'empty','feature','empty');
if strcmp(branch, 'left')
tree.left = new_tree;
new_tree.feature = split_feature;
elseif strcmp(branch, 'right')
tree.right = new_tree;
new_tree.feature = split_feature;
elseif strcmp(branch, 'node')
tree.feature = split_feature;
new_tree = tree;
end
[ after_split_purity_percentage ] = decisiontree_classcount( a1_split_labels );
if after_split_purity_percentage < 100 && ...
after_split_purity_percentage > before_split_purity_percentage
decisiontree_train(a1_split_data, a1_split_labels, ...
after_split_purity_percentage, new_tree, 'left');
end
[ after_split_purity_percentage ] = decisiontree_classcount( a2_split_labels );
if after_split_purity_percentage < 100 && ...
after_split_purity_percentage > before_split_purity_percentage
decisiontree_train(a2_split_data, a2_split_labels, ...
after_split_purity_percentage, new_tree, 'right');
end
% add variable to workspace
% assignin('base', 'a1_split_data', a1_split_data)
end