// file: $isip/class/pr/VerifyHMM/VerifyHMM.h
// version: $Id: VerifyHMM.h 10505 2006-03-16 18:28:07Z may $
//

// make sure definitions are only made once
//
#ifndef ISIP_VERIFY_HMM
#define ISIP_VERIFY_HMM

#ifndef ISIP_HIDDEN_MARKOV_MODEL
#include <HiddenMarkovModel.h>
#endif


// VerifyHMM: a class that contains the interface for the verification
// system training and verification
//
class VerifyHMM : public HiddenMarkovModel {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;

  // define the algorithm choices
  //
  enum ALGORITHM { VERIFY = 0, TRAIN, MODEL_CREATION, INITIALIZE,
		   MIXTURE_SPLITTING, DEF_ALGORITHM = VERIFY };
  
  // define the implementation choices
  //
  enum IMPLEMENTATION { LIKELIHOOD_RATIO = 0, BAUM_WELCH,
			GLOBAL, VARIANCE_SPLITTING, LIKELIHOOD,
			DEF_IMPLEMENTATION = LIKELIHOOD_RATIO };

  // define the static NameMap objects
  //
  static const NameMap IMPL_MAP;
  static const NameMap ALGO_MAP;
  
  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------
  
  static const String PARAM_IMPOSTER_LANGUAGE_MODEL;
  static const String PARAM_IMPOSTER_STATISTICAL_MODEL_POOL;
  static const String PARAM_DECISION_THRESHOLDS;
  
  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------
  
  // default values
  //
  static const String DEF_DECISION_THRESHOLDS;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:
  
  // algorithm name
  //
  ALGORITHM algorithm_d;
  
  // implementation name
  //
  IMPLEMENTATION implementation_d;

  // imposter language model file
  //
  Filename imp_lm_file_d;

  // imposter statistical model pool file
  //
  Filename imp_smp_file_d;

  // decision thresholds
  //
  VectorFloat decision_thresholds_d;
  
  // hierarchical search for imposter models. note that for speaker
  // models, we use the search-engine from the base HMM class
  //
  HierarchicalSearch imp_search_engine_d;

  // Language model for imposter models. note that for speaker
  // models, we use the language model from the base HMM class
  //
  LanguageModelIHD imp_lm_d;
  
  // static memory manager
  //
  static MemoryManager mgr_d;

  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // other static methods
  //   
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // constructor(s)/destructor(s)
  //
  ~VerifyHMM();
  VerifyHMM();
  VerifyHMM(const VerifyHMM& arg);

  // method: assign
  //
  boolean assign(const VerifyHMM& arg) {
    return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__);
  }
  
  // i/o methods
  //
  long sofSize() const;
  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);
  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;
  
  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT,
		   boolean param = true,
		   boolean nested = false);
  boolean writeData(Sof& sof, const String& param = DEF_PARAM) const;

  // method: new
  //
  static void* operator new(size_t size) {
    return mgr_d.get();
  }

  // method: new[]
  //
  static void* operator new[](size_t size) {
    return mgr_d.getBlock(size);
  }

  // method: delete
  //
  static void operator delete(void* ptr) {
    mgr_d.release(ptr);
  }

  // method: delete[]
  //
  static void operator delete[](void* ptr) {
    mgr_d.releaseBlock(ptr);
  }

  // method: setGrowSize
  //
  static boolean setGrowSize(long grow_size) {
    return mgr_d.setGrow(grow_size);
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //  set methods
  //
  //---------------------------------------------------------------------------
  
  // method: getAlgorithm
  //
  ALGORITHM getAlgorithm() {
    return algorithm_d;
  }

  // method: setAlgorithm
  //
  boolean setAlgorithm(ALGORITHM arg) {
    return (algorithm_d = arg);
  }

  // method: getImplementation
  //
  IMPLEMENTATION getImplementation() {
    return implementation_d;
  }
  
  // method: setImplementation
  //
  boolean setImplementation(IMPLEMENTATION arg) {
    return (implementation_d = arg);
  }

  // method: getImposterLanguageModelFile
  //
  Filename& getImposterLanguageModelFile() {
    return imp_lm_file_d;
  }
  
  // method: setImposterLanguageModelFile
  //
  boolean setImposterLanguageModelFile(const Filename& arg) {
    return imp_lm_file_d.assign(arg);
  }

  // method: getImposterStatisticalModelPoolFile
  //
  Filename& getImposterStatisticalModelPoolFile() {
    return imp_smp_file_d;
  }
  
  // method: setImposterStatisticalModelPoolFile
  //
  boolean setImposterStatisticalModelPoolFile(const Filename& arg) {
    return imp_smp_file_d.assign(arg);
  }

  // method: getDecisionThresholds
  //
  VectorFloat getDecisionThresholds() {
    return decision_thresholds_d;
  }

  // method: setDecisionThresholds
  //
  boolean setDecisionThresholds(const VectorFloat& decision_thresholds) {
    decision_thresholds_d = decision_thresholds;
    return true;
  }

  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  computational methods
  //
  //---------------------------------------------------------------------------

  // run methods
  //
  boolean run(Sdb& sdb);

  // load methods
  //
  boolean load();

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
  private:

  boolean verify(Sdb& sdb);
  boolean verifylr(Sdb& sdb);
  boolean verifyl(Sdb& sdb);
};

//end of include file
//
#endif
