📄 discretepotential.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; // Generated package nameimport edu.umass.cs.mallet.base.types.Alphabet;import salvo.jesus.graph.Vertex;import java.util.Random;import java.util.HashMap;import java.util.Set;import java.util.Collection;import java.util.Iterator;/** * Interface for multivariate discrete probability distributions. * All distributions are assumed to be over * 0...k. If you want a distribution over some * other discrete set, use the @see getAlphabet * and @see setAlphabet members. * * @note I thought about having a single Potential interface, * for both continuous and discrete, but then all the method * parameters were java.lang.Object, and the lack of type * safety was both inefficient and disturbing. * * Created: Mon Sep 15 14:04:58 2003 * * @author <a href="mailto:casutton@cs.umass.edu">Charles Sutton</a> * @version $Id: DiscretePotential.java,v 1.1 2004/07/15 17:53:31 casutton Exp $ */public interface DiscretePotential extends Cloneable { /** * Returns the probability of an assignment to these variables. * All variables in the potential must be included, but it's * okay if the assignment uses variables not in the potential. */ public double phi (Assignment assn); /** * Returns the probability of an assignment to these variables. * The assignment used is the curret assignment from the given * AssignmentIterator. * <p> * This can be used to do things like * <pre> DiscretePotential phi = createMyPtl (); for (AssignmentIterator it = phi.assignmentIterator; it.hasNext(); it.advance()) { double val = ptl.phi (it); // do something with val } </pre> * <p> * This is equivalent to creating an assignment object explicitly * using <tt>(Assignment) it.next()</tt>, but can be much faster. */ public double phi (AssignmentIterator it); /** * Multiplies this potential by a constant such that it sums to 1. */ public void normalize (); /** * Returns the marginal of this distribution over the given variables. */ public DiscretePotential marginalize (Variable vars[]); /** * Returns the marginal of this distribution over the given variables. */ public DiscretePotential marginalize (Collection vars); /** * Returns the marginal of this distribution over one variable. */ public DiscretePotential marginalize (Variable var); /** * Returns the marginal distribution attained by summing out * the given variable. */ public DiscretePotential marginalizeOut (Variable var); /** * Returns a potential phi over the given variables * obtained by taking * phi (x) = max_[all v that contain x] this.prob (x) */ public DiscretePotential extractMax (Collection vars); /** * Returns a potential phi over the given variables * obtained by taking * phi (x) = max_[all v that contain x] this.prob (x) */ public DiscretePotential extractMax (Variable var); /** * Returns a potential phi over the given variables * obtained by taking * phi (x) = max_[all v that contain x] this.prob (x) */ public DiscretePotential extractMax (Variable[] vars); /** * Returns the assignment that maximizes this potential. */ // xxx should return an Assignment int argmax (); /** * Returns the sum of this potential over all cases. */ public double sum (); /** * Returns the expected log potential over all cases. */ public double entropy (); /** * Returns the elementwise product of this distribution and * another */ public DiscretePotential multiply (DiscretePotential dist); /** * Does this *= pot. * <P> * If both potentials are currently in log space, then does * addition instead. * @throws UnsupportedOperationException If one potential is in * log space and the other isn't. */ public void multiplyBy (DiscretePotential pot); /** * Computes this /= pot * <P> * If both potentials are currently in log space, then does * subtraction instead. * @throws UnsupportedOperationException If one potential is in * log space and the other isn't. */ public void divideBy (DiscretePotential pot); public boolean isInLogSpace (); /** * Puts this potential into log space. That is, sets every element * in this potential to its log. If this potential is already in * log space, then this method does nothing. */ public void logify (); /** * Takes this potential back down from log space. That is, sets * every element in this potential to its exp. If this potential * has not previously been put into log space using {@link logify}, * then this method does nothing. */ public void delogify (); /** * Returns a new potential exactly the same as this, except in log * space. */ public DiscretePotential log (); /** * Returns whether the potential is over the given variable. */ public boolean containsVar (Variable var); /** Returns set of variables in this potential. */ public Set varSet (); /** Returns an iterator over all Assignmentss to this potential. */ public AssignmentIterator assignmentIterator (); /** Returns whether this is almost equal to another potential. */ public boolean almostEquals (DiscretePotential p); public boolean almostEquals (DiscretePotential p, double epsilon); public DiscretePotential duplicate (); public boolean isNaN ();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -