function c_tree = BR_build_DT
%

load A8_data

P = [Xb1;Xb2;Xc1;Xc2;Xt1;Xt2];
num_Xb1 = length(Xb1(:,1));
num_Xb2 = length(Xb2(:,1));
num_Xc1 = length(Xc1(:,1));
num_Xc2 = length(Xc2(:,1));
num_Xt1 = length(Xt1(:,1));
num_Xt2 = length(Xt2(:,1));
num_Xb3 = length(Xb3(:,1));
num_Xc3 = length(Xc3(:,1));
num_Xt3 = length(Xt3(:,1));
T = [ones(num_Xb1+num_Xb2,1);2*ones(num_Xc1+num_Xc2,1);...
    3*ones(num_Xt1+num_Xt2,1)];
PT = [Xb3;Xc3;Xt3];
TT = [ones(num_Xb3,1);2*ones(num_Xc3,1);3*ones(num_Xt3,1)];

c_tree = fitctree(P,T);

%view(c_tree);
%predict(c_tree,PT(1,:));

paths = BR_DT_paths(P);
y = zeros(length(P(:,1)),1);
for s = 1:length(P(:,1))
    y(s) = predict(c_tree,P(s,:));
end
cl = zeros(35,2);
for s = 1:length(P(:,1))
    p = paths(s,1);
    cl(p,1) = cl(p,1) + 1;
    if y(s)==T(s)
        cl(p,2) = cl(p,2) + 1;
    end
end

probs = cl(:,2)./cl(:,1);
KB = BR_DT_KB_gen;
for p = 1:35
    KB(p).prob = probs(p);
end

tch = 0;
