ghmmのソースコードリーディング

まだ, 編集中

Pythonから呼ぶときにエラーメッセージが出るため, その原因を解明するためちょっとだけghmmのソースコードを読むことにした. 下はあいまいに読んだものなので間違っていても許してください.

なお, ソースコードを読む際にBaumWelchの更新式が手元に欲しかったため, よくお世話になるこのページを参考にした.


まず, 出るのは次のエラーメッセージ
NO sequence can be build from smodel smo!

エラーメッセージを出力する関数は2つある.

ighmm_mes (MES_WIN, " THIS IS DEBUG!\n");
GHMM_LOG_PRINTF(LCONVERTED, LOC, "GYAOOOOOOOOOOOOOOOOOOOON!!!!!!!!!!!");

前者はメッセージキューにメッセージを足す関数で, 後者はメッセージキューにメッセージを足して, そのキューの内容を出力する関数である.
デバッグメッセージを埋め込みたい場合は, 基本的に後者を用いればよい(行番号でるし).

観測列が連続値のHMMはghmm_cmodelという構造体で表され, smodel.hの175行目から始まる.

  typedef struct ghmm_cmodel {
  /** Number of states */
    int N;
  /** Maximun number of components in the states */
    int M;
  /** Number of dimensions of the emission components.
      All emissions must have the same number of dimensions */
    int dim;
  /** ghmm_cmodel includes continuous model with one transition matrix 
      (cos  is set to 1) and an extension for models with several matrices
      (cos is set to a positive integer value > 1).*/
    int cos;
  /** prior for a priori prob. of the model. -1 means no prior specified (all
      models have equal prob. a priori. */
    double prior;

  /* contains a arbitrary name for the model (null terminated utf-8) */
  char *name;

  /** Contains bit flags for varios model extensions such as
      kSilentStates (see ghmm.h for a complete list)
  */
  int model_type;

  /** All states of the model. Transition probs are part of the states. */
    ghmm_cstate *s;

    /* pointer to a ghmm_cmodel_class_change_context struct necessary for multiple transition
       classes */
    ghmm_cmodel_class_change_context *class_change;

  } ghmm_cmodel;
  typedef struct ghmm_cstate {
  /** Number of output densities per state */
    int M;
  /** initial prob. */
    double pi;
  /** IDs of successor states */
    int *out_id;
  /** IDs of predecessor states */
    int *in_id;
  /** transition probs to successor states. It is a
   matrix in case of mult. transition matrices (COS > 1)*/
    double **out_a;
  /** transition probs from predecessor states. It is a
   matrix in case of mult. transition matrices (COS > 1) */
    double **in_a;
  /** number of  successor states */
    int out_states;
  /** number of  predecessor states */
    int in_states;
  /** weight vector for output function components */
    double *c;
  /** flag for fixation of parameter. If fix = 1 do not change parameters of
      output functions, if fix = 0 do normal training. Default is 0. */
    int fix;
  /** vector of ghmm_c_emission
      (type and parameters of output function components) */
    ghmm_c_emission *e;
  /** contains a description of the state (null terminated utf-8)*/
  char *desc;
  /** x coordinate position for graph representation plotting **/
  int xPosition;
  /** y coordinate position for graph representation plotting **/
  int yPosition;
  } ghmm_cstate;