edu.stanford.nlp.ie.crf
Class CRFCliqueTree

java.lang.Object
  extended by edu.stanford.nlp.ie.crf.CRFCliqueTree
All Implemented Interfaces:
SequenceListener, SequenceModel

public class CRFCliqueTree
extends Object
implements SequenceModel, SequenceListener

Builds a CliqueTree (an array of FactorTable) and does message passing inference along it.

Author:
Jenny Finkel

Method Summary
 int backgroundIndex()
           
 String backgroundSymbol()
           
 Index classIndex()
           
 double condLogProbGivenNext(int position, int label, int[] nextLabels)
           
 double condLogProbGivenNext(int position, Object label, Object[] nextLabels)
           
 double condLogProbGivenPrevious(int position, int label, int[] prevLabels)
           
 double condLogProbGivenPrevious(int position, Object label, Object[] prevLabels)
           
 Counter condLogProbsGivenNext(int position, int[] nextlabels)
           
 Counter condLogProbsGivenNext(int position, Object[] nextlabels)
           
 Counter condLogProbsGivenPrevious(int position, int[] prevlabels)
           
 Counter condLogProbsGivenPrevious(int position, Object[] prevlabels)
           
 double condProbGivenNext(int position, int label, int[] nextLabels)
           
 double condProbGivenNext(int position, Object label, Object[] nextLabels)
           
 double condProbGivenPrevious(int position, int label, int[] prevLabels)
           
 double condProbGivenPrevious(int position, Object label, Object[] prevLabels)
           
static CRFCliqueTree getCalibratedCliqueTree(double[][] weights, int[][][] data, Index[] labelIndices, int numClasses, Index classIndex, String backgroundSymbol)
           
 double[] getConditionalDistribution(int[] sequence, int position)
          Computes the distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 int getNumClasses()
           
 int getNumValues()
           
 int[] getPossibleValues(int position)
          0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;
 int leftWindow()
          How many positions to the left a position is dependent on.
 int length()
           
 double logProb(int position, int label)
           
 double logProb(int position, int[] labels)
           
 double logProb(int position, Object label)
           
 double logProb(int position, Object[] labels)
           
 Counter logProbs(int position)
           
 GeneralizedCounter logProbs(int position, int window)
           
 double prob(int position, int label)
           
 double prob(int position, int[] labels)
           
 double prob(int position, Object label)
           
 double prob(int position, Object[] labels)
           
 Counter probs(int position)
           
 GeneralizedCounter probs(int position, int window)
           
 int rightWindow()
          How many positions to the right a position is dependent on.
 double scoreOf(int[] sequence)
          Returns the log probability of this sequence given the CRF.
 double scoreOf(int[] sequence, int pos)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 double[] scoresOf(int[] sequence, int position)
          Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.
 void setInitialSequence(int[] sequence)
          Informs this sequence model that the value of the whole sequence is initialized to sequence
 double totalMass()
           
 void updateSequenceElement(int[] sequence, int pos, int oldVal)
          Informs this sequence model that the value of the element at position pos has changed.
 int window()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

classIndex

public Index classIndex()

length

public int length()
Specified by:
length in interface SequenceModel
Returns:
the length of the sequences modeled by this SequenceModel

leftWindow

public int leftWindow()
Description copied from interface: SequenceModel
How many positions to the left a position is dependent on.

Specified by:
leftWindow in interface SequenceModel
Returns:
the size of the left window used by this sequence model

rightWindow

public int rightWindow()
Description copied from interface: SequenceModel
How many positions to the right a position is dependent on.

Specified by:
rightWindow in interface SequenceModel
Returns:
the size of the right window used by this sequence model

getPossibleValues

public int[] getPossibleValues(int position)
Description copied from interface: SequenceModel
0...leftWindow-1 etc are null, leftWindow...length+leftWindow-1 are words, length+leftWindow...length+leftWindow+rightWindow-1 are null;

Specified by:
getPossibleValues in interface SequenceModel
Parameters:
position - the position
Returns:
the set of possible int values at this position, as an int array

scoreOf

public double scoreOf(int[] sequence,
                      int pos)
Description copied from interface: SequenceModel
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoreOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
pos - the position of the element to give a distribution for
Returns:
the log score of the token at the specified position in the sequence

scoresOf

public double[] scoresOf(int[] sequence,
                         int position)
Computes the unnormalized log conditional distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Specified by:
scoresOf in interface SequenceModel
Parameters:
sequence - the sequence containing the rest of the values to condition on
position - the position of the element to give a distribution for
Returns:
an array of type double, representing a probability distribution; sums to 1.0

scoreOf

public double scoreOf(int[] sequence)
Returns the log probability of this sequence given the CRF. Does so by computing the marginal of the first windowSize tags, and then computing the conditional probability for the rest of them, conditioned on the previous tags.

Specified by:
scoreOf in interface SequenceModel
Parameters:
sequence - the sequence to compute a score for
Returns:
the score for the sequence

window

public int window()

getNumClasses

public int getNumClasses()

totalMass

public double totalMass()

backgroundIndex

public int backgroundIndex()

backgroundSymbol

public String backgroundSymbol()

logProb

public double logProb(int position,
                      int label)

prob

public double prob(int position,
                   int label)

logProb

public double logProb(int position,
                      Object label)

prob

public double prob(int position,
                   Object label)

probs

public Counter probs(int position)

logProbs

public Counter logProbs(int position)

logProb

public double logProb(int position,
                      int[] labels)

prob

public double prob(int position,
                   int[] labels)

logProb

public double logProb(int position,
                      Object[] labels)

prob

public double prob(int position,
                   Object[] labels)

logProbs

public GeneralizedCounter logProbs(int position,
                                   int window)

probs

public GeneralizedCounter probs(int position,
                                int window)

condLogProbGivenPrevious

public double condLogProbGivenPrevious(int position,
                                       int label,
                                       int[] prevLabels)

condLogProbGivenPrevious

public double condLogProbGivenPrevious(int position,
                                       Object label,
                                       Object[] prevLabels)

condProbGivenPrevious

public double condProbGivenPrevious(int position,
                                    int label,
                                    int[] prevLabels)

condProbGivenPrevious

public double condProbGivenPrevious(int position,
                                    Object label,
                                    Object[] prevLabels)

condLogProbsGivenPrevious

public Counter condLogProbsGivenPrevious(int position,
                                         int[] prevlabels)

condLogProbsGivenPrevious

public Counter condLogProbsGivenPrevious(int position,
                                         Object[] prevlabels)

condLogProbGivenNext

public double condLogProbGivenNext(int position,
                                   int label,
                                   int[] nextLabels)

condLogProbGivenNext

public double condLogProbGivenNext(int position,
                                   Object label,
                                   Object[] nextLabels)

condProbGivenNext

public double condProbGivenNext(int position,
                                int label,
                                int[] nextLabels)

condProbGivenNext

public double condProbGivenNext(int position,
                                Object label,
                                Object[] nextLabels)

condLogProbsGivenNext

public Counter condLogProbsGivenNext(int position,
                                     int[] nextlabels)

condLogProbsGivenNext

public Counter condLogProbsGivenNext(int position,
                                     Object[] nextlabels)

getCalibratedCliqueTree

public static CRFCliqueTree getCalibratedCliqueTree(double[][] weights,
                                                    int[][][] data,
                                                    Index[] labelIndices,
                                                    int numClasses,
                                                    Index classIndex,
                                                    String backgroundSymbol)
Parameters:
weights -
data -
labelIndices -
numClasses -
classIndex -
Returns:
a new CRFCliqueTree for the weights on the data

getConditionalDistribution

public double[] getConditionalDistribution(int[] sequence,
                                           int position)
Computes the distribution over values of the element at position pos in the sequence, conditioned on the values of the elements in all other positions of the provided sequence.

Parameters:
sequence - the sequence containing the rest of the values to condition on
position - the position of the element to give a distribution for
Returns:
an array of type double, representing a probability distribution; sums to 1.0

updateSequenceElement

public void updateSequenceElement(int[] sequence,
                                  int pos,
                                  int oldVal)
Informs this sequence model that the value of the element at position pos has changed. This allows this sequence model to update its internal model if desired.

Specified by:
updateSequenceElement in interface SequenceListener
Parameters:
sequence -
pos -
oldVal -

setInitialSequence

public void setInitialSequence(int[] sequence)
Informs this sequence model that the value of the whole sequence is initialized to sequence

Specified by:
setInitialSequence in interface SequenceListener
Parameters:
sequence -

getNumValues

public int getNumValues()
Returns:
the number of possible values for each element; it is assumed to be the same for the element at each position


Stanford NLP Group