📄 bruteforceinferencer.java
字号:
/* 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;import salvo.jesus.graph.Vertex;import salvo.jesus.graph.Graph;import salvo.jesus.graph.Vertex;import java.util.Iterator;/** * Computes the joint of a GraphicalModel by brute-force * calculation. This is exponentially slow, so it is mostly * useful as a sanity check on more complicated algorithms. * * Created: Wed Sep 17 13:21:13 2003 * * @author <a href="mailto:casutton@cs.umass.edu">Charles Sutton</a> * @version $Id: BruteForceInferencer.java,v 1.1 2004/07/15 17:53:31 casutton Exp $ */public class BruteForceInferencer extends AbstractInferencer implements Inferencer { DiscretePotential cachedJoint; public DiscretePotential joint (UndirectedModel model) { DiscretePotential joint = MultinomialPotential.multiplyAll (model.potentials()); joint.normalize(); return joint; } public DiscretePotential joint (JunctionTree jt) { MultinomialPotential joint = MultinomialPotential.multiplyAll (jt.potentials ()); for (Iterator it = jt.sepsetPotentials().iterator(); it.hasNext();) { MultinomialPotential pot = (MultinomialPotential) it.next(); joint.divideBy (pot); } joint.normalize(); return joint; } public void computeMarginals (UndirectedModel mdl) { cachedJoint = joint (mdl); } public void computeMarginals (JunctionTree jt) { cachedJoint = joint (jt); } public DiscretePotential lookupMarginal (Variable var) { return cachedJoint.marginalize (var); } public DiscretePotential lookupMarginal (Clique c) { return cachedJoint.marginalize (c); } public double lookupJoint (Assignment assn) { return cachedJoint.phi (assn); } public double lookupLogJoint (Assignment assn) { return Math.log (cachedJoint.phi (assn)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -