// ht_state_2.cc
//
// isip include files
//
#include "hmm_train.h"
#include "hmm_train_constants.h"

// method: count_state_cc
//
// arguments:
//  Train_Trace* trace : (input) the current trace
//  float_8** data : (input) the all feature vectors in current input file
//  float_8*** mean : (output) the sum of the data in each state
//  float_8*** covar : (output) the sum of the covar in each state
//  int_4** count : (output) the number of data in each state
//  int_4 num_feat : (input) the number of features
//  int_4 num_st : (input) the number of states
//  int_4 num_mix : (input) the number of mixtures
//  Train_State** states : (input) the states
//  int_4* mod_map : (input) the map from phone to model
//  int_4** st_map : (input) the map from model and temp state to final state
//
// return: a logical_1 flag indicating success
//
// this method update the mean and covar according to the input trace
//
logical_1 count_state_cc(Train_Trace* trace_a, float_8** data_a, float_8*** mean_a,
			 float_8*** covar_a, int_4** count_a, int_4 num_feat_a,
			 int_4 num_st_a, int_4 num_mix_a, Train_State** states_a,
			 int_4* mod_map_a, int_4** st_map_a) {

  // get the state index of the current trace
  //
  int_4 st_ind = (int_4)0;
  get_ind_st_cc(trace_a, st_ind, mod_map_a, st_map_a);

  // get the maximum mixture for the current trace
  //
  int_4 max_mix = (int_4)0;
  max_mix = trace_a->get_max_mixture_cc();

  // accumulate the mean and covar
  //
  int_4 ind_frame = trace_a->get_frame_ind_cc();

  for (int_4 j = 0; j < num_feat_a; j++) {
    mean_a[st_ind][max_mix][j] += data_a[ind_frame][j];
  }
  count_a[st_ind][max_mix]++;
  
  for (int_4 j = 0; j < num_feat_a; j++) {
    covar_a[st_ind][max_mix][j] += (data_a[ind_frame][j] *
				data_a[ind_frame][j]);
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
