[![Build Status](https://travis-ci.org/dwiel/tensorflow_hmm.svg?branch=master)](https://travis-ci.org/dwiel/tensorflow_hmm)
# tensorflow_hmm
Tensorflow and numpy implementations of the HMM viterbi and forward/backward algorithms.
See [Keras example](https://github.com/dwiel/tensorflow_hmm/blob/master/tensorflow_hmm/hmm_layer.py) for an example of how to use the Keras HMMLayer.
See test_hmm.py for usage examples. Here is an excerpt of the documentation from hmm.py for reference for now.
See also viterbi_wikipedia_example.py which replicates the viterbi example on wikipedia.
```
class HMM(object):
"""
A class for Hidden Markov Models.
The model attributes are:
- K :: the number of states
- P :: the K by K transition matrix (from state i to state j,
(i, j) in [1..K])
- p0 :: the initial distribution (defaults to starting in state 0)
"""
def __init__(self, P, p0=None):
class HMMTensorflow(HMM):
def forward_backward(self, y):
"""
runs forward backward algorithm on state probabilities y
Arguments
---------
y : np.array : shape (T, K) where T is number of timesteps and
K is the number of states
Returns
-------
(posterior, forward, backward)
posterior : list of length T of tensorflow graph nodes representing
the posterior probability of each state at each time step
forward : list of length T of tensorflow graph nodes representing
the forward probability of each state at each time step
backward : list of length T of tensorflow graph nodes representing
the backward probability of each state at each time step
"""
def viterbi_decode(self, y, nT):
"""
Runs viterbi decode on state probabilies y.
Arguments
---------
y : np.array : shape (T, K) where T is number of timesteps and
K is the number of states
nT : int : number of timesteps in y
Returns
-------
(s, pathScores)
s : list of length T of tensorflow ints : represents the most likely
state at each time step.
pathScores : list of length T of tensorflow tensor of length K
each value at (t, k) is the log likliehood score in state k at
time t. sum(pathScores[t, :]) will not necessary == 1
"""
```
tensorflow_hmm-0.2.1.tar.gz
需积分: 1 119 浏览量
2024-03-02
13:15:28
上传
评论
收藏 7KB GZ 举报
![avatar](https://profile-avatar.csdnimg.cn/ec7f5c9efb5b4604b3b8de71dbfb0088_calculusstill.jpg!1)
程序员Chino的日记
- 粉丝: 3057
- 资源: 5万+
最新资源
- 652027170733254多亿影视.apk
- 创新实践CNN车牌识别项目
- 小程序版图像分类算法对中文数字识别-不含数据集图片-含逐行注释和说明文档.zip
- 公交卡管理系统一个实验
- C语言学生成绩管理系统(信息可保存读取txt文件)
- 网上零食销售系统论文.docx
- 小程序版图像分类算法对电脑配件分类识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版深度学习CNN训练识别8种水果-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版基于深度学习对手势动作分类识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版深度学习CNN训练识别手写数字图像中的数字分类-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)