ddd = datestr(now);
ddd([12 15 18])='-' ;
fnd=[ddd '.txt']; 
diary(fnd)
dbstop if error

clear all;
close all;
disp('Jouet3 1');
N=5;
dagO = zeros(N);
dagO(1,2)=1;
dagO(2,[3 4])=1;
dagO(4,5)=1;
dagO(3,5)=1;
draw_graph(dagO);

node_sizes=2*ones(1,N);
bnetO = mk_bnet(dagO, node_sizes);
bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.3 0.6 0.7 0.4]);
bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.45 0.65 0.55]);
%bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.25 0.60 0.75 0.85 0.75 0.40]);

m = 1000;
for l=1:m, dataO(:,l) = sample_bnet(bnetO); end

DM = 0.1
rand('state',0); randn('state',0);
vide = rand(size(dataO))<(1-DM);
data = bnt_to_mat(dataO);
data = data.*vide;
data = mat_to_bnt(data,0);

nbloopmax = 5;
root = 1;
prior = 0;
discrete = 1:N;
%profile on
tic
[BT_J11, Sbest0, L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
toc
%profile off
%profile report mwstem_Jouet3_1
BT_J11.dag

BICT = get_BIC(BT_J11, data)
BICT2 = get_BICL(BT_J11, L(end) ,m)

% bnet_vide = mk_bnet(zeros(N),node_sizes);
% for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %profile on
% tic
% [BS_J11, orderSEM0, BIC_scoreSEM0, L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% toc
% %profile off
% %profile report sem_Jouet3_1
% BS_J11.dag
% 
% BICS = get_BIC(BS_J11, data)
% BICS2 = get_BICL(BS_J11, L(end) ,m)
% 
% %profile on
% tic
% [BTS_J11, orderMWSTSEM0, BIC_scoreMWSTSEM0, L] = learn_struct_EM(BT_J11, data, nbloopmax*3);
% toc
% %profile off
% %profile report sem_plus_t_Jouet3_1
% BTS_J11.dag
% 
% BICTS = get_BIC(BTS_J11, data)
% BICTS2 = get_BICL(BTS_J11, L(end) ,m)
% save jouet3_1

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clear all;
% close all;
% disp('Jouet3 2');
% N=5;
% dagO = zeros(N);
% dagO(1,2)=1;
% dagO(2,[3 4])=1;
% dagO(4,5)=1;
% dagO(3,5)=1;
% draw_graph(dagO);
% 
% node_sizes=2*ones(1,N);
% bnetO = mk_bnet(dagO, node_sizes);
% bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
% bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.1 0.6 0.9 0.4]);
% bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
% bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.05 0.65 0.95]);
% %bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
% bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.05 0.60 0.75 0.85 0.95 0.40]);
% 
% m = 500;
% for l=1:m, dataO(:,l) = sample_bnet(bnetO); end
% 
% DM = 0.2
% rand('state',0); randn('state',0);
% vide = rand(size(dataO))<(1-DM);
% data = bnt_to_mat(dataO);
% data = data.*vide;
% data = mat_to_bnt(data,0);
% 
% nbloopmax = 5;
% root = 1;
% prior = 0;
% discrete = 1:N;
% profile on
% tic
% [BT_J12, Sbest0, L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% toc
% profile off
% profile report mwstem_Jouet3_2
% BT_J12.dag
% 
% BICT = get_BIC(BT_J12, data)
% BICT2 = get_BICL(BT_J12, L(end) ,m)
% 
% bnet_vide = mk_bnet(zeros(N),node_sizes);
% for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% profile on
% tic
% [BS_J12, orderSEM0, BIC_scoreSEM0, L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% toc
% profile off
% profile report sem_Jouet3_2
% BS_J12.dag
% 
% BICS = get_BIC(BS_J12, data)
% BICS2 = get_BICL(BS_J12, L(end) ,m)
% 
% profile on
% tic
% [BTS_J12, orderMWSTSEM0, BIC_scoreMWSTSEM0, L] = learn_struct_EM(BT_J12, data, nbloopmax*3);
% toc
% profile off
% profile report sem_plus_t_Jouet3_2
% BTS_J12.dag
% 
% BICTS = get_BIC(BTS_J12, data)
% BICTS2 = get_BICL(BTS_J12, L(end) ,m)
% save jouet3_2
% 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clear all;
% close all;
% disp('Jouet3 3');
% N=5;
% dagO = zeros(N);
% dagO(1,2)=1;
% dagO(2,[3 4])=1;
% dagO(4,5)=1;
% dagO(3,5)=1;
% draw_graph(dagO);
% 
% node_sizes=2*ones(1,N);
% bnetO = mk_bnet(dagO, node_sizes);
% bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
% bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.1 0.6 0.9 0.4]);
% bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
% bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.05 0.65 0.95]);
% %bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
% bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.05 0.60 0.75 0.85 0.95 0.40]);
% 
% m = 500;
% for l=1:m, dataO(:,l) = sample_bnet(bnetO); end
% 
% DM = 0.3
% rand('state',0); randn('state',0);
% vide = rand(size(dataO))<(1-DM);
% data = bnt_to_mat(dataO);
% data = data.*vide;
% data = mat_to_bnt(data,0);
% 
% nbloopmax = 5;
% root = 1;
% prior = 0;
% discrete = 1:N;
% profile on
% tic
% [BT_J13, Sbest03, L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% toc
% profile off
% profile report mwstem_Jouet3_3
% BT_J13.dag
% 
% BICT = get_BIC(BT_J13, data)
% BICT2 = get_BICL(BT_J13, L(end) ,m)
% 
% bnet_vide = mk_bnet(zeros(N),node_sizes);
% for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% profile on
% tic
% [BS_J13, orderSEM03, BIC_scoreSEM03, L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% toc
% profile off
% profile report sem_Jouet3_3
% BS_J13.dag
% 
% BICS = get_BIC(BS_J13, data)
% BICS2 = get_BICL(BS_J13, L(end) ,m)
% 
% profile on
% tic
% [BTS_J13, orderMWSTSEM03, BIC_scoreMWSTSEM03, L] = learn_struct_EM(BT_J13, data, nbloopmax*3);
% toc
% profile off
% profile report sem_plus_t_Jouet3_3
% BTS_J13.dag
% 
% BICTS = get_BIC(BTS_J13, data)
% BICTS2 = get_BICL(BTS_J13, L(end) ,m)
% save jouet3_3
% 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Jouet2 1');
% %  N=6;
% %  dagO = zeros(N);
% %  dagO(1,[2,3])=1;
% %  dagO(2,4)=1;
% %  dagO(3,[5 6])=1;
% %  draw_graph(dagO);
% %  
% %  node_sizes=2*ones(1,N);
% %  bnetO = mk_bnet(dagO, node_sizes);
% %  bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
% %  bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.1 0.6 0.9 0.4]);
% %  bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
% %  bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.05 0.65 0.95]);
% %  bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
% %  bnetO.CPD{6} = tabular_CPD(bnetO, 6, [0.02 0.12 0.98 0.88]);
% %  
% %  m = 500;
% %  for l=1:m, dataO(:,l) = sample_bnet(bnetO); end
% %  
% %  DM = 0.1
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(dataO))<(1-DM);
% %  data = bnt_to_mat(dataO);
% %  data = data.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 5;
% %  root = 1;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_J21, Sbest7,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_jouet2_1
% %  BT_J21.dag
% %  
% %  BICT = get_BIC(BT_J21, data)
% %  BICT2 = get_BICL(BT_J21, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_J21, orderSEM7, BIC_scoreSEM7,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4)
% %  toc
% %  profile off
% %  profile report sem_jouet2_1
% %  BS_J21.dag
% %  
% %  BICS = get_BIC(BS_J21, data)
% %  BICS2 = get_BICL(BS_J21, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_J21, orderMWSTSEM7, BIC_scoreMWSTSEM7,L] = learn_struct_EM(BT_J21, data, nbloopmax*3)
% %  toc
% %  profile off
% %  profile report sem_plus_t_jouet2_1
% %  BTS_J21.dag
% %  
% %  BICTS = get_BIC(BTS_J21, data)
% %  BICTS2 = get_BICL(BTS_J21, L(end) ,m)
% %  save jouet2_1
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Jouet2 2');
% %  N=6;
% %  dagO = zeros(N);
% %  dagO(1,[2,3])=1;
% %  dagO(2,4)=1;
% %  dagO(3,[5 6])=1;
% %  draw_graph(dagO);
% %  
% %  node_sizes=2*ones(1,N);
% %  bnetO = mk_bnet(dagO, node_sizes);
% %  bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
% %  bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.1 0.6 0.9 0.4]);
% %  bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
% %  bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.05 0.65 0.95]);
% %  bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
% %  bnetO.CPD{6} = tabular_CPD(bnetO, 6, [0.02 0.12 0.98 0.88]);
% %  
% %  m = 500;
% %  for l=1:m, dataO(:,l) = sample_bnet(bnetO); end
% %  
% %  DM = 0.2
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(dataO))<(1-DM);
% %  data = bnt_to_mat(dataO);
% %  data = data.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 5;
% %  root = 1;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_J22, Sbest7,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_jouet2_2
% %  BT_J22.dag
% %  
% %  BICT = get_BIC(BT_J22, data)
% %  BICT2 = get_BICL(BT_J22, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_J22, orderSEM7, BIC_scoreSEM7,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_jouet2_2
% %  BS_J22.dag
% %  
% %  BICS = get_BIC(BS_J22, data)
% %  BICS2 = get_BICL(BS_J22, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_J22, orderMWSTSEM7, BIC_scoreMWSTSEM7,L] = learn_struct_EM(BT_J22, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_jouet2_2
% %  BTS_J22.dag
% %  
% %  BICTS = get_BIC(BTS_J22, data)
% %  BICTS2 = get_BICL(BTS_J22, L(end) ,m)
% %  save jouet2_2
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Jouet2 3');
% %  N=6;
% %  dagO = zeros(N);
% %  dagO(1,[2,3])=1;
% %  dagO(2,4)=1;
% %  dagO(3,[5 6])=1;
% %  draw_graph(dagO);
% %  
% %  node_sizes=2*ones(1,N);
% %  bnetO = mk_bnet(dagO, node_sizes);
% %  bnetO.CPD{1} = tabular_CPD(bnetO, 1, [0.2 0.8]);
% %  bnetO.CPD{2} = tabular_CPD(bnetO, 2, [0.1 0.6 0.9 0.4]);
% %  bnetO.CPD{3} = tabular_CPD(bnetO, 3, [0.3 0.5 0.7 0.5]);
% %  bnetO.CPD{4} = tabular_CPD(bnetO, 4, [0.35 0.05 0.65 0.95]);
% %  bnetO.CPD{5} = tabular_CPD(bnetO, 5, [0.25 0.15 0.75 0.85]);
% %  bnetO.CPD{6} = tabular_CPD(bnetO, 6, [0.02 0.12 0.98 0.88]);
% %  
% %  m = 500;
% %  for l=1:m, dataO(:,l) = sample_bnet(bnetO); end
% %  
% %  DM = 0.3
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(dataO))<(1-DM);
% %  data = bnt_to_mat(dataO);
% %  data = data.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 5;
% %  root = 1;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_J23, Sbest7,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_jouet2_3
% %  BT_J23.dag
% %  
% %  BICT = get_BIC(BT_J23, data)
% %  BICT2 = get_BICL(BT_J23, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_J23, orderSEM7, BIC_scoreSEM7,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_jouet2_3
% %  BS_J23.dag
% %  
% %  BICS = get_BIC(BS_J23, data)
% %  BICS2 = get_BICL(BS_J23, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_J23, orderMWSTSEM7, BIC_scoreMWSTSEM7,L] = learn_struct_EM(BT_J23, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_jouet2_3
% %  BTS_J23.dag
% %  
% %  BICTS = get_BIC(BTS_J23, data)
% %  BICTS2 = get_BICL(BTS_J23, L(end) ,m)
% %  save jouet2_3
% %  
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Australian 1');
% %  load austr
% %  class_node=15;
% %  rand('state',0);randn('state',0);
% %  melange=1:size(austr,2);
% %  app=austr(:,melange); clear austr
% %  Napp=500; %Napp=round(size(app,2)*0.7);
% %  %Ntest=size(app,2)-Napp;
% %  %test=app(:,Napp+1:size(app,2));
% %  node_sizes = max(app')
% %  
% %  DM = 0.1
% %  BD0 = app(:,1:Napp);
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  %node_type={'tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular'};
% %  nbloopmax = 6;
% %  root = 15;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_A1, Sbest8,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_austr_1
% %  BT_A1.dag
% %  
% %  %BICT = get_BIC(BT_A1, data)
% %  BICT2 = get_BICL(BT_A1, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_A1, orderSEM8, BIC_scoreSEM8,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_austr_1
% %  BS_A1.dag
% %  
% %  %BICS = get_BIC(BS_A1, data)
% %  BICS2 = get_BICL(BS_A1, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_A1, orderMWSTSEM8, BIC_scoreMWSTSEM8,L] = learn_struct_EM(BT_A1, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_austr_1
% %  BTS_A1.dag
% %  
% %  %BICTS = get_BIC(BTS_A1, data)
% %  BICTS2 = get_BICL(BTS_A1, L(end) ,m)
% %  save austr_1
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Australian 2');
% %  load austr
% %  class_node=15;
% %  rand('state',0);randn('state',0);
% %  melange=1:size(austr,2);
% %  app=austr(:,melange); clear austr
% %  Napp=500; %Napp=round(size(app,2)*0.7);
% %  %Ntest=size(app,2)-Napp;
% %  %test=app(:,Napp+1:size(app,2));
% %  node_sizes = max(app')
% %  
% %  DM = 0.2
% %  BD0 = app(:,1:Napp);
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  %node_type={'tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular'};
% %  nbloopmax = 6;
% %  root = 15;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_A2, Sbest8,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_austr_2
% %  BT_A2.dag
% %  
% %  %BICT = get_BIC(BT_A2, data)
% %  BICT2 = get_BICL(BT_A2, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_A2, orderSEM8, BIC_scoreSEM8,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_austr_2
% %  BS_A2.dag
% %  
% %  %BICS = get_BIC(BS_A2, data)
% %  BICS2 = get_BICL(BS_A2, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_A2, orderMWSTSEM8, BIC_scoreMWSTSEM8,L] = learn_struct_EM(BT_A2, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_austr_2
% %  BTS_A2.dag
% %  
% %  %BICTS = get_BIC(BTS_A2, data)
% %  BICTS2 = get_BICL(BTS_A2, L(end) ,m)
% %  save austr_2
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Australian 3');
% %  load austr
% %  class_node=15;
% %  rand('state',0);randn('state',0);
% %  melange=1:size(austr,2);
% %  app=austr(:,melange); clear austr
% %  Napp=500; %Napp=round(size(app,2)*0.7);
% %  %Ntest=size(app,2)-Napp;
% %  %test=app(:,Napp+1:size(app,2));
% %  node_sizes = max(app')
% %  
% %  DM = 0.3
% %  BD0 = app(:,1:Napp);
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  %node_type={'tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular','tabular'};
% %  nbloopmax = 6;
% %  root = 15;
% %  prior = 0;
% %  discrete = 1:N;
% %  profile on
% %  tic
% %  [BT_A3, Sbest8,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax);
% %  toc
% %  profile off
% %  profile report mwstem_austr_3
% %  BT_A3.dag
% %  
% %  %BICT = get_BIC(BT_A3, data)
% %  BICT2 = get_BICL(BT_A3, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_A3, orderSEM8, BIC_scoreSEM8,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_austr_3
% %  BS_A3.dag
% %  
% %  %BICS = get_BIC(BS_A3, data)
% %  BICS2 = get_BICL(BS_A3, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_A3, orderMWSTSEM8, BIC_scoreMWSTSEM8,L] = learn_struct_EM(BT_A3, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_austr_3
% %  BTS_A3.dag
% %  
% %  %BICTS = get_BIC(BTS_A3, data)
% %  BICTS2 = get_BICL(BTS_A3, L(end) ,m)
% %  save austr_3
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Asia 1')
% %  load asia2000;
% %  DM = 0.1
% %  BD0 = asiab;
% %  node_sizes = max(BD0');
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 8;
% %  root = 2;
% %  prior = 0;
% %  discrete = 1:N;
% %  thresh = 1e-3;
% %  profile on
% %  tic
% %  [BT_D1, Sbest1,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax, thresh);
% %  toc
% %  profile off
% %  profile report mwstem_asia_1
% %  BT_D1.dag
% %  
% %  BICT = get_BIC(BT_D1, data)
% %  BICT2 = get_BICL(BT_D1, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_D1, orderSEM1, BIC_scoreSEM1,L] = learn_struct_EM(bnet_vide, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_asia_1
% %  BS_D1.dag
% %  
% %  BICS = get_BIC(BS_D1, data)
% %  BICS2 = get_BICL(BS_D1, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_D1, orderMWSTSEM1, BIC_scoreMWSTSEM1,L] = learn_struct_EM(BT_D1, data, nbloopmax*2);
% %  toc
% %  profile off
% %  profile report sem_plus_t_asia_1
% %  BTS_D1.dag
% %  
% %  BICTS = get_BIC(BTS_D1, data)
% %  BICTS2 = get_BICL(BTS_D1, L(end) ,m)
% %  save asia1
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Asia 2')
% %  load asia2000;
% %  DM = 0.2
% %  BD0 = asiab;
% %  node_sizes = max(BD0');
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 8;
% %  root = 2;
% %  prior = 0;
% %  discrete = 1:N;
% %  thresh = 1e-3;
% %  profile on
% %  tic
% %  [BT_D2, Sbest1,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax, thresh);
% %  toc
% %  profile off
% %  profile report mwstem_asia_2
% %  BT_D2.dag
% %  
% %  BICT = get_BIC(BT_D2, data)
% %  BICT2 = get_BICL(BT_D2, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_D2, orderSEM1, BIC_scoreSEM1,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_asia_2
% %  BS_D2.dag
% %  
% %  BICS = get_BIC(BS_D2, data)
% %  BICS2 = get_BICL(BS_D2, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_D2, orderMWSTSEM1, BIC_scoreMWSTSEM1,L] = learn_struct_EM(BT_D2, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_asia_2
% %  BTS_D2.dag
% %  
% %  BICTS = get_BIC(BTS_D2, data)
% %  BICTS2 = get_BICL(BTS_D2, L(end) ,m)
% %  save asia2
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  disp('Asia 3')
% %  load asia2000;
% %  DM = 0.3
% %  BD0 = asiab;
% %  node_sizes = max(BD0');
% %  [N, m]=size(BD0);
% %  rand('state',0); randn('state',0);
% %  vide = rand(size(BD0))<(1-DM);
% %  data=BD0.*vide;
% %  data = mat_to_bnt(data,0);
% %  
% %  nbloopmax = 8;
% %  root = 2;
% %  prior = 0;
% %  discrete = 1:N;
% %  thresh = 1e-3;
% %  profile on
% %  tic
% %  [BT_D3, Sbest1,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax, thresh);
% %  toc
% %  profile off
% %  profile report mwstem_asia_3
% %  BT_D3.dag
% %  
% %  BICT = get_BIC(BT_D3, data)
% %  BICT2 = get_BICL(BT_D3, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_D3, orderSEM1, BIC_scoreSEM1,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_asia_3
% %  BS_D3.dag
% %  
% %  BICS = get_BIC(BS_D3, data)
% %  BICS2 = get_BICL(BS_D3, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_D3, orderMWSTSEM1, BIC_scoreMWSTSEM1,L] = learn_struct_EM(BT_D3, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_asia_3
% %  BTS_D3.dag
% %  
% %  BICTS = get_BIC(BTS_D3, data)
% %  BICTS2 = get_BICL(BTS_D3, L(end) ,m)
% %  save asia3
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  load thyroid_app.mat
% %  disp('Thyroid');
% %  data = mat_to_bnt(thyroid_app,-9999);
% %  [N, m]=size(data);
% %  prior = 0;
% %  thresh = 1e-3;
% %  discrete = 1:N;
% %  node_sizes = max(thyroid_app');
% %  
% %  root = 1;
% %  nbloopmax = 12;
% %  profile on
% %  tic
% %  [BT_T, Sbest2,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax, thresh);
% %  toc
% %  profile off
% %  profile report mwstem_thyr
% %  BT_T.dag
% %  
% %  %BICT = get_BIC(BT_T, data)
% %  BICT2 = get_BICL(BT_T, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_T, orderSEM2, BIC_scoreSEM2,L] = learn_struct_EM(bnet_vide, data, nbloopmax*5);
% %  toc
% %  profile off
% %  profile report sem_thyr
% %  BS_T.dag
% %  
% %  %BICS = get_BIC(BS_T, data)
% %  BICS2 = get_BICL(BS_T, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_T, orderMWSTSEM2, BIC_scoreMWSTSEM2,L] = learn_struct_EM(BT_T, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_plus_t_thyr
% %  BTS_T.dag
% %  
% %  %BICTS = get_BIC(BTS_T, data)
% %  BICTS2 = get_BICL(BTS_T, L(end) ,m)
% %  save Thyr11
% %  
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %  clear all;
% %  close all;
% %  load heart2
% %  disp('heart');
% %  data = BDMapp;
% %  data{5,59}=[];
% %  prior=0;
% %  root=14;
% %  nbloopmax = 12;
% %  thresh = 1e-3;
% %  m=NbApp;
% %  
% %  profile on
% %  tic
% %  [BT_H, Sbest3,L] = learn_struct_mwst_EM(data, discrete, node_sizes, prior, root, nbloopmax, thresh);
% %  toc
% %  profile off
% %  profile report mwstem_heart
% %  BT_H.dag
% %  
% %  %BICT = get_BIC(BT_H, data)
% %  BICT2 = get_BICL(BT_H, L(end) ,m)
% %  
% %  bnet_vide = mk_bnet(zeros(N),node_sizes);
% %  for i=1:N, bnet_vide.CPD{i} = tabular_CPD(bnet_vide, i); end
% %  profile on
% %  tic
% %  [BS_H, orderSEM3, BIC_scoreSEM3,L] = learn_struct_EM(bnet_vide, data, nbloopmax*4);
% %  toc
% %  profile off
% %  profile report sem_heart
% %  BS_H.dag
% %  
% %  %BICS = get_BIC(BS_H, data)
% %  BICS2 = get_BICL(BS_H, L(end) ,m)
% %  
% %  profile on
% %  tic
% %  [BTS_H, orderMWSTSEM3, BIC_scoreMWSTSEM3,L] = learn_struct_EM(BT_H, data, nbloopmax*3);
% %  toc
% %  profile off
% %  profile report sem_plus_t_heart
% %  BTS_H.dag
% %  
% %  %BICTS = get_BIC(BTS_H, data)
% %  BICTS2 = get_BICL(BTS_H, L(end) ,m)
% %  save heart11
% %  
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

diary off
