001 package calhoun.analysis.crf;
002
003 /** holds additional configuration information used in semi-Markov CRFs.
004 */
005 public class SemiMarkovSetup {
006 boolean ignoreSemiMarkovSelfTransitions;
007 private short[] maxLengths;
008 private short[] minLengths;
009
010 /** default constructor used by Spring during automatic configuration */
011 public SemiMarkovSetup() { }
012 /** constructs using this set of maximum lengths. */
013 public SemiMarkovSetup(short[] lengths) { this.maxLengths = lengths; }
014 /** constructs using this set of maximum lengths and value for the ignore flag. */
015 public SemiMarkovSetup(short[] lengths, boolean ignore) {
016 this(lengths);
017 ignoreSemiMarkovSelfTransitions = ignore;
018 }
019
020 /** constructs will all parameters. */
021 public SemiMarkovSetup(short[] minLen, short maxLen[], boolean ignore) {
022 this.minLengths = minLen;
023 this.maxLengths = maxLen;
024 this.ignoreSemiMarkovSelfTransitions = ignore;
025 }
026
027 /** gets the minimum lengths for each state. The minimum value is 1. This array defaults to
028 * all 1's if it was not set explicitly.
029 * @return an array of the minimum lengths of each state.
030 */
031 public short[] getMinLengths() {
032 // Default minLengths to all zeros (and the same size as maxLengths).
033 if(minLengths == null)
034 minLengths = new short[maxLengths.length];
035 return minLengths;
036 }
037
038 /** sets the minimum lengths for each state.
039 * @param lengths an array of the minimum lengths of each state.
040 */
041 public void setMinLengths(short[] lengths) {
042 this.minLengths = lengths;
043 }
044
045 /** gets the maximum lengths for each state. The minimum value is 1, which corresponds to the
046 * special case of a Markov feature. This value has no default. It is usually configured through the XML model file.
047 * @return an array of the maximum lengths of each state.
048 */
049 public short[] getMaxLengths() {
050 return maxLengths;
051 }
052
053 /** sets the maximum lengths for each state.
054 * @param lengths an array of the minimum lengths of each state.
055 */
056 public void setMaxLengths(short[] lengths) {
057 this.maxLengths = lengths;
058 }
059
060 /** gets the flag indicating that self-transition edges for the semi-Markov states should be ignored. This flag is useful
061 * if you are using the same model definition for both Markov and semi-Markov models. In a Markov model a self-transition
062 * means that a state can be repeated multiple times, essentially forming a segment. However, in a semi-Markov a self-transition
063 * means a transition between two segments with the same state. This distinction means that the same state transition graph
064 * will mean different things under the two models. If this flag is set to true, which is the
065 * default, then it is assumed that no two segments in the semi-Markov model can have the same state, and so self-transitions in
066 * the semi-Markov states are ignored. This forces the state transition graph to have the same meaning for both cases.
067 * <p>
068 * This flag does not affect Markov states, those with a max length of 1. This means that a state may legally occur in consecutive
069 * positions if the maximum length for that state is one and the graph contains a self-transition for that state.
070 * @return true if self-transition edges in the model should be ignored.
071 */
072 public boolean isIgnoreSemiMarkovSelfTransitions() {
073 return ignoreSemiMarkovSelfTransitions;
074 }
075
076 /** sets the flag indicating that self-transition edges for the semi-Markov states should be ignored.
077 * @param ignoreSemiMarkovSelfTransitions true if self-transition edges for the semi-Markov states should be ignored.
078 */
079 public void setIgnoreSemiMarkovSelfTransitions(
080 boolean ignoreSemiMarkovSelfTransitions) {
081 this.ignoreSemiMarkovSelfTransitions = ignoreSemiMarkovSelfTransitions;
082 }
083 }