function filename = viz_tree( tree )
%UNTITLED Summary of this function goes here
% Visualiz the tree using graphviz
global index;
index = 0;
fid = fopen('Visualization.dot','w+');
fprintf(fid, 'digraph G {\n');
fprintf(fid, 'fontname = "Bitstream Vera Sans"\n');
fprintf(fid, 'fontsize = 8\n');
fprintf(fid, 'node[fontname = "Bitstream Vera Sans"\n');
fprintf(fid, ' fontsize = 8\n');
fprintf(fid, ' shape = "record"]\n');
fprintf(fid, 'edge [fontname = "Bitstream Vera Sans"\n');
fprintf(fid, ' fontsize = 8]\n');
visual( tree ,fid);
fprintf(fid,'}');
fclose(fid);
filename = 'Visualization.dot';
function nodename = visual( tree ,fid)
global index;
index = index + 1;
nodename = ['node' num2str(index)];
if isnumeric(tree.Raction)
%Reached an end node
fprintf(fid, '%s[label ="{class = %d|+Error Rate : %5f}"]\n',nodename, tree.Raction(1),tree.Resub);
else
fprintf(fid, '%s[label ="{Left : %s|+Right : %s|+Alpha : %6f}"]\n',nodename, tree.Laction, tree.Raction, tree.Alpha);
nl = visual(tree.left, fid);
nr = visual(tree.right, fid);
fprintf(fid, '%s -> %s\n',nodename, nl);
fprintf(fid, '%s -> %s\n',nodename, nr);
%fprintf(fid, 'nodename[label =%s|+Leafcnt : %d|+Alpha : %6f]\n', tree.Raction, tree.Leafcnt, tree.Alpha);
%Rl = visual(tree.left, fid);
%RR = visual(tree.right, fid);
end