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

📄 forward_std.java

📁 马尔科夫模型的c语言实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.util.*;import java.io.*;class Forward_std extends Module{    /* initial transition distributions (uniform is default) */    final int U = 12; /* Uniform */    final int PO = 13; /* Poisson, largest length gets the probs for the larger numbers as well */    final int BI = 14; /* Binomial */    String name;    LinkedList theVertices;    int nrVertices;    int vertexType;    int distribType;    int distribType_2;    int distribType_3;    int distribType_4;    int intervalStart;    int intervalEnd;    Vertex inVertex;    Vertex outVertex;    String label;    int size;    int transDistribType;    String priorfile;    String priorfile_2;    String priorfile_3;    String priorfile_4;    String transPriorfile;    double m_Po;    /*  */    public Forward_std(String name, int distribType, int vertexType, int intervalStart, int intervalEnd, String label)    {	this.name = name;	this.vertexType = vertexType;	this.distribType = distribType;	this.distribType_2 = distribType;	this.distribType_3 = distribType;	this.distribType_4 = distribType;	this.intervalStart = intervalStart;	this.intervalEnd = intervalEnd;	this.label = label;	theVertices = new LinkedList();	nrVertices = intervalEnd;	inVertices = new int[1];	outVertices = new int[1];	priorfile = null;	priorfile_2 = null;	priorfile_3 = null;	priorfile_4 = null;	transPriorfile = null;	transDistribType = U;		/* create the vertices */	Vertex v = new Vertex(name, vertexType, distribType, label);	inVertex = v;	theVertices.add(v);	inVertices[0] = v.getNumber();	Vertex last = null;	for(int i = 1; i < nrVertices; i++) {	    Vertex w = new Vertex(name, vertexType, v.getEmissionProbs(), label);	    theVertices.add(w);	    if(i == nrVertices - 1) {		outVertices[0] = w.getNumber();		outVertex = w;		last = w;	    }	}		/* add transitions between the vertices so that all paths through the model	 * are equally probable, uniform distribution in decider state */	int v_nr = 1;	Vertex cur = null;	Vertex next = null;	ListIterator i = theVertices.listIterator();	if(i.hasNext()) {	    cur = (Vertex)i.next();	}	while(i.hasNext()) {	    next = (Vertex)i.next();	    if(v_nr < intervalStart-1) {		/* add transition to next vertex */		if(!cur.addTransition(next.getNumber())) {		    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");		}	    }	    else if(v_nr == intervalStart - 1) {		if(transDistribType == U) {		    /* add transition to all vertices from next to last vertex + set initial trans probs*/		    int nrTrans = intervalEnd - v_nr;		    for(int l = next.getNumber(); l <= last.getNumber(); l++) {			if(!cur.addTransition(l,1.0/((double)nrTrans), true)) {			    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");			} 		    }		}	    }	    else {		/* add transition to next vertex */		if(!cur.addTransition(next.getNumber())) {		    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");		}	    }	    v_nr++;	    cur = next;	}	size = theVertices.size();    }    public Forward_std(String name, double[] initDistrib, int vertexType, int intervalStart, int intervalEnd, String label)    {	this.name = name;	this.vertexType = vertexType;	this.distribType = HMM.MANUAL;	this.distribType_2 = HMM.MANUAL;	this.distribType_3 = HMM.MANUAL;	this.distribType_4 = HMM.MANUAL;	this.intervalStart = intervalStart;	this.intervalEnd = intervalEnd;	this.label = label;	theVertices = new LinkedList();	nrVertices = intervalEnd;	inVertices = new int[nrVertices];	priorfile = null;	priorfile_2 = null;	priorfile_3 = null;	priorfile_4 = null;	transPriorfile = null;	transDistribType = U;		/* create the vertices */	Vertex v = new Vertex(name, vertexType, initDistrib, label);	inVertex = v;	theVertices.add(v);	inVertices[0] = v.getNumber();	Vertex last = null;	for(int i = 1; i < nrVertices; i++) {	    Vertex w = new Vertex(name, vertexType, v.getEmissionProbs(), label);	    theVertices.add(w);	    if(i == nrVertices - 1) {		outVertices[0] = w.getNumber();		outVertex = w;		last = w;	    }	}	/* add transitions between the vertices according to set distribution */	int v_nr = 1;	Vertex cur = null;	Vertex next = null;	ListIterator i = theVertices.listIterator();	if(i.hasNext()) {	    cur = (Vertex)i.next();	}	while(i.hasNext()) {	    next = (Vertex)i.next();	    if(v_nr < intervalStart-1) {		/* add transition to next vertex */		if(!cur.addTransition(next.getNumber())) {		    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");		}	    }	    else if(v_nr == intervalStart - 1) {		if(transDistribType == U) {		    /* add transition to all vertices from next to last vertex + set initial trans probs*/		    int nrTrans = intervalEnd - v_nr;		    for(int l = next.getNumber(); l <= last.getNumber(); l++) {			if(!cur.addTransition(l,1.0/((double)nrTrans), true)) {			    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");			} 		    }		}	    }	    else {		/* add transition to next vertex */		if(!cur.addTransition(next.getNumber())) {		    P.INTERNAL_ERROR("Forward_std.construct: Could not add intraconnections");		}	    }	    v_nr++;	    cur = next;	}	size = theVertices.size();    }    public int getSize()    {	return size;    }        public String getName()    {	return name;    }        public String getLabel()    {	return label;    }    public int getVertexType()    {	return vertexType;    }        public int getDistribType()    {	return distribType;    }    public String getPriorfile()    {	return priorfile;    }    public Vertex getVertex(int nr)    {	for(int i = 0; i < theVertices.size(); i++) {	    Vertex v = ((Vertex)theVertices.get(i));	    if(v.getNumber() == nr) {		return v;	    }	}	return null;    }    public double[] getEmissionProbs()    {	Vertex v = (Vertex)theVertices.get(0);	return v.getEmissionProbs();    }    public int[] getInVertices()    {	return inVertices;    }    public LinkedList getVertices()    {	return theVertices;    }    public int getNrOfTransitions()    {	int nrTransitions = 0;	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    nrTransitions = nrTransitions + v.getNrOfTransitions();	    nrTransitions = nrTransitions + v.getNrOfEndTransitions();	}	return nrTransitions;    }    public int getNrOfRegularTransitions()    {	int nrTransitions = 0;	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    nrTransitions = nrTransitions + v.getNrOfTransitions();	}	return nrTransitions;    }        public int getNrOfEndTransitions()    {	int nrTransitions = 0;	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    nrTransitions = nrTransitions + v.getNrOfEndTransitions();	}	return nrTransitions;    }    public int[] getOutVertices()    {	return outVertices;    }        public void addVerticesToVertexHash(Hashtable theVerticesHash)    {	for(int i = 0; i < nrVertices; i++) {	    Vertex v = ((Vertex)theVertices.get(i));	    theVerticesHash.put(new Integer(v.getNumber()), v);	}    }    /* adds transition from specified vertex to specified vertex */    public boolean addTransition(int fromVertex, int toVertex)    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    if(v.getNumber() == fromVertex) {		return v.addTransition(toVertex);	    }	}		/* could not find the vertex */	P.INTERNAL_ERROR("Forward_std.addTransition: vertex not in module");	return false;    }        public void setTransPriorScaler(double d)    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    v.setTransPriorScaler(d);	}    }    public void setEmissPriorScaler(double d)    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    v.setEmissPriorScaler(d);	}    }    public void setEmissPriorScaler(int nr, double d)    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    v.setEmissPriorScaler(nr, d);	}    }    public void lockVertexEmissions()    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    v.lock();	}    }    /* adds transitions from all out vertices to specified vertex */    public boolean addTransition(int toVertex)    {	boolean res = true;	if(!outVertex.addTransition(toVertex)) {	    res = false;	}	return res;    }        /* adds end transitions from all out vertices to specified vertex */    public boolean addEndTransition(int toVertex)    {	boolean res = true;	if(!outVertex.addEndTransition(toVertex)) {	    res = false;	}	return res;    }    public void initializeTransitionProbabilities()    {	for(ListIterator i = (ListIterator)theVertices.iterator(); i.hasNext();) {	    Vertex v = (Vertex)i.next();	    v.initializeTransitionProbabilities();	}    }    public void setDistribType(int distribType, double[] distribution)    {	this.distribType = distribType;	for(ListIterator i = (ListIterator)theVertices.iterator();i.hasNext();) {	    Vertex v = (Vertex)i.next();

⌨️ 快捷键说明

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