HMM vertibe算法使用java实现

package RareProb_v2;



public class VertibeAlgorithm {

	int hiddenStateNum;
	int T;
	double[] pi;
	double[][] A;
	double[][] B;
	int[] ObserveSeq;
	double[][] deta;
	int[][] psi;
//	int ObserveSeqState;//这个用来表示观察序列中有几种情况,如值为0,1,2,3这三种值,目的是用在使用B的时候需要
//	ArrayList observation = new ArrayList(); // 观察到的集合
	
	VertibeAlgorithm(int hiddenStateNum,int ObserveSeqNum,int[] ObserveSeq,double[] pi,double[][] A,double[][] B /*,int[] ObserveSeqState*/)
	{
		this.hiddenStateNum = hiddenStateNum;
		this.T = ObserveSeqNum;
		this.ObserveSeq = ObserveSeq;
		this.pi = pi;
		this.A = A;
		this.B = B;
		deta = new double[T][hiddenStateNum];
		psi = new int [T][hiddenStateNum];
	}
	

	
	public void partialPr()
	{
		//t=0时的deta
		for(int i=0; i maxPr )
						maxPr = deta[t][i];
					
					if(( temp = deta[t-1][j]*A[j][i]) > maxj)
					{
						psi[t][i] = j;
						maxj = temp;
					}
				}
				deta[t][i] = maxPr;
				System.out.println("psi["+t+"]"+"["+i+"]="+psi[t][i]);
			}
		}
	}
	
	public void getSequence()
	{
		int[] backSeq = new int[T];
		backSeq[T-1] = 1;
		double max = 0;
		for(int i=0;i max)
			{
				max = deta[T-1][i];
				backSeq[T-1]=i;
			}
		
		for(int t=T-2;t>=0;t--)
		{
			backSeq[t] = psi[t+1][backSeq[t+1]];
		}
		System.out.println("sequece:");
		for(int t=0;t


转载请注明出处

你可能感兴趣的:(java,Java,JAVA,算法,HMM算法之vertibe算法)