⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hmmdrawer.java

📁 java实现的隐马尔科夫模型
💻 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.draw;import java.io.*;import java.text.*;import be.ac.ulg.montefiore.run.jahmm.*;/** * An HMM to <i>dot</i> file converter.  See * <url>http://www.research.att.com/sw/tools/graphviz/</url> * for more information on the .<i>dot</i> tool. */public class HmmDrawer {        double minimumAij = 0.01;    double minimumPi = 0.01;    NumberFormat probabilityFormat;    /**     * This class converts an HMM to a dot file.     */    public HmmDrawer() {	probabilityFormat = NumberFormat.getInstance();	probabilityFormat.setMaximumFractionDigits(2);    }        String convert(Hmm hmm) {	String s = beginning();		s += transitions(hmm);	s += states(hmm);		return s + ending();    }    String beginning() {	return "digraph G {\n";    }        String transitions(Hmm hmm) {	String s = "";		for (int i = 0; i < hmm.nbStates(); i++)	    for (int j = 0; j < hmm.nbStates(); j++)		if (hmm.getAij(i, j) >= minimumAij)		    s += "\t" + i + " -> " + j + " [label=" + 			probabilityFormat.format(hmm.getAij(i, j)) + "];\n";		return s;    }    String states(Hmm hmm) {	String s = "";	for (int i = 0; i < hmm.nbStates(); i++) {	    s += "\t" + i + " [";	    	    if (hmm.getPi(i) >= minimumPi) {		s += "shape=doublecircle, label=\"" + i +		    " - Pi= " + probabilityFormat.format(hmm.getPi(i)) + " - " +		    opdfLabel(hmm, i) + "\"";	    } else {		s += "shape=circle, label=\"" + i + " - " +		    opdfLabel(hmm, i) + "\"";	    }	    	    s += "];\n";	}		return s;    }    String opdfLabel(Hmm hmm, int stateNb) {	return "";    }        String ending() {	return "}\n";    }        /**     * Writes a dot file depicting the given HMM.     *     * @param hmm The HMM to depict.     * @param filename The resulting 'dot' file filename.     */    public void write(Hmm hmm, String filename) throws IOException {	FileWriter fw = new FileWriter(filename);	fw.write(convert(hmm));	fw.close();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -