// file: dtn_compute_0.cc
//

// isip include files
//
#include "dt_node.h"
#include "dt_node_constants.h"

// method:  compute_likelihood_cc
//       L= -0,5* num_feat_a*(1+log2*pi)+log(det(covar))*sum_occupancy
//                                                        s
//
// arguments:
//    State** states: (input) all states associated with this node
//    float_4* occupy: (input) state occupancies
//    int_4 num_feat: (input) the number of features
//    int_4 num_mix: (input) the number of mixtures
//
// return: a float_4 likelihood
//
float_4 Dt_node::compute_likelihood_cc(State** states_a, float_4* occupy_a,
				       int_4 num_feat_a, int_4 num_mix_a) {

  likelihood_d = 0.0;
  float_4 det_covar = 0.0;
  float_4 sum_occupy = 0;
  float_4 scale = 0.0;
  
  // compute the sum of occupancy
  //
  for (int_4 i= 0; i<num_states_d; i++) {
    sum_occupy += occupy_a[state_index_d[i]];
  }

  // make sure the division is valid
  //
  if(sum_occupy != 0) {
    
    // compute the covariance of all the states
    //
    float_4* covar = new float_4[num_feat_a]; 
    
    compute_covar_cc(covar, det_covar, scale, states_a, occupy_a, num_feat_a,
		     num_mix_a);
  
    // compute the likelihood
    //
    likelihood_d = -0.5*(num_feat_a*(1+log(ISIP_TWOPI))+det_covar)*(float_4)sum_occupy;
  
    // free memory
    //
    delete [] covar;
    
    return likelihood_d;
  }
  
  // else return a very small value
  //
  else {
    return MIN_LIKELIHOOD;
  }
}
