-
Notifications
You must be signed in to change notification settings - Fork 4
/
inference.h
107 lines (92 loc) · 5.32 KB
/
inference.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
liblrhsmm
===
Copyright (c) 2016-2017 Kanru Hua. All rights reserved.
This file is part of liblrhsmm.
liblrhsmm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
liblrhsmm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with liblrhsmm. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LRHSMM_INFERENCE_H
#define LRHSMM_INFERENCE_H
#include "data.h"
#include "model.h"
#include "mempool.h"
typedef struct {
float* p;
int lower, upper;
} lrh_pslice;
FP_TYPE lrh_gmm_mixprob_lg(lrh_gmm* src, FP_TYPE* observ, int k);
double lrh_gmm_mixprob(lrh_gmm* src, FP_TYPE* observ, int k);
FP_TYPE lrh_gmm_outputprob_lg(lrh_gmm* src, FP_TYPE* observ);
double lrh_gmm_outputprob(lrh_gmm* src, FP_TYPE* observ);
FP_TYPE lrh_duration_prob_lg(lrh_duration* src, int duration);
double lrh_duration_prob(lrh_duration* src, FP_TYPE duration);
FP_TYPE* lrh_sample_outputprob_lg(lrh_model* model, lrh_observ* observ, lrh_seg* seg);
FP_TYPE* lrh_sample_outputprob_lg_full(lrh_model* model, lrh_observ* observ, lrh_seg* seg);
FP_TYPE* lrh_sample_outputprob(lrh_model* model, lrh_observ* observ, lrh_seg* seg);
/*
ae: forward termination probability p(s'_t = i, o_1, ..., o_t)
ab: forward initiation probability p(s*_t = i, o_1, ..., o_t)
be: backward termination probability p(o_{t+1}, ..., o_T | s'_t = i)
bb: backward initiation probability p(o_{t+1}, ..., o_T | s*_t = i)
lrh_forward returns ae by default; ab is optional (to be allocated, which can be NULL)
lrh_backward returns be by default; bb is optional (to be allocated, which can be NULL)
lrh_viterbi returns an interleaving state/time sequence and optionally allocates and writes
forward termination probability (MAP) to argument ae.
Format of returned sequence: [t0, s0, t1, s1, t2, s2, ..., -1, -1]
where s0, s1, ... are the indices of states in the input sequence.
In most cases ae/be instead of ab/bb are used for the following computation.
lrh_viterbi_geometric, lrh_forward_geometric and lrh_backward_geometric do not support
jump transitions yet.
lrh_viterbi_geometric returns a time sequence.
*/
FP_TYPE* lrh_forward(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt, FP_TYPE** ab);
FP_TYPE* lrh_forward_geometric(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt);
int* lrh_viterbi(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt, FP_TYPE** ae);
int* lrh_viterbi_geometric(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt, FP_TYPE** a);
FP_TYPE* lrh_backward(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt, FP_TYPE** bb);
FP_TYPE* lrh_backward_geometric(lrh_model* model, lrh_seg* seg, FP_TYPE* output_lg, int nt);
/*
lrh_total: compute total probability from both forward and backward probabilities (HSMM)
lrh_total_backward_b: compute total probability from backward termination probability (HSMM)
lrh_total_pseudo: compute total probability from foward probability (HMM)
lrh_total_pseudo_backward: compute total probability from backward probability (HMM)
TL;DR: always use either lrh_total_backward_b or lrh_total evaluated at the first state to
compute total probability.
---
lrh_total_foward/lrh_total_forward_b/lrh_total_backward are not implemented because the
definition of observation probability after the end of the sequence is not clear.
For HSMMs, lrh_total_backward_b always gives accurate results.
lrh_total gives accurate results when evaluated at the first state. However the assumption
behind the total probability equation is violated when there are skipped states, giving
wrong results after the first state. This is what the equation does. It's not a bug.
*/
FP_TYPE lrh_total(FP_TYPE* a_, FP_TYPE* b_, int nt, int nseg, int i);
FP_TYPE lrh_total_backward_b(FP_TYPE* b_, FP_TYPE* output_lg, int nseg);
FP_TYPE lrh_total_pseudo(FP_TYPE* a_, int nt, int nseg);
FP_TYPE lrh_total_pseudo_backward(FP_TYPE* b_, FP_TYPE* output_lg, int nseg);
/*
lrh_durocp: compute consecutive state occupancy probability from ae and be probabilities (HSMM)
lrh_stocp: compute single state occupancy probability from durocp (HSMM)
lrh_mixocp: compute mixture occupancy probability from stocp (HSMM)
*/
lrh_pslice* lrh_durocp(lrh_model* model, lrh_seg* seg, FP_TYPE* ae, FP_TYPE* be,
FP_TYPE* output_lg, FP_TYPE total, int nt, lrh_mempool* pool);
lrh_pslice* lrh_sttran_geometric(lrh_model* model, lrh_seg* seg, FP_TYPE* a, FP_TYPE* b,
FP_TYPE* output_lg, FP_TYPE total, int nt, lrh_mempool* pool);
FP_TYPE* lrh_stocp(lrh_model* model, lrh_seg* seg, lrh_pslice* durocp, int nt);
lrh_pslice* lrh_mixocp(lrh_model* model, lrh_observ* observ, lrh_seg* seg,
FP_TYPE* stocp, int stream, lrh_mempool* pool);
FP_TYPE* lrh_stocp_geometric(lrh_model* model, lrh_seg* seg, FP_TYPE* a, FP_TYPE* b,
FP_TYPE total, int nt);
lrh_pslice* lrh_mixocp_geometric(lrh_model* model, lrh_observ* observ, lrh_seg* seg,
FP_TYPE* stocp, int stream, lrh_mempool* pool);
#endif