%Andrew Howard
%
%DST_inference iterates recursively the structured mean field equations for a DST 
%
%   function states = DST_inference(D) iterates the smf equations for a DST rooted at D
%
%   function states = DST_inference(D, varparam) iterates the smf equations for a DST rooted at D with varparam being the variational parameters for the root D
%
%   D = a struct which is the root of a DST
%   varparams = the variational parameters for the root D (optional)

function [bound] = DST_inference4(cur,n,pred)

global DST;

global TINY;

bound = 0;

%%if HMM
if (DST(cur).type == 2)

    bound = bound + inferHMM2(cur,n);
  
%%else if LDS
elseif (DST(cur).type == 3)

    bound = bound + inferLDS2(cur,n,pred);
    
%%else internal chain
elseif(DST(cur).type == 1)
    
    for m=1:length(DST(cur).child)

        bound = bound + DST_inference4(DST(cur).child(m),n,pred);

    end
        
    bound = bound + inferChain3(cur,n,pred);
    
end
