没有合适的资源?快使用搜索试试~ 我知道了~
隐马尔科夫算法(HMM)的Java实现
5星 · 超过95%的资源 需积分: 50 294 下载量 67 浏览量
2010-01-02
10:36:13
上传
评论 4
收藏 19KB TXT 举报
温馨提示
试读
20页
隐马尔科夫算法(HMM)的Java实现 隐马尔科夫算法(HMM)的Java实现
资源推荐
资源详情
资源评论
// Implementation of some algorithms for pairwise alignment from
// Durbin et al: Biological Sequence Analysis, CUP 1998, chapter 3.
// Peter Sestoft, sestoft@dina.kvl.dk (Oct 1999), 2001-08-20 version 0.7
// Reference: http://www.dina.kvl.dk/~sestoft/bsa.html
// License: Anybody can use this code for any purpose, including
// teaching, research, and commercial purposes, provided proper
// reference is made to its origin. Neither the author nor the Royal
// Veterinary and Agricultural University, Copenhagen, Denmark, can
// take any responsibility for the consequences of using this code.
// Compile with:
// javac Match3.java
// Run with:
// java Match3
// Notational conventions:
// i = 1,...,L indexes x, the observed string, x_0 not a symbol
// k,ell = 0,...,hmm.nstate-1 indexes hmm.state(k) a_0 is the start state
import java.text.*;
import java.util.*;
// Some algorithms for Hidden Markov Models (Chapter 3): Viterbi,
// Forward, Backward, Baum-Welch. We compute with log probabilities.
class HMM {
// State names and state-to-state transition probabilities
// Durbin et al: Biological Sequence Analysis, CUP 1998, chapter 3.
// Peter Sestoft, sestoft@dina.kvl.dk (Oct 1999), 2001-08-20 version 0.7
// Reference: http://www.dina.kvl.dk/~sestoft/bsa.html
// License: Anybody can use this code for any purpose, including
// teaching, research, and commercial purposes, provided proper
// reference is made to its origin. Neither the author nor the Royal
// Veterinary and Agricultural University, Copenhagen, Denmark, can
// take any responsibility for the consequences of using this code.
// Compile with:
// javac Match3.java
// Run with:
// java Match3
// Notational conventions:
// i = 1,...,L indexes x, the observed string, x_0 not a symbol
// k,ell = 0,...,hmm.nstate-1 indexes hmm.state(k) a_0 is the start state
import java.text.*;
import java.util.*;
// Some algorithms for Hidden Markov Models (Chapter 3): Viterbi,
// Forward, Backward, Baum-Welch. We compute with log probabilities.
class HMM {
// State names and state-to-state transition probabilities
int nstate; // number of states (incl initial state)
String[] state; // names of the states
double[][] loga; // loga[k][ell] = log(P(k -> ell))
// Emission names and emission probabilities
int nesym; // number of emission symbols
String esym; // the emission symbols e1,...,eL (characters)
double[][] loge; // loge[k][ei] = log(P(emit ei in state k))
// Input:
// state = array of state names (except initial state)
// amat = matrix of transition probabilities (except initial state)
// esym = string of emission names
// emat = matrix of emission probabilities
public HMM(String[] state, double[][] amat,
String esym, double[][] emat) {
if (state.length != amat.length)
throw new IllegalArgumentException("HMM: state and amat disagree");
if (amat.length != emat.length)
throw new IllegalArgumentException("HMM: amat and emat disagree");
for (int i=0; i<amat.length; i++) {
if (state.length != amat[i].length)
throw new IllegalArgumentException("HMM: amat non-square");
if (esym.length() != emat[i].length)
throw new IllegalArgumentException("HMM: esym and emat disagree");
}
// Set up the transition matrix
nstate = state.length + 1;
String[] state; // names of the states
double[][] loga; // loga[k][ell] = log(P(k -> ell))
// Emission names and emission probabilities
int nesym; // number of emission symbols
String esym; // the emission symbols e1,...,eL (characters)
double[][] loge; // loge[k][ei] = log(P(emit ei in state k))
// Input:
// state = array of state names (except initial state)
// amat = matrix of transition probabilities (except initial state)
// esym = string of emission names
// emat = matrix of emission probabilities
public HMM(String[] state, double[][] amat,
String esym, double[][] emat) {
if (state.length != amat.length)
throw new IllegalArgumentException("HMM: state and amat disagree");
if (amat.length != emat.length)
throw new IllegalArgumentException("HMM: amat and emat disagree");
for (int i=0; i<amat.length; i++) {
if (state.length != amat[i].length)
throw new IllegalArgumentException("HMM: amat non-square");
if (esym.length() != emat[i].length)
throw new IllegalArgumentException("HMM: esym and emat disagree");
}
// Set up the transition matrix
nstate = state.length + 1;
剩余19页未读,继续阅读
zhgh070
- 粉丝: 14
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页