abstractinferencer.java

来自「这是一个matlab的java实现。里面有许多内容。请大家慢慢捉摸。」· Java 代码 · 共 97 行

JAVA
97
字号
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).   http://www.cs.umass.edu/~mccallum/mallet   This software is provided under the terms of the Common Public License,   version 1.0, as published by http://www.opensource.org.  For further   information, see the file `LICENSE' included with this distribution. */package edu.umass.cs.mallet.grmm;/** * Abstract base class for inferencers.  This simply throws *  an UnsupportedOperationException for all methods, which *  is useful for subclasses that want to implement only *  specific inference functionality. * * Created: Mon Oct  6 17:01:21 2003 * * @author <a href="mailto:casutton@cs.umass.edu">Charles Sutton</a> * @version $Id: AbstractInferencer.java,v 1.2 2004/07/22 00:37:38 casutton Exp $ */abstract public class AbstractInferencer implements Inferencer, Cloneable {// Implementation of edu.umass.cs.mallet.grmm.graphical.Inferencer	public void computeMarginals(DirectedModel undirectedModel) {		throw new UnsupportedOperationException 			(this.getClass().getName()+" doesn't support undirected models.");					}	public void computeMarginals(UndirectedModel undirectedModel) {		throw new UnsupportedOperationException 			(this.getClass().getName()+" doesn't support undirected models.");					}	public void computeMarginals(JunctionTree junctionTree) {		throw new UnsupportedOperationException 			(this.getClass().getName()+" doesn't support junction trees.");					}	public double lookupJoint (Assignment assn)	{		return Math.exp (lookupLogJoint (assn));	}	public double lookupLogJoint (Assignment assn)	{		throw new UnsupportedOperationException 			(this.getClass().getName()+" doesn't compute joint probabilities.");	}	public DiscretePotential lookupMarginal (Clique c)	{		throw new UnsupportedOperationException 			(this.getClass().getName()+" doesn't compute marginals of arbitrary cliques.");	}	// xxx Should be generalized to GraphicalModel	public double query (UndirectedModel mdl, Assignment assn)	{		// Computes joint of assignment using chain rule		UndirectedModel mdl2 = mdl.duplicate();		double marginal = 1.0;		for (int i = 0; i < assn.size(); i++) {			Variable var = assn.getVariable (i);			computeMarginals (mdl2);			DiscretePotential ptl = lookupMarginal (var);			marginal *= ptl.phi (assn);			mdl2.setObserved (var, assn.get (var));		}		return marginal;	}	public double query (DirectedModel mdl, Assignment assn)	{		throw new UnsupportedOperationException 			(this.getClass().getName()+" can't query assignments.");	}	public double query (JunctionTree mdl, Assignment assn)	{		throw new UnsupportedOperationException 			(this.getClass().getName()+" can't query assignments.");	}	abstract public DiscretePotential lookupMarginal(Variable variable);	public Inferencer duplicate () {		try {			return (Inferencer) clone();		} catch (CloneNotSupportedException e) {			throw new RuntimeException (e);		}	}	} // AbstractInferencer

⌨️ 快捷键说明

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