Classes | Macros | Typedefs | Functions
hmm.h File Reference

HMM data structure and operation. More...

#include <stdio.h>
#include "s3types.h"

Go to the source code of this file.

Classes

struct  hmm_context_s
 
struct  hmm_state_t
 A single state in the HMM. More...
 
struct  hmm_s
 

Macros

#define MAX_HMM_NSTATE   5
 
#define hmm_context(h)   ((hmm_t *)(h))->ctx
 
#define hmm_is_mpx(h)   ((hmm_t *)(h))->mpx
 
#define hmm_state(h, st)   ((hmm_t *)(h))->state[st]
 
#define hmm_in_score(h)   hmm_state(h,0).score
 
#define hmm_score(h, st)   hmm_state(h,st).score
 
#define hmm_out_score(h)   ((hmm_t *)(h))->out.score
 
#define hmm_in_history(h)   hmm_state(h,0).history.id
 
#define hmm_history(h, st)   hmm_state(h,st).history.id
 
#define hmm_out_history(h)   ((hmm_t *)(h))->out.history.id
 
#define hmm_in_histobj(h)   hmm_state(h,0).history.ptr
 
#define hmm_histobj(h, st)   hmm_state(h,st).history.ptr
 
#define hmm_out_histobj(h)   ((hmm_t *)(h))->out.history.ptr
 
#define hmm_bestscore(h)   ((hmm_t *)(h))->bestscore
 
#define hmm_frame(h)   ((hmm_t *)(h))->frame
 
#define hmm_mpx_ssid(h, st)   ((hmm_t *)(h))->s.mpx_ssid[st]
 
#define hmm_nonmpx_ssid(h)   ((hmm_t *)(h))->s.ssid
 
#define hmm_ssid(h, st)
 
#define hmm_senid(h, st)
 
#define hmm_senscr(h, st)
 
#define hmm_tmatid(h)   ((hmm_t *)(h))->tmatid
 
#define hmm_tprob(h, i, j)   ((hmm_t *)(h))->ctx->tp[hmm_tmatid(h)][i][j]
 
#define hmm_n_emit_state(h)   (((hmm_t *)(h))->n_emit_state)
 
#define hmm_n_state(h)   (((hmm_t *)(h))->n_emit_state + 1)
 
#define hmm_context_set_senscore(ctx, senscr)   ((ctx)->senscore = (senscr))
 

Typedefs

typedef struct hmm_context_s hmm_context_t
 
typedef struct hmm_s hmm_t
 

Functions

hmm_context_thmm_context_init (int32 n_emit_state, int32 ***tp, int32 *senscore, s3senid_t **sseq)
 
void hmm_context_free (hmm_context_t *ctx)
 
void hmm_init (hmm_context_t *ctx, hmm_t *hmm, int mpx, int32 ssid, s3tmatid_t tmatid)
 
void hmm_deinit (hmm_t *hmm)
 
void hmm_clear (hmm_t *h)
 
void hmm_clear_scores (hmm_t *h)
 
void hmm_normalize (hmm_t *h, int32 bestscr)
 
void hmm_enter (hmm_t *h, int32 score, int32 histid, int32 frame)
 
void hmm_enter_obj (hmm_t *h, int32 score, void *histobj, int32 frame)
 
int32 hmm_vit_eval (hmm_t *hmm)
 
int32 hmm_dump_vit_eval (hmm_t *hmm, FILE *fp)
 
void hmm_dump (hmm_t *h, FILE *fp)
 

Detailed Description

HMM data structure and operation.

For efficiency, this version is hardwired for two possible HMM topologies, but will fall back to others:

5-state left-to-right HMMs: (0 is the emitting entry state and E is a non-emitting exit state; the x's indicate allowed transitions between source and destination states):

          0   1   2   3   4   E (destination-states)
      0   x   x   x
      1       x   x   x
      2           x   x   x
      3               x   x   x
      4                   x   x

(source-states) 5-state topologies that contain a subset of the above transitions should work as well.

3-state left-to-right HMMs (similar notation as the 5-state topology above):

          0   1   2   E (destination-states)
      0   x   x   x
      1       x   x   x
      2           x   x 

(source-states) 3-state topologies that contain a subset of the above transitions should work as well.

Macro Definition Documentation

◆ hmm_bestscore

#define hmm_bestscore (   h)    ((hmm_t *)(h))->bestscore

◆ hmm_context

#define hmm_context (   h)    ((hmm_t *)(h))->ctx

Access macros.

◆ hmm_context_set_senscore

#define hmm_context_set_senscore (   ctx,
  senscr 
)    ((ctx)->senscore = (senscr))

Change the senone score array for a context.

◆ hmm_frame

#define hmm_frame (   h)    ((hmm_t *)(h))->frame

◆ hmm_histobj

#define hmm_histobj (   h,
  st 
)    hmm_state(h,st).history.ptr

◆ hmm_history

#define hmm_history (   h,
  st 
)    hmm_state(h,st).history.id

◆ hmm_in_histobj

#define hmm_in_histobj (   h)    hmm_state(h,0).history.ptr

◆ hmm_in_history

#define hmm_in_history (   h)    hmm_state(h,0).history.id

◆ hmm_in_score

#define hmm_in_score (   h)    hmm_state(h,0).score

◆ hmm_is_mpx

#define hmm_is_mpx (   h)    ((hmm_t *)(h))->mpx

◆ hmm_mpx_ssid

#define hmm_mpx_ssid (   h,
  st 
)    ((hmm_t *)(h))->s.mpx_ssid[st]

◆ hmm_n_emit_state

#define hmm_n_emit_state (   h)    (((hmm_t *)(h))->n_emit_state)

◆ hmm_n_state

#define hmm_n_state (   h)    (((hmm_t *)(h))->n_emit_state + 1)

◆ hmm_nonmpx_ssid

#define hmm_nonmpx_ssid (   h)    ((hmm_t *)(h))->s.ssid

◆ hmm_out_histobj

#define hmm_out_histobj (   h)    ((hmm_t *)(h))->out.history.ptr

◆ hmm_out_history

#define hmm_out_history (   h)    ((hmm_t *)(h))->out.history.id

◆ hmm_out_score

#define hmm_out_score (   h)    ((hmm_t *)(h))->out.score

◆ hmm_score

#define hmm_score (   h,
  st 
)    hmm_state(h,st).score

◆ hmm_senid

#define hmm_senid (   h,
  st 
)
Value:
(hmm_ssid(h,st) == -1 \
? -1 : ((hmm_t *)(h))->ctx->sseq[hmm_ssid(h,st)][st])
An individual HMM among the HMM search space.
#define hmm_ssid(h, st)
Definition: hmm.h:220

◆ hmm_senscr

#define hmm_senscr (   h,
  st 
)
Value:
(hmm_ssid(h,st) == -1 \
: ((hmm_t *)(h))->ctx->senscore[hmm_senid(h,st)])
An individual HMM among the HMM search space.
#define S3_LOGPROB_ZERO
Definition: s3types.h:191
#define hmm_ssid(h, st)
Definition: hmm.h:220
#define hmm_senid(h, st)
Definition: hmm.h:222

◆ hmm_ssid

#define hmm_ssid (   h,
  st 
)
Value:
(hmm_is_mpx((hmm_t *)(h)) \
? hmm_mpx_ssid(h,st) : ((hmm_t *)(h))->s.ssid)
#define hmm_mpx_ssid(h, st)
Definition: hmm.h:218
#define hmm_is_mpx(h)
Definition: hmm.h:201
An individual HMM among the HMM search space.

◆ hmm_state

#define hmm_state (   h,
  st 
)    ((hmm_t *)(h))->state[st]

◆ hmm_tmatid

#define hmm_tmatid (   h)    ((hmm_t *)(h))->tmatid

◆ hmm_tprob

#define hmm_tprob (   h,
  i,
 
)    ((hmm_t *)(h))->ctx->tp[hmm_tmatid(h)][i][j]

◆ MAX_HMM_NSTATE

#define MAX_HMM_NSTATE   5

Hardcoded limit on the number of states (temporary)

Typedef Documentation

◆ hmm_context_t

typedef struct hmm_context_s hmm_context_t

◆ hmm_t

typedef struct hmm_s hmm_t

Function Documentation

◆ hmm_clear()

void hmm_clear ( hmm_t h)

Reset the states of the HMM to the invalid condition; i.e., scores to WORST_SCORE and hist to undefined.

◆ hmm_clear_scores()

void hmm_clear_scores ( hmm_t h)

Reset the scores of the HMM.

◆ hmm_context_free()

void hmm_context_free ( hmm_context_t ctx)

Free an HMM context.

Note
The transition matrices, senone scores, and senone sequence mapping are all assumed to be allocated externally, and will NOT be freed by this function.

◆ hmm_context_init()

hmm_context_t* hmm_context_init ( int32  n_emit_state,
int32 ***  tp,
int32 *  senscore,
s3senid_t **  sseq 
)

Create an HMM context.

◆ hmm_deinit()

void hmm_deinit ( hmm_t hmm)

Free an HMM structure, releasing internal data (but not the HMM structure itself).

◆ hmm_dump()

void hmm_dump ( hmm_t h,
FILE *  fp 
)

For debugging, dump the whole HMM out.

Parameters
hIn/Out: HMM being updated
fpAn output file pointer

◆ hmm_dump_vit_eval()

int32 hmm_dump_vit_eval ( hmm_t hmm,
FILE *  fp 
)

Like hmm_vit_eval, but dump HMM state and relevant senscr to fp first, for debugging;.

Parameters
hmmIn/Out: HMM being updated
fpAn output file pointer

◆ hmm_enter()

void hmm_enter ( hmm_t h,
int32  score,
int32  histid,
int32  frame 
)

Enter an HMM with the given path score and history ID.

◆ hmm_enter_obj()

void hmm_enter_obj ( hmm_t h,
int32  score,
void *  histobj,
int32  frame 
)

Enter an HMM with the given path score and history object.

◆ hmm_init()

void hmm_init ( hmm_context_t ctx,
hmm_t hmm,
int  mpx,
int32  ssid,
s3tmatid_t  tmatid 
)

Populate a previously-allocated HMM structure, allocating internal data.

◆ hmm_normalize()

void hmm_normalize ( hmm_t h,
int32  bestscr 
)

Renormalize the scores in this HMM based on the given best score.

◆ hmm_vit_eval()

int32 hmm_vit_eval ( hmm_t hmm)

Viterbi evaluation of given HMM. (NOTE that if this module were being used for tracking state segmentations, the dummy, non-emitting exit state would have to be updated separately. In the Viterbi DP diagram, transitions to the exit state occur from the current time; they are vertical transitions. Hence they should be made only after the history has been logged for the emitting states. But we're not bothered with state segmentations, for now. So, we update the exit state as well.)