1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2 /*
3  *  hmm.h
4  *
5  *  Created by Mark Levy on 12/02/2006.
6  *  Copyright 2006 Centre for Digital Music, Queen Mary, University of London.
7 
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13  *
14  */
15 
16 #ifndef QM_DSP_HMM_H
17 #define QM_DSP_HMM_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct _model_t {
24     int N;          /* number of states */
25     double* p0;     /* initial probs */
26     double** a;     /* transition probs */
27     int L;          /* dimensionality of data */
28     double** mu;    /* state means */
29     double** cov;   /* covariance, tied between all states */
30 } model_t;
31 
32 void hmm_train(double** x, int T, model_t* model); /* with scaling */
33 
34 void forward_backwards(double*** xi, double** gamma,
35                        double* loglik, double* loglik1, double* loglik2,
36                        int iter, int N, int T,
37                        double* p0, double** a, double** b);
38 
39 void baum_welch(double* p0, double** a, double** mu, double** cov,
40                 int N, int T, int L, double** x, double*** xi, double** gamma);
41 
42 void viterbi_decode(double** x, int T, model_t* model, int* q); /* using logs */
43 
44 model_t* hmm_init(double** x, int T, int L, int N);
45 void hmm_close(model_t* model);
46 
47 void invert(double** cov, int L, double** icov, double* detcov); /* uses LAPACK */
48 
49 double gauss(double* x, int L, double* mu, double** icov,
50              double detcov, double* y, double* z);
51 
52 double loggauss(double* x, int L, double* mu, double** icov,
53                 double detcov, double* y, double* z);
54 
55 void hmm_print(model_t* model);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif
62 
63