[mlpack-svn] r10786 - mlpack/trunk/src/mlpack/methods/hmm

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Dec 14 12:16:02 EST 2011


Author: rcurtin
Date: 2011-12-14 12:16:02 -0500 (Wed, 14 Dec 2011)
New Revision: 10786

Removed:
   mlpack/trunk/src/mlpack/methods/hmm/generate.cpp
   mlpack/trunk/src/mlpack/methods/hmm/loglik.cpp
   mlpack/trunk/src/mlpack/methods/hmm/train.cpp
   mlpack/trunk/src/mlpack/methods/hmm/viterbi.cpp
Modified:
   mlpack/trunk/src/mlpack/methods/hmm/CMakeLists.txt
Log:
Remove these executables because they don't work anymore.


Modified: mlpack/trunk/src/mlpack/methods/hmm/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/CMakeLists.txt	2011-12-14 16:50:31 UTC (rev 10785)
+++ mlpack/trunk/src/mlpack/methods/hmm/CMakeLists.txt	2011-12-14 17:16:02 UTC (rev 10786)
@@ -19,32 +19,3 @@
 # Append sources (with directory name) to list of all MLPACK sources (used at
 # the parent scope).
 set(MLPACK_SRCS ${MLPACK_SRCS} ${DIR_SRCS} PARENT_SCOPE)
-
-# executables
-#add_executable(generate
-#  generate.cpp
-#)
-#target_link_libraries(generate
-#  mlpack
-#)
-
-#add_executable(loglik
-#  loglik.cpp
-#)
-#target_link_libraries(loglik
-#  mlpack
-#)
-
-#add_executable(viterbi
-#  viterbi.cpp
-#)
-#target_link_libraries(viterbi
-#  mlpack
-#)
-
-#add_executable(train
-#  train.cpp
-#)
-#target_link_libraries(train
-#  mlpack
-#)

Deleted: mlpack/trunk/src/mlpack/methods/hmm/generate.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/generate.cpp	2011-12-14 16:50:31 UTC (rev 10785)
+++ mlpack/trunk/src/mlpack/methods/hmm/generate.cpp	2011-12-14 17:16:02 UTC (rev 10786)
@@ -1,226 +0,0 @@
-/**
- * @file generate.cc
- *
- * This file contains the program to generate sequences from a Hidden Markov
- * Model.
- *
- * Usage:
- *   generate --type=TYPE --profile=PROFILE [OPTCLINS]
- * See the usage() function for complete option list
- */
-#include <mlpack/core.hpp>
-
-#include "support.hpp"
-#include "discreteHMM.hpp"
-#include "gaussianHMM.hpp"
-#include "mixgaussHMM.hpp"
-#include "mixtureDST.hpp"
-
-using namespace mlpack;
-using namespace hmm;
-using namespace hmm_support;
-
-bool generate_discrete();
-bool generate_gaussian();
-bool generate_mixture();
-void usage();
-
-PARAM_STRING_REQ("type", "HMM type : discrete | gaussian | mixture.", "");
-PARAM_STRING_REQ("profile", "A file containing HMM profile.", "");
-PARAM_STRING_REQ("seqfile", "Output file for the generated sequences.", "");
-PARAM_STRING_REQ("statefile", "Output file for the generated state sequences.",
-		"");
-
-PARAM_INT("length", "Sequence length, default = 10.", "", 10);
-PARAM_INT("lenmax", "Maximum sequence length, default = 10", "", 10);
-PARAM_INT("numseq", "Number of sequance, default = 10.\n", "", 10);
-
-PARAM_MODULE("hmm", "This is a program generating sequences from HMM models.");
-
-int main(int argc, char* argv[]) {
-
-  CLI::ParseCommandLine(argc, argv);
-  bool s = true;
-  if (CLI::HasParam("type")) {
-    const char* type = CLI::GetParam<std::string>("type").c_str();
-    if (strcmp(type, "discrete")==0)
-      s = generate_discrete();
-    else if (strcmp(type, "gaussian")==0)
-      s = generate_gaussian();
-    else if (strcmp(type, "mixture")==0)
-      s = generate_mixture();
-    else {
-      Log::Fatal << "Unrecognized type: must be: " <<
-		"discrete | gaussian | mixture !!!" << std::endl;
-      return true;
-    }
-  }
-  else {
-    Log::Fatal << "Unrecognized type: must be: " <<
-		"discrete | gaussian | mixture  !!!" << std::endl;
-    s = false;
-  }
-  if (!(s)) usage();
-
-}
-
-void usage() {
-  Log::Info << std::endl << "Usage:" << std::endl;
-  Log::Info << "  generate --type=={discrete|gaussian|mixture} OPTCLINS" << std::endl;
-  Log::Info << "[OPTCLINS]" << std::endl;
-  Log::Info << "  --profile=file   : file contains HMM profile" << std::endl;
-  Log::Info << "  --length=NUM     : sequence length" << std::endl;
-  Log::Info << "  --lenmax=NUM     : maximum sequence length, default = length" << std::endl;
-  Log::Info << "  --numseq=NUM     : number of sequence" << std::endl;
-  Log::Info << "  --seqfile=file   : output file for generated sequences" << std::endl;
-  Log::Info << "  --statefile=file : output file for generated state sequences" << std::endl;
-}
-
-bool generate_mixture() {
-  if (!CLI::HasParam("profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("profile").c_str();
-  const int seqlen = CLI::GetParam<int>("length");
-  const int seqlmax = CLI::GetParam<int>("lenmax");
-  const int numseq = CLI::GetParam<int>("numseq");
-  //const char* seqout = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str();
-
-  Log::Assert(seqlen <= seqlmax, "LENMAX must bigger than LENGTH");
-  Log::Assert(numseq > 0, "NUMSEQ must be positive");
-
-  //double step = (double) (seqlmax - seqlen) / numseq;
-
-  MixtureofGaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  /** need something better
-  TextWriter w_seq, w_state;
-  if (!(w_seq.Open(seqout))) {
-    Log::Warn << "Couldn't open '" << seqout << "' for writing." << std::endl;
-    return false;
-  }
-
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  double L = seqlen;
-  for (int i = 0; i < numseq; i++, L += step) {
-    arma::mat seq;
-    arma::vec states;
-    char s[100];
-
-    hmm.GenerateSequence((int)L, seq, states);
-
-    sprintf(s, "%% sequence %d", i);
-    print_matrix(w_seq, seq, s, "%E,");
-    sprintf(s, "%% state sequence %d", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-
-  //printf("---END---");
-  return true;
-}
-
-bool generate_gaussian() {
-  if (!CLI::HasParam("profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("profile").c_str();
-  const int seqlen = CLI::GetParam<int>("length");
-  const int seqlmax = CLI::GetParam<int>("lenmax");
-  const int numseq = CLI::GetParam<int>("numseq");
-  //const char* seqout = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str();
-
-  Log::Assert(seqlen <= seqlmax, "LENMAX must bigger than LENGTH");
-  Log::Assert(numseq > 0, "NUMSEQ must be positive");
-
-  //double step = (double) (seqlmax - seqlen) / numseq;
-
-  GaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  /** need something better
-  TextWriter w_seq, w_state;
-  if (!(w_seq.Open(seqout))) {
-    Log::Warn << "Couldn't open '" << seqout << "' for writing." << std::endl;
-    return false;
-  }
-
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  double L = seqlen;
-  for (int i = 0; i < numseq; i++, L+=step) {
-    arma::mat seq;
-    arma::vec states;
-    char s[100];
-
-    hmm.GenerateSequence((int) L, seq, states);
-
-    sprintf(s, "%% sequence %d", i);
-    print_matrix(w_seq, seq, s, "%E,");
-    sprintf(s, "%% state sequence %d", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-
-  return true;
-}
-
-bool generate_discrete() {
-  if (!CLI::HasParam("profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("profile").c_str();
-  const int seqlen = CLI::GetParam<int>("length");
-  const int seqlmax = CLI::GetParam<int>("lenmax");
-  const int numseq = CLI::GetParam<int>("numseq");
-  //const char* seqout = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str();
-
-  Log::Assert(seqlen <= seqlmax, "LENMAX must bigger than LENGTH");
-  Log::Assert(numseq > 0, "NUMSEQ must be positive");
-
-  //double step = (double) (seqlmax - seqlen) / numseq;
-
-  DiscreteHMM hmm;
-  hmm.InitFromFile(profile);
-
-  /** need something better
-  TextWriter w_seq, w_state;
-  if (!(w_seq.Open(seqout))) {
-    Log::Warn << "Couldn't open '" << seqout << "' for writing." << std::endl;
-    return false;
-  }
-
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  double L = seqlen;
-  for (int i = 0; i < numseq; i++, L+=step) {
-    arma::vec seq, states;
-    char s[100];
-
-    hmm.GenerateSequence((int) L, seq, states);
-
-    sprintf(s, "%% sequence %d", i);
-    print_vector(w_seq, seq, s, "%.0f,");
-    sprintf(s, "%% state sequence %d", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-  return true;
-}

Deleted: mlpack/trunk/src/mlpack/methods/hmm/loglik.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/loglik.cpp	2011-12-14 16:50:31 UTC (rev 10785)
+++ mlpack/trunk/src/mlpack/methods/hmm/loglik.cpp	2011-12-14 17:16:02 UTC (rev 10786)
@@ -1,187 +0,0 @@
-/**
- * @file loglik.cc
- *
- * This file contains the program to compute log-likelihood of sequences
- * according to a Hidden Markov  Model.
- *
- * Usage:
- *   loglik --type=TYPE --profile=PROFILE [OPTCLINS]
- * See the usage() function for complete option list
- */
-#include <mlpack/core.hpp>
-
-#include "support.hpp"
-#include "discreteHMM.hpp"
-#include "gaussianHMM.hpp"
-#include "mixgaussHMM.hpp"
-#include "mixtureDST.hpp"
-
-using namespace mlpack;
-using namespace hmm;
-using namespace hmm_support;
-
-bool loglik_discrete();
-bool loglik_gaussian();
-bool loglik_mixture();
-void usage();
-
-/*const fx_entry_doc hmm_loglik_main_entries[] = {
-  {"type", FX_REQUIRED, FX_STR, NULL,
-   "  HMM type : discrete | gaussian | mixture.\n"},
-  {"profile", FX_REQUIRED, FX_STR, NULL,
-   "  A file containing HMM profile.\n"},
-  {"seqfile", FX_PARAM, FX_STR, NULL,
-   "  Output file for the data sequences.\n"},
-  {"logfile", FX_PARAM, FX_STR, NULL,
-   "  Output file for the computed log-likelihood of the sequences.\n"},
-  FX_ENTRY_DOC_DONE
-};*/
-
-PARAM_STRING_REQ("type", "HMM type : discrete | gaussian | mixture.", "hmm");
-PARAM_STRING_REQ("profile", "A file containing HMM profile.", "hmm");
-PARAM_STRING("seqfile", "Outputfile for the datasequences.",
-	"hmm", "seq.mix.out");
-PARAM_STRING("logfile",
-	"Output file for the computed log-likelihood of the sequences.",
-	"hmm", "log.mix.out");
-
-PARAM_MODULE("hmm", "This is a program computing log-likelihood of data \nsequences from HMM models.");
-/* const fx_submodule_doc hmm_loglik_main_submodules[] = {
-  FX_SUBMODULE_DOC_DONE
-}; */
-
-/* const fx_module_doc hmm_loglik_main_doc = {
-  hmm_loglik_main_entries, hmm_loglik_main_submodules,
-  "This is a program computing log-likelihood of data sequences \n"
-  "from HMM models.\n"
-}; */
-
-int main(int argc, char* argv[]) {
-  CLI::ParseCommandLine(argc, argv);
-
-  bool s = true;
-  if (CLI::HasParam("hmm/type")) {
-    const char* type = CLI::GetParam<std::string>("hmm/type").c_str();
-    if (strcmp(type, "discrete")==0)
-      s = loglik_discrete();
-    else if (strcmp(type, "gaussian")==0)
-      s = loglik_gaussian();
-    else if (strcmp(type, "mixture")==0)
-      s = loglik_mixture();
-    else {
-      Log::Info << "Unrecognized type: must be: discrete | gaussian | mixture !!!";
-      s = false;
-    }
-  }
-  else {
-    Log::Info << "Unrecognized type: must be: discrete | gaussian | mixture  !!!";
-    s = false;
-  }
-  if (!(s)) usage();
-}
-
-void usage() {
-  Log::Warn << "\n" << std::endl;
-  Log::Warn << "Usage:\n" << std::endl;
-  Log::Warn << "  loglik --type=={discrete|gaussian|mixture} OPTCLINS" << std::endl;
-  Log::Warn << "[OPTCLINS]" << std::endl;
-  Log::Warn << "  --profile==file   : file contains HMM profile" << std::endl;
-  Log::Warn << "  --seqfile==file   : file contains input sequences" << std::endl;
-  Log::Warn << "  --logfile==file   : output file for log-likelihood of the sequences" << std::endl;
-}
-
-bool loglik_mixture() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Warn << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* logout = CLI::GetParam<std::string>("hmm/logfile").c_str();
-
-  MixtureofGaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::mat> seqs;
-  load_matrix_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_log;
-  if (!(w_log.Open(logout))) {
-    Log::Warn << "Couldn't open '" << logout << "' for writing." << std::endl;
-    return false;
-  }
-
-  std::vector<double> list_loglik;
-  hmm.ComputeLogLikelihood(seqs, list_loglik);
-
-  for (size_t i = 0; i < seqs.size(); i++)
-    w_log.Printf("%f\n", list_loglik[i]);
-  */
-
-  return true;
-}
-
-bool loglik_gaussian() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Warn << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* logout = CLI::GetParam<std::string>("hmm/logfile").c_str();
-
-  GaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::mat> seqs;
-  load_matrix_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_log;
-  if (!(w_log.Open(logout))) {
-    Log::Warn << "Couldn't open '"<< logout <<"' for writing." << std::endl;
-    return false;
-  }
-
-  std::vector<double> list_loglik;
-  hmm.ComputeLogLikelihood(seqs, list_loglik);
-
-  for (size_t i = 0; i < seqs.size(); i++)
-    w_log.Printf("%f\n", list_loglik[i]);
-  */
-
-  return true;
-}
-
-bool loglik_discrete() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Warn << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str();
-  //const char* logout = CLI::GetParam<std::string>("hmm/logfile").c_str();
-
-  DiscreteHMM hmm;
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::vec> seqs;
-  load_vector_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_log;
-  if (!(w_log.Open(logout))) {
-    Log::Warn << "Couldn't open '"<< logout <<"' for writing." << std::endl;
-    return false;
-  }
-
-  std::vector<double> list_loglik;
-  hmm.ComputeLogLikelihood(seqs, list_loglik);
-
-  for (size_t i = 0; i < seqs.size(); i++)
-    w_log.Printf("%f\n", list_loglik[i]);
-  */
-
-  return true;
-}

Deleted: mlpack/trunk/src/mlpack/methods/hmm/train.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/train.cpp	2011-12-14 16:50:31 UTC (rev 10785)
+++ mlpack/trunk/src/mlpack/methods/hmm/train.cpp	2011-12-14 17:16:02 UTC (rev 10786)
@@ -1,324 +0,0 @@
-/**
- * @file train.cc
- *
- * This file contains the program to estimate Hidden Markov Model parameter
- * using training sequences.
- *
- * It use two algorithm: Baum-Welch (EM) and Viterbi
- *
- * Usage:
- *   train --type=TYPE --profile=PROFILE --seqfile=FILE [OPTCLINS]
- * See the usage() function for complete option list
- */
-#include <mlpack/core.hpp>
-
-#include "support.hpp"
-#include "discreteHMM.hpp"
-#include "gaussianHMM.hpp"
-#include "mixgaussHMM.hpp"
-#include "mixtureDST.hpp"
-
-using namespace mlpack;
-using namespace hmm;
-using namespace hmm_support;
-
-bool train_baumwelch();
-bool train_viterbi();
-void usage();
-
-PARAM_STRING_REQ("type", "HMM type : discrete | gaussian | mixture.", "T");
-PARAM_STRING_REQ("profile", "A file containing HMM profile.", "P");
-PARAM_STRING_REQ("seqfile", "Output file for the generated sequences.", "S");
-PARAM_STRING("algorithm", "Training algorithm: baumwelch | viterbi.", "A",
-	"baumwelch");
-PARAM_STRING("guess", "File containing guessing HMM model profile.", "G",
-	"");
-
-
-PARAM(double, "tolerance",
-	"Error tolerance on log-likelihood as a stopping criteria.", "R", 1e-3, false);
-PARAM_INT("maxiter", "Maximum number of iterations, default = 500.", "M", 500);
-PARAM_INT("numstate", "If no guessing profile specified, at least provide the number of states.", "N", 10);
-
-void usage() {
-  Log::Warn << "Usage:" << std::endl;
-  Log::Warn << "  train --type=={discrete|gaussian|mixture} OPTCLIN" << std::endl;
-  Log::Warn << "[OPTCLINS]" << std::endl;
-  Log::Warn << "  --algorithm={baumwelch|viterbi} : algorithm used for training, default Baum-Welch" << std::endl;
-  Log::Warn << "  --seqfile=file   : file contains input sequences" << std::endl;
-  Log::Warn << "  --guess=file     : file contains guess HMM profile" << std::endl;
-  Log::Warn << "  --numstate=NUM   : if no guess profile is specified, at least specify the number of state" << std::endl;
-  Log::Warn << "  --profile=file   : output file for estimated HMM profile" << std::endl;
-  Log::Warn << "  --maxiter=NUM    : maximum number of iteration, default=500" << std::endl;
-  Log::Warn << "  --tolerance=NUM  : error tolerance on log-likelihood, default=1e-3" << std::endl;
-}
-
-int main(int argc, char* argv[]) {
-  CLI::ParseCommandLine(argc, argv);
-
-  bool s = true;
-  if (CLI::HasParam("type")) {
-    const char* algorithm = CLI::GetParam<std::string>("algorithm").c_str();
-    if (strcmp(algorithm,"baumwelch") == 0)
-      s = train_baumwelch();
-    else if (strcmp(algorithm,"viterbi") == 0)
-      s = train_viterbi();
-    else {
-      Log::Fatal << "Unrecognized algorithm: must be baumwelch or viterbi!";
-      s = false;
-    }
-  }
-  else {
-    Log::Fatal << "Unrecognized type: must be: discrete | gaussian | mixture!";
-    s = false;
-  }
-  if (!(s)) usage();
-}
-
-bool train_baumwelch_discrete();
-bool train_baumwelch_gaussian();
-bool train_baumwelch_mixture();
-
-bool train_baumwelch() {
-  const char* type = CLI::GetParam<std::string>("type").c_str();
-  if (strcmp(type, "discrete")==0)
-    return train_baumwelch_discrete();
-  else if (strcmp(type, "gaussian")==0)
-    return train_baumwelch_gaussian();
-  else if (strcmp(type, "mixture")==0)
-    return train_baumwelch_mixture();
-  else {
-    printf("Unrecognized type: must be: discrete | gaussian | mixture!\n");
-    return false;
-  }
-}
-
-bool train_viterbi_discrete();
-bool train_viterbi_gaussian();
-bool train_viterbi_mixture();
-
-bool train_viterbi() {
-  const char* type = CLI::GetParam<std::string>("type").c_str();
-  if (strcmp(type, "discrete")==0)
-    return train_viterbi_discrete();
-  else if (strcmp(type, "gaussian")==0)
-    return train_viterbi_gaussian();
-  else if (strcmp(type, "mixture")==0)
-    return train_viterbi_mixture();
-  else {
-    printf("Unrecognized type: must be: discrete | gaussian | mixture !!!\n");
-    return false;
-  }
-}
-
-bool train_baumwelch_mixture() {
-  if (!CLI::HasParam("seqfile")) {
-    printf("--seqfile must be defined.\n");
-    return false;
-  }
-
-  MixtureofGaussianHMM hmm;
-  std::vector<arma::mat> seqs;
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.mix.out"
-
-  load_matrix_list(seqin, seqs);
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  }
-  else {
-    hmm.Init();
-    Log::Fatal <<"Automatic initialization not supported !!!";
-    return false;
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  hmm.TrainBaumWelch(seqs, maxiter, tol);
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}
-
-bool train_baumwelch_gaussian() {
-  if (!CLI::HasParam("seqfile")) {
-    printf("--seqfile must be defined.\n");
-    return false;
-  }
-  GaussianHMM hmm;
-  std::vector<arma::mat> seqs;
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.gauss.out");
-
-  load_matrix_list(seqin, seqs);
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  }
-  else { // otherwise initialized using information from the data
-    int numstate = CLI::GetParam<int>("numstate");
-    Log::Info << "Generate HMM parameters: NUMSTATE = " << numstate << std::endl;
-    hmm.InitFromData(seqs, numstate);
-    Log::Info << "Done." << std::endl;
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  printf("Training ...\n");
-  hmm.TrainBaumWelch(seqs, maxiter, tol);
-  printf("Done.\n");
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}
-
-bool train_baumwelch_discrete() {
-  if (!CLI::HasParam("seqfile")) {
-    printf("--seqfile must be defined.\n");
-    return false;
-  }
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.dis.out");
-
-  std::vector<arma::vec> seqs;
-  load_vector_list(seqin, seqs);
-
-  DiscreteHMM hmm;
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load HMM parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  }
-  else { // otherwise randomly initialized using information from the data
-    int numstate = CLI::GetParam<int>("numstate");
-    Log::Info << "Randomly generate parameters: NUMSTATE = " << numstate << std::endl;
-    hmm.InitFromData(seqs, numstate);
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  hmm.TrainBaumWelch(seqs, maxiter, tol);
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}
-
-bool train_viterbi_mixture() {
-  if (!CLI::HasParam("seqfile")) {
-    printf("--seqfile must be defined.\n");
-    return false;
-  }
-
-  MixtureofGaussianHMM hmm;
-  std::vector<arma::mat> seqs;
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.mix.out");
-
-  load_matrix_list(seqin, seqs);
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  } else {
-    hmm.Init();
-    Log::Info << "Automatic initialization not supported !!!" << std::endl;
-    return false;
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  hmm.TrainViterbi(seqs, maxiter, tol);
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}
-
-bool train_viterbi_gaussian() {
-  if (!CLI::HasParam("seqfile")) {
-    Log::Fatal << "--seqfile must be defined." << std::endl;
-    return false;
-  }
-
-  GaussianHMM hmm;
-  std::vector<arma::mat> seqs;
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.gauss.viterbi.out");
-
-  load_matrix_list(seqin, seqs);
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  }
-  else { // otherwise initialized using information from the data
-    int numstate = CLI::GetParam<int>("numstate");
-    Log::Info << "Generate parameters: NUMSTATE = " << numstate << std::endl;
-    hmm.InitFromData(seqs, numstate);
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  hmm.TrainViterbi(seqs, maxiter, tol);
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}
-
-bool train_viterbi_discrete() {
-  if (!CLI::HasParam("seqfile")) {
-    printf("--seqfile must be defined.\n");
-    return false;
-  }
-
-  DiscreteHMM hmm;
-  std::vector<arma::vec> seqs;
-
-  const char* seqin = CLI::GetParam<std::string>("seqfile").c_str();
-  const char* proout = CLI::GetParam<std::string>("profile").c_str(); //"pro.dis.viterbi.out");
-
-  load_vector_list(seqin, seqs);
-
-  if (CLI::HasParam("guess")) { // guessed parameters in a file
-    std::vector<arma::mat> matlst;
-    const char* guess = CLI::GetParam<std::string>("guess").c_str();
-    Log::Info << "Load parameters from file " << guess << std::endl;
-    hmm.InitFromFile(guess);
-  }
-  else { // otherwise randomly initialized using information from the data
-    int numstate = CLI::GetParam<int>("numstate");
-    printf("Generate parameters with NUMSTATE = %d\n", numstate);
-    hmm.InitFromData(seqs, numstate);
-  }
-
-  int maxiter = CLI::GetParam<int>("maxiter");
-  double tol = CLI::GetParam<double>("tolerance");
-
-  hmm.TrainViterbi(seqs, maxiter, tol);
-
-  hmm.SaveProfile(proout);
-
-  return true;
-}

