edu.stanford.nlp.ie.hmm
Class Structure

java.lang.Object
  |
  +--edu.stanford.nlp.ie.hmm.Structure
All Implemented Interfaces:
GeneralStructure, Serializable
Direct Known Subclasses:
MultiStructure

public class Structure
extends Object
implements GeneralStructure, Serializable

Class to model an HMM structure. This builds a straightforward one-target-state structure, via a series of structure building operations. It can be used like this:

      Structure s = new Structure();
      s.giveDefault();
      s.lengthenTarget(0);
      s.lengthenTarget(0);
      s.addTarget(1);
      s.addPrefix(1);
      s.addSuffix(2);
      s.addPrefix(3);
      s.createTransitions();
      State[] struct = s.getStates();
 

See Also:
Serialized Form

Field Summary
static int BACKGROUND
           
static int END
           
static int END_STATE
           
static int GLOBAL_END
           
static int GLOBAL_START
           
static Double ONE
           
static int PREFIX
           
protected  List prefixes
           
static int START
           
static int START_STATE
           
protected  List stateTypes
           
static int SUFFIX
           
protected  List suffixes
           
static int TARGET
           
protected  List targets
           
protected  List transitions
           
static Double ZERO
           
 
Constructor Summary
Structure()
           
Structure(double[][] transitions, int[] stateTypes)
           
Structure(State[] states)
           
 
Method Summary
 void addPrefix(int length)
          Legacy method for modifying the structure.
 void addSuffix(int length)
          Legacy method for modifying the structure.
 void addTarget(int length)
          Legacy method for modifying the structure.
 void addTransition(int fromState, int toState)
          Inserts a transition from fromState to toState
static State[] chrisDefaultStates()
          Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states.
static State[] chrisDefaultStates2()
          Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states.
 Structure copy()
           
static State[] defaultStates()
           
 List getIncoming(int toState)
           
 List getOutgoing(int fromState)
           
 State[] getStates()
           
 double[][] getTransitions()
           
 void giveDefault()
          Build a simple IE HMM structure, with start and finish state, and one each background, prefix, suffix, and target states.
protected  void giveEmpty()
           
 void giveErgodic(int[] stateTypes)
          Builds an ergodic (fully-connected) HMM structure.
 void giveTarget()
          Build a simple Target HMM structure, with start and finish state and target states only.
 void initializeTransitions()
          initializes the transition weights in the HMM to "sensible" values
 int insertState(int state, int type)
          Inserts a new state of given type AFTER the specified state.
static State[] jimDefaultStates()
          Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states.
 void lengthenPrefix(int i)
          Legacy method for modifying the structure.
 void lengthenSuffix(int i)
          Legacy method for modifying the structure.
 void lengthenTarget(int i)
          Legacy method for modifying the structure.
static void main(String[] args)
          Provides a sample exercising of the structure creation operations
static Structure mergeStructures(Structure[] structures)
           
static void normalize(double[] dist)
           
 int numParameters()
           
 int numPrefixes()
           
 int numSuffixes()
           
 int numTargets()
           
static void perturbTransitions(double[][] t)
           
 void setWeight(int fromState, int toState, double weight)
          Sets the weight for the transition from fromState to toState
 int splitState(int state)
          Splits a state into two states of the same type producing one new state.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

transitions

protected List transitions

END_STATE

public static final int END_STATE
See Also:
Constant Field Values

START_STATE

public static final int START_STATE
See Also:
Constant Field Values

GLOBAL_END

public static final int GLOBAL_END
See Also:
Constant Field Values

GLOBAL_START

public static final int GLOBAL_START
See Also:
Constant Field Values

END

public static final int END
See Also:
Constant Field Values

START

public static final int START
See Also:
Constant Field Values

BACKGROUND

public static final int BACKGROUND
See Also:
Constant Field Values

TARGET

public static final int TARGET
See Also:
Constant Field Values

PREFIX

public static final int PREFIX
See Also:
Constant Field Values

SUFFIX

public static final int SUFFIX
See Also:
Constant Field Values

stateTypes

protected List stateTypes

ONE

public static final Double ONE

ZERO

public static final Double ZERO

prefixes

protected List prefixes

suffixes

protected List suffixes

targets

protected List targets
Constructor Detail

Structure

public Structure()

Structure

public Structure(State[] states)

Structure

public Structure(double[][] transitions,
                 int[] stateTypes)
Method Detail

insertState

public int insertState(int state,
                       int type)
Inserts a new state of given type AFTER the specified state. For example if we had 1->2->(3 4), insertState(2, Structure.SUFFIX) would produce 1->2->5->(3 4). Note that state 2 formerly went to the two states 3 and 4, but now goes instead to the new state 5, and state 5 now goes to 3 and 4. Possible types are Structure.PREFIX, Structure.SUFFIX, Structure.TARGET, and Structure.BACKGROUND


splitState

public int splitState(int state)
Splits a state into two states of the same type producing one new state. For example, if we have 1->2->3, then split(2) produces 1->(2 4)->3. Note that all of the transitions into state 2 also go to the new state 4, and the transitions from state 2 are also in state 4


addTransition

public void addTransition(int fromState,
                          int toState)
Inserts a transition from fromState to toState


setWeight

public void setWeight(int fromState,
                      int toState,
                      double weight)
Sets the weight for the transition from fromState to toState


getOutgoing

public List getOutgoing(int fromState)
Returns:
A List containing the states that can be reached from fromState

getIncoming

public List getIncoming(int toState)
Returns:
A List containing the states that go to toState

giveEmpty

protected void giveEmpty()

giveDefault

public void giveDefault()
Build a simple IE HMM structure, with start and finish state, and one each background, prefix, suffix, and target states.


giveTarget

public void giveTarget()
Build a simple Target HMM structure, with start and finish state and target states only.


giveErgodic

public void giveErgodic(int[] stateTypes)
Builds an ergodic (fully-connected) HMM structure. All states can be reached from any other state except the end state, and all states can go to any other state except the start state. Equal weights are assigned to all transitions, which can be perturbed.


mergeStructures

public static Structure mergeStructures(Structure[] structures)
Returns:
A new structure containing the merged structures

numPrefixes

public int numPrefixes()

numTargets

public int numTargets()

numSuffixes

public int numSuffixes()

addPrefix

public void addPrefix(int length)
Legacy method for modifying the structure. Adds a new prefix chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault


addSuffix

public void addSuffix(int length)
Legacy method for modifying the structure. Adds a new suffix chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault


addTarget

public void addTarget(int length)
Legacy method for modifying the structure. Adds a new target chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault or @see giveTarget


lengthenPrefix

public void lengthenPrefix(int i)
Legacy method for modifying the structure. Extends the named prefix chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault


lengthenSuffix

public void lengthenSuffix(int i)
Legacy method for modifying the structure. Extends the named suffix chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault


lengthenTarget

public void lengthenTarget(int i)
Legacy method for modifying the structure. Extends the named target chain chain in the "list of lists" representation. Can only be used if the structure is initialized with @see giveDefault or @see giveTarget


copy

public Structure copy()

initializeTransitions

public void initializeTransitions()
initializes the transition weights in the HMM to "sensible" values


getTransitions

public double[][] getTransitions()
Returns:
The transition matrix for the HMM

perturbTransitions

public static void perturbTransitions(double[][] t)

normalize

public static void normalize(double[] dist)

numParameters

public int numParameters()

getStates

public State[] getStates()
Specified by:
getStates in interface GeneralStructure

toString

public String toString()
Overrides:
toString in class Object

defaultStates

public static State[] defaultStates()

jimDefaultStates

public static State[] jimDefaultStates()
Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states. The structure is based on a McCallum and Nigam example. We add start, finish, and background states to prefix/suffix/target states.


chrisDefaultStates

public static State[] chrisDefaultStates()
Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states. The structure is based on a McCallum and Nigam example. We add start, finish, and background states to prefix/suffix/target states. This just changes some transition structure


chrisDefaultStates2

public static State[] chrisDefaultStates2()
Initializes a reasonable default structure, with a background, prefix and suffix states and some number of target states. The structure is based on a McCallum and Nigam example. We add start, finish, and background states to prefix/suffix/target states. Versus the Jim version, this version just changes some transition structure, in hopefully useful ways


main

public static void main(String[] args)
Provides a sample exercising of the structure creation operations



Stanford NLP Group