Ejemplo n.º 1
0
// construit les matrices emit et trans à l'aide de l'algorithme Baum-Welch
void learn(const std::string& name, unsigned int maxIterations)
{
    Hmm hmm;
    std::string output = (boost::format("seq-%1%-result") %
                          name).str();
    ifstream istrm((boost::format("seq-%1%.input") % name).str().c_str());
    std:: vector < std::vector < unsigned long >* > trainingSequences;

    hmm.loadProbs((boost::format("seq-%1%-init") % name).str().c_str());
    hmm.readSeqs(istrm, trainingSequences);
    hmm.baumWelch(trainingSequences, maxIterations);
    hmm.saveProbs(output.c_str());
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
  Hmm hmm;
  if (argc<3) {
    cerr << "USAGE: trainhmm INIT-HMM RESULT-HMM DATA [MAX-ITERATIONS]" << endl;
    exit(1);
  }

  hmm.loadProbs(argv[1]);
  const char* output = argv[2];
  ifstream istrm(argv[3]);
  int maxIterations = 10;
  if (argc>4)
    maxIterations = atoi(argv[4]);

  vector<vector<unsigned long>*> trainingSequences;
  hmm.readSeqs(istrm, trainingSequences);
  hmm.baumWelch(trainingSequences, maxIterations);
  hmm.saveProbs(output);
}