// file: dt_logl_1.cc
//

// isip include files
//
#include "decision_tree.h"
#include "decision_tree_constants.h"

// method: compute_lk_dec_cc
//
// arguments:
//    Dt_node* dt_node1: (input) the node supposed to be merged
//    Dt_node* dt_node2: (input) the node supposed to be merged
//    State** states: (input)  all the states
//    float_4* occupancy: (input) the states occupancy
//    int_4 num_feat: (input) number of features
//    int_4 num_mix: (input) number of mixtures
// 
// return: a float_4 likelihood decrease value
//
// this method computes the likelihood decrease if merging the two nodes
//
float_4 Decision_tree::compute_lk_dec_cc(Dt_node* dt_node1_a,
					 Dt_node* dt_node2_a, State** states_a,
					 float_4* occupancy_a,
					 int_4 num_feat_a, int_4 num_mix_a) {
  
  // the likelihood decrease when merging
  //
  float_4 merge_lk_dec = 0.0;
  
  // compute the likelihood of the two nodes
  //
  float_4 lk_1 = dt_node1_a->get_likelihood_cc();
  float_4 lk_2 = dt_node2_a->get_likelihood_cc();

  // merge these two nodes
  //
  Dt_node* tmp_dt_node  = (Dt_node*)NULL;
  tmp_dt_node = merge_nodes_cc(dt_node1_a, dt_node2_a);
  
  // compute the likelihood decrease
  //
  float_4 merge_likelihood =
    tmp_dt_node->compute_likelihood_cc(states_a, occupancy_a,
				       num_feat_a, num_mix_a);
  merge_lk_dec = lk_1 + lk_2 - merge_likelihood;

  // free memory
  //
  delete tmp_dt_node;

  // exit gracefully
  //
  return merge_lk_dec;
}