Deleted: mlpack/trunk/src/mlpack/methods/hmm/viterbi.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/viterbi.cpp	2011-12-14 16:50:31 UTC (rev 10785)
+++ mlpack/trunk/src/mlpack/methods/hmm/viterbi.cpp	2011-12-14 17:16:02 UTC (rev 10786)
@@ -1,196 +0,0 @@
-/**
- * @file viterbi.cc
- *
- * This file contains the program to compute the most probable state sequences
- * in a Hidden Markov Model of given sequences
- * Model.
- *
- * Usage:
- *   viterbi --type=TYPE --profile=PROFILE --seqfile=FILE [OPTCLINS]
- * See the usage() function for complete option list
- */
-#include <mlpack/core.hpp>
-
-#include "support.hpp"
-#include "discreteHMM.hpp"
-#include "gaussianHMM.hpp"
-#include "mixgaussHMM.hpp"
-#include "mixtureDST.hpp"
-
-using namespace mlpack;
-using namespace hmm;
-using namespace hmm_support;
-
-bool viterbi_discrete();
-bool viterbi_gaussian();
-bool viterbi_mixture();
-void usage();
-
-/* const fx_entry_doc hmm_viterbi_main_entries[] = {
-  {"type", FX_REQUIRED, FX_STR, NULL,
-   "  HMM type : discrete | gaussian | mixture.\n"},
-  {"profile", FX_REQUIRED, FX_STR, NULL,
-   "  A file containing HMM profile.\n"},
-  {"seqfile", FX_PARAM, FX_STR, NULL,
-   "  Output file for the data sequences.\n"},
-  {"statefile", FX_PARAM, FX_STR, NULL,
-   "  Output file for the most probable state sequences.\n"},
-  FX_ENTRY_DOC_DONE
-}; */
-
-PARAM_STRING_REQ("type", "HMM type : discrete | gaussian | mistruxe.", "hmm");
-PARAM_STRING_REQ("profile", "A file containing HMM profile", "hmm");
-PARAM_STRING_REQ("seqfile", "Output file for the data sequences.", "hmm");
-PARAM_STRING_REQ("statefile", "Output file for the most probable state sequences.", "hmm");
-
-PARAM_MODULE("hmm", "This is a program computing th emost probable state\n sequences of data sequences from HMM models.\n");
-/* const fx_submodule_doc hmm_viterbi_main_submodules[] = {
-  FX_SUBMODULE_DOC_DONE
-}; */
-
-/* const fx_module_doc hmm_viterbi_main_doc = {
-  hmm_viterbi_main_entries, hmm_viterbi_main_submodules,
-  "This is a program computing the most probable state sequences \n"
-  "of data sequences from HMM models.\n"
-}; */
-
-int main(int argc, char* argv[]) {
-  CLI::ParseCommandLine(argc, argv);
-
-  bool s = true;
-  if (CLI::HasParam("hmm/type")) {
-    const char* type = CLI::GetParam<std::string>("hmm/type").c_str();
-    if (strcmp(type, "discrete") == 0)
-      s = viterbi_discrete();
-    else if (strcmp(type, "gaussian") == 0)
-      s = viterbi_gaussian();
-    else if (strcmp(type, "mixture") == 0)
-      s = viterbi_mixture();
-    else {
-      Log::Warn << "Unrecognized type: must be: discrete | gaussian | mixture!" << std::endl;
-      s = false;
-    }
-  }
-  else {
-    Log::Warn << "Unrecognized type: must be: discrete | gaussian | mixture!";
-    s = false;
-  }
-  if (!(s)) usage();
-}
-
-void usage() {
-  Log::Warn << "Usage:" << std::endl;
-  Log::Warn << "  viterbi --type=={discrete|gaussian|mixture} OPTCLINS" << std::endl;
-  Log::Warn << "[OPTCLINS]" << std::endl;
-  Log::Warn << "  --profile=file   : file contains HMM profile" << std::endl;
-  Log::Warn << "  --seqfile=file   : file contains input sequences" << std::endl;
-  Log::Warn << "  --statefile=file : output file for state sequences" << std::endl;
-}
-
-bool viterbi_mixture() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str(); //"seq.mix.out");
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str(); //"state.viterbi.mix.out");
-
-  MixtureofGaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::mat> seqs;
-  load_matrix_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_state;
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  for (size_t i = 0; i < seqs.size(); i++) {
-    arma::vec states;
-    char s[100];
-
-    hmm.ComputeViterbiStateSequence(seqs[i], states);
-
-    sprintf(s, "%% viterbi state sequence %zu", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-
-  return true;
-}
-
-bool viterbi_gaussian() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str(); //"seq.gauss.out");
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str(); //"state.viterbi.gauss.out");
-
-  GaussianHMM hmm;
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::mat> seqs;
-  load_matrix_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_state;
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  for (size_t i = 0; i < seqs.size(); i++) {
-    arma::vec states;
-    char s[100];
-    hmm.ComputeViterbiStateSequence(seqs[i], states);
-
-    sprintf(s, "%% viterbi state sequence %zu", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-
-  return true;
-}
-
-bool viterbi_discrete() {
-  if (!CLI::HasParam("hmm/profile")) {
-    Log::Fatal << "--profile must be defined." << std::endl;
-    return false;
-  }
-  const char* profile = CLI::GetParam<std::string>("hmm/profile").c_str();
-  const char* seqin = CLI::GetParam<std::string>("hmm/seqfile").c_str(); //"seq.out");
-  //const char* stateout = CLI::GetParam<std::string>("hmm/statefile").c_str(); //"state.viterbi.out");
-
-  DiscreteHMM hmm;
-
-  hmm.InitFromFile(profile);
-
-  std::vector<arma::vec> seqs;
-  load_vector_list(seqin, seqs);
-
-  /** need something better
-  TextWriter w_state;
-  if (!(w_state.Open(stateout))) {
-    Log::Warn << "Couldn't open '" << stateout << "' for writing." << std::endl;
-    return false;
-  }
-
-  for (size_t i = 0; i < seqs.size(); i++) {
-    arma::vec states;
-    char s[100];
-
-    hmm.ComputeViterbiStateSequence(seqs[i], states);
-
-    sprintf(s, "%% viterbi state sequence %zu", i);
-    print_vector(w_state, states, s, "%.0f,");
-  }
-  */
-
-  return true;
-}




More information about the mlpack-svn mailing list