function bnet2 = change_algo(bnet, algo, clusters)
% CHANGE_ALGO Change the inference algorithm of a Bayes Net.
% bnet2 = change_algo(bnet, algo, clusters)
%
% clusters is an optional argument for DBNs with algo==bk.

if strcmp(algo, 'hmm')
  error('can''t convert to hmm using change_algo because num. nodes is different');
end

if ~bnet.is_dbn
  bnet2 = mk_bnet(bnet.adj_mat, bnet.node_sizes, bnet.discrete_nodes, algo, bnet.equiv_class, ...
      bnet.observed_nodes, bnet.uedges, bnet.cliques);
else
  if ~exist('clusters')
    if strcmp(bnet.algo, 'bk')
      clusters = bnet.dbn.cluster; 
    else
      clusters = 'exact';
    end
  end
  bnet2 =  mk_dbn(bnet.intra, bnet.inter, bnet.node_sizes_slice, bnet.discrete_slice, ...
      bnet.equiv_class, bnet.observed_slice, algo, clusters, bnet.intra1);
end

for i=1:length(bnet.adj_mat)
  bnet2.bnodes{i} = bnet.bnodes{i};
end

bnet2 = compile_params(bnet2);
