📄 baumwelchscaledlearner.java
字号:
/* jahmm package - v0.3.1 *//* * Copyright (c) 2004, Jean-Marc Francois. * * This file is part of Jahmm. * Jahmm 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 2 of the License, or * (at your option) any later version. * * Jahmm 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 Jahmm; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package be.ac.ulg.montefiore.run.jahmm.learn;import java.util.*;import be.ac.ulg.montefiore.run.jahmm.*;/** * An implementation of the Baum-Welch learning algorithm. It uses a * scaling mecanism so as to avoid underflows. * <p> * For more information on the scaling procedure, read <i>Rabiner</i> and * <i>Juang</i>'s <i>Fundamentals of speech recognition</i> (Prentice Hall, * 1993). */public class BaumWelchScaledLearner extends BaumWelchLearner { /** * Initializes a Baum-Welch algorithm implementation. This algorithm * finds a HMM that models a set of observation sequences. * * @param nbStates The number of states the resulting HMM will be made of. * @param opdfFactory A class that builds the observation probability * distributions associated to the states of the HMM. * @param obsSeqs A vector of observation sequences. Each observation * sequences is a vector of * {@link be.ac.ulg.montefiore.run.jahmm.Observation * observations}. */ public BaumWelchScaledLearner(int nbStates, OpdfFactory opdfFactory, Vector obsSeqs) { super(nbStates, opdfFactory, obsSeqs); } ForwardBackwardCalculator generateForwardBackwardCalculator(Vector obsSeq, Hmm hmm) { return new ForwardBackwardScaledCalculator(obsSeq, hmm, ForwardBackwardCalculator. COMPUTE_ALPHA | ForwardBackwardCalculator. COMPUTE_BETA); } /* Here, the xi (and, thus, gamma) values are not divided by the probability of the sequence because this probability might be too small and induce an underflow. xi[t][i][j] still can be interpreted as P[q_t = i and q_(t+1) = j | obsSeq, hmm] because we assume that the scaling factors are such that their product is equal to the inverse of the probability of the sequence. */ double[][][] estimation_xi(Vector obsSeq, ForwardBackwardCalculator fbc, Hmm hmm) { double xi[][][] = new double[obsSeq.size() - 1][hmm.nbStates()][hmm.nbStates()]; for (int t = 0; t < obsSeq.size() - 1; t++) for (int i = 0; i < hmm.nbStates(); i++) for (int j = 0; j < hmm.nbStates(); j++) xi[t][i][j] = fbc.alphaElement(t, i) * hmm.getAij(i, j) * hmm.getOpdf(j).probability((Observation) obsSeq.elementAt(t + 1)) * fbc.betaElement(t + 1, j); return xi; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -