// file: $isip_ifc/class/asr/SpeakerVerifier/SpeakerVerifier.h
// version: $Id: SpeakerVerifier.h 10480 2006-03-13 21:31:40Z raghavan $
//

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

#ifndef ISIP_VERIFY_HMM
#include <VerifyHMM.h>
#endif

#ifndef ISIP_SUPPORT_VECTOR_MACHINE
#include <SupportVectorMachine.h>
#endif

#ifndef ISIP_RELEVANCE_VECTOR_MACHINE
#include <RelevanceVectorMachine.h>
#endif

#ifndef ISIP_AUDIO_DATABASE
#include <AudioDatabase.h>
#endif

#ifndef ISIP_FEATURE_FILE
#include <FeatureFile.h>
#endif

#ifndef ISIP_STATISTICAL_MODEL
#include <StatisticalModel.h>
#endif

// SpeakerVerifier:  a class to set up parameters of the SpeakerVerifier
//                    system and run it
//
class SpeakerVerifier {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;
  
  // decalre constant string
  //
  static const String DEF_HMM_ALGO;
  static const String DEF_SVM_ALGO;
  static const String DEF_RVM_ALGO;
    
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  static const long ERR = (long)110000;

  // define algorithm types
  //
  enum ALGORITHM { HMM = 0, SVM, RVM, DEF_ALGORITHM = HMM };  
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // algorithm type
  //
  ALGORITHM algorithm_d;

  // parameter file
  //
  Filename param_file_name_d;
  
  // Verify HMM object
  //
  VerifyHMM hmm_d;

  // Support Vector Machine object
  //
  SupportVectorMachine svm_d;

  // Relevance Vector Machine object
  //
  RelevanceVectorMachine rvm_d;

  // debug level
  //
  static Integral::DEBUG debug_level_d;

  // verbosity
  //
  static Integral::DEBUG verbosity_d;
  
  // static memory manager
  //
  static MemoryManager mgr_d;

  // model file
  //
  Filename model_file_d;

  // audio db file
  //
  Filename audio_db_file_d;

  // output file
  //
  Filename output_file_d;

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

  // other static methods
  //   
  static boolean diagnose(Integral::DEBUG debug_level);

  // method: setDebug
  //
  boolean setDebug(Integral::DEBUG debug_level) {
    debug_level_d = debug_level;
    return true;
  }
  
  // constructor(s)/destructor(s)
  //
  SpeakerVerifier();
  SpeakerVerifier(const SpeakerVerifier& arg);
  ~SpeakerVerifier();

  // assign method
  //
  boolean assign(const SpeakerVerifier& arg); 
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------
  
  // method: setAlgorithm
  //
  boolean setAlgorithm(String algo_type) {
    if (algo_type.eq(DEF_HMM_ALGO)) 
      algorithm_d = HMM;
    else if (algo_type.eq(DEF_SVM_ALGO))
      algorithm_d = SVM;
    else if (algo_type.eq(DEF_RVM_ALGO))
      algorithm_d = RVM;
	
    return true;
  }

  // method: setParam
  //
  boolean setParam(String param_file_name);
  
  // method: setVerbosity
  //
  boolean setVerbosity(Integral::DEBUG verbosity) {
    verbosity_d = verbosity;
    return true;
  }

  // method: setModelFile
  //
  boolean setModelFile(Filename& model_file) {
    model_file_d = model_file;
    return true;
  }
  
  // method: setAudioDb
  //
  boolean setAudioDbFile(Filename& audio_db_file) {
    audio_db_file_d = audio_db_file;
    return true;
  }
  
  // method setOutputFile
  //
  boolean setOutputFile(Filename& output_file) {
   if (output_file.length() != 0) {
     // svm test output file
     //
     output_file_d = output_file; 
     return true;
   }
   return false;  
  }

  // method: setDecisionThresholds
  //
  boolean setDecisionThresholds(const String& decision_thresholds) {
    if ( decision_thresholds.length() != 0 ) {
      decision_thresholds_d.assign(decision_thresholds);
      return true;
    }
    return false;
  }
 
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  get methods
  //
  //---------------------------------------------------------------------------

  // method: getAlgorithm
  //
  ALGORITHM getAlgorithm() const {
    return algorithm_d;
  }  

  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  computational methods
  //
  //---------------------------------------------------------------------------
  
  // method: run
  // used for hmm training and testing, svm/rvm testing
  //
  boolean run(Sdb& sdb);
  
  // method: run
  // used for svm/rvm training
  //
  boolean run(Sdb& pos_sdb, Sdb& neg_sdb);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:
  
};

//end of include file
//
#endif
