// file: bw_occ_0.cc
//

// isip include files
//
#include "bw_train.h"
#include "bw_train_constants.h"

// method: comp_occ_cc
//
// arguments:
//  float_8& occ_prob : (output) the mixture occupancy
//  int_4 mod_ind : (input) the current model index
//  int_4 loc_st : (input) the number of states in current model
//  int_4 frame : (input) the current frame index
//  State* state : (input) the current state
//  int_4 cur_st : (input) the current state index
//  int_4 mix_ind : (input) the mixture component index
//  float_8 utt_prob : (input) the probability of the current utterance
//  float_4** trans : (input) the transition matrix
//  float_8** for_probt : (input) the forward probability of current frame
//  float_8** for_probt1 : (input) the forward prob. of previous frame
//  float_8*** back_prob : (input) the backward probability
//  float_8* data : (input) the current frame of acoustic data
//
// return a logical flag to indicate success
//
// this method calculates the occupancy probability
//
logical_1 comp_occ_cc(float_8& occ_prob_a, int_4 mod_ind_a, int_4 loc_st_a,
		      int_4 frame_a, Train_State* state_a, int_4 cur_st_a,
		      int_4 mix_ind_a, float_8 utt_prob_a,
		      float_4** trans_a, float_8** for_probt_a,
		      float_8** for_probt1_a,
		      float_8*** back_prob_a, float_8* data_a) {
  
  // local variables
  //
  float_8 for_occ = BW_LOG_ZERO;
  float_8 tmp_score = BW_LOG_ZERO;
  
  // compute the forward part for mixture occupancy
  //
  comp_focc_cc(for_occ, trans_a, for_probt_a, for_probt1_a, mod_ind_a,
	       loc_st_a, cur_st_a, frame_a);
  
  // compute the score based on current mixture component
  //
  tmp_score = state_a->eval_score_cc(mix_ind_a, data_a);
  
  // compute the whole occupancy
  //
  occ_prob_a = for_occ + tmp_score + back_prob_a[frame_a][mod_ind_a][cur_st_a]
    - utt_prob_a;

  if (occ_prob_a <= BW_LOG_ZERO) {
    occ_prob_a = BW_LOG_ZERO;
  }

  // exit gracefully
  //
  return(ISIP_TRUE);
}
  

