de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous
Class MEMConstraint

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.discrete.Constraint
      extended by de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhConstraint
          extended by de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.MEMConstraint
All Implemented Interfaces:
Storable, Cloneable

public class MEMConstraint
extends InhConstraint

This constraint can be used for any maximum entropy model (MEM) application.

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhConstraint
offset
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.Constraint
counts, freq, usedPositions
 
Constructor Summary
MEMConstraint(int[] pos, int[] alphabetLength)
          Creates a MEMConstraint as part of a (whole) model.
MEMConstraint(int[] pos, int[] alphabetLength, int[] corrected_positions)
          Creates a MEMConstraint as part of a model.
MEMConstraint(StringBuffer xml)
          The standard constructor for the interface Storable.
 
Method Summary
 void addParameters(int offset, IntList list, MEMConstraint[] constraint, double[] params, int[] start)
          This method implements a heuristic to modify a constraint if a number of constraints should be delete.
protected  void appendAdditionalInfo(StringBuffer xml)
          This method appends additional information that is not stored in the base class to the StringBuffer.
 MEMConstraint clone()
           
 int comparePosition(int offset, MEMConstraint constr)
          This method computes the number of overlapping positions between the current and the given constraints.
 void draw(double ess)
          Draws the parameters from a Dirichlet.
 void estimate(double ess)
          Estimates the (smoothed) relative frequencies using the ess (equivalent sample size).
protected  void extractAdditionalInfo(StringBuffer xml)
          This method parses additional information from the StringBuffer that is not parsed in the base class.
 int getCorrectedPosition(int index)
          Returns the value of the corrected position index.
 double getExpLambda(int index)
          Returns the exponential value of $\lambda_{index}$ at position index: $\exp(\lambda_{index})$.
 double getFreq(int index)
          Returns the current frequency with index index.
 double getLambda(int index)
          Returns the value of $\lambda_{index}$.
protected  String getXMLTag()
          Returns the XML tag that is used for the class to en- or decode.
 void multiplyExpLambdaWith(int index, double val)
          Multiplies the exponential value of $\lambda_{index}$ with the factor val: $\exp(\lambda_{index}) \cdot val$.
 void reset()
          This method resets all member variables that are in some way counters, frequencies, ...
 int satisfiesSpecificConstraint(SequenceIterator sequence)
          Returns the index of the constraint that is satisfied by sequence.
 void setExpLambda(int index, double val)
          Sets the exponential value of $\exp(\lambda_{index}) = val$.
(Additionally it sets the value of $\lambda_{index}$ to the logarithmic value of val: $\lambda_{index} = \log(val)$.)
 void setLambda(int index, double val)
          Sets the value of $\lambda_{index} = val$.
(Additionally it sets the exponential value of $\lambda_{index} = val$ to the exponential value of val: $\exp(\lambda_{index}) = \exp(val)$.
 String toString()
           
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhConstraint
getDescription, satisfiesSpecificConstraint
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.Constraint
add, add, estimateUnConditional, getCount, getFreq, getFreqInfo, getMarginalOrder, getNumberOfSpecificConstraints, getPosition, getPositions, resetCounts, toXML
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MEMConstraint

public MEMConstraint(int[] pos,
                     int[] alphabetLength)
              throws IllegalArgumentException
Creates a MEMConstraint as part of a (whole) model.

Parameters:
pos - the used positions (have to be sorted)
alphabetLength - an array containing the length of the the alphabet for each position (of the whole model)
Throws:
IllegalArgumentException - if pos is not sorted
See Also:
Constraint.Constraint(int[], int)

MEMConstraint

public MEMConstraint(int[] pos,
                     int[] alphabetLength,
                     int[] corrected_positions)
              throws IllegalArgumentException
Creates a MEMConstraint as part of a model.

Parameters:
pos - the used positions (have to be sorted)
alphabetLength - an array containing the length of the the alphabet for each position (of the whole model)
corrected_positions - an array containing the corrected positions if the maximum entropy model is decomposed into parts
Throws:
IllegalArgumentException - if pos is not sorted or pos.length != corrected_positions.length
See Also:
InhConstraint.InhConstraint(int[], int[])

MEMConstraint

public MEMConstraint(StringBuffer xml)
              throws NonParsableException
The standard constructor for the interface Storable. Creates a new MEMConstraint out of its XML representation.

Parameters:
xml - the XML representation as StringBuffer
Throws:
NonParsableException - if the MEMConstraint could not be reconstructed out of the XML representation (the StringBuffer could not be parsed)
See Also:
Storable, InhConstraint.InhConstraint(StringBuffer)
Method Detail

clone

public MEMConstraint clone()
                    throws CloneNotSupportedException
Overrides:
clone in class InhConstraint
Throws:
CloneNotSupportedException

estimate

public void estimate(double ess)
Description copied from class: Constraint
Estimates the (smoothed) relative frequencies using the ess (equivalent sample size).

Specified by:
estimate in class Constraint
Parameters:
ess - the ess

draw

public void draw(double ess)
Draws the parameters from a Dirichlet.

Parameters:
ess - the equivalent sample size

getCorrectedPosition

public int getCorrectedPosition(int index)
Returns the value of the corrected position index.

Parameters:
index - the index of the position
Returns:
the value of the corrected position

getExpLambda

public double getExpLambda(int index)
Returns the exponential value of $\lambda_{index}$ at position index: $\exp(\lambda_{index})$.

Parameters:
index - the index
Returns:
$\exp(\lambda_{index})$

getLambda

public double getLambda(int index)
Returns the value of $\lambda_{index}$.

Parameters:
index - the index
Returns:
$\lambda_{index}$

multiplyExpLambdaWith

public void multiplyExpLambdaWith(int index,
                                  double val)
Multiplies the exponential value of $\lambda_{index}$ with the factor val: $\exp(\lambda_{index}) \cdot val$.
(Additionally it adds the logarithmic value of val to the value of $\lambda_{index}$ at position index: $\lambda_{index} + \log(val)$.)

Parameters:
index - the index
val - the factor/value

reset

public void reset()
Description copied from class: Constraint
This method resets all member variables that are in some way counters, frequencies, ...

Overrides:
reset in class Constraint

satisfiesSpecificConstraint

public int satisfiesSpecificConstraint(SequenceIterator sequence)
Returns the index of the constraint that is satisfied by sequence.

Parameters:
sequence - the SequenceIterator
Returns:
the index of the fulfilled constraint

getFreq

public double getFreq(int index)
Description copied from class: Constraint
Returns the current frequency with index index.

Overrides:
getFreq in class Constraint
Parameters:
index - the index
Returns:
the current frequency

setExpLambda

public void setExpLambda(int index,
                         double val)
Sets the exponential value of $\exp(\lambda_{index}) = val$.
(Additionally it sets the value of $\lambda_{index}$ to the logarithmic value of val: $\lambda_{index} = \log(val)$.)

Parameters:
index - the index
val - the value to be set

setLambda

public void setLambda(int index,
                      double val)
Sets the value of $\lambda_{index} = val$.
(Additionally it sets the exponential value of $\lambda_{index} = val$ to the exponential value of val: $\exp(\lambda_{index}) = \exp(val)$.

Parameters:
index - the index
val - the value

toString

public String toString()
Specified by:
toString in class Constraint

appendAdditionalInfo

protected void appendAdditionalInfo(StringBuffer xml)
Description copied from class: Constraint
This method appends additional information that is not stored in the base class to the StringBuffer.

Overrides:
appendAdditionalInfo in class InhConstraint
Parameters:
xml - the StringBuffer that is used for appending additional information

getXMLTag

protected String getXMLTag()
Description copied from class: Constraint
Returns the XML tag that is used for the class to en- or decode.

Specified by:
getXMLTag in class Constraint
Returns:
the XML tag that is used for the class to en- or decode

extractAdditionalInfo

protected void extractAdditionalInfo(StringBuffer xml)
                              throws NonParsableException
Description copied from class: Constraint
This method parses additional information from the StringBuffer that is not parsed in the base class.

Overrides:
extractAdditionalInfo in class InhConstraint
Parameters:
xml - the StringBuffer to be parsed
Throws:
NonParsableException - if something with the parsing went wrong

comparePosition

public int comparePosition(int offset,
                           MEMConstraint constr)
This method computes the number of overlapping positions between the current and the given constraints.

Parameters:
offset - the offset for the given constraint
constr - the given constraint
Returns:
the number of matching positions

addParameters

public void addParameters(int offset,
                          IntList list,
                          MEMConstraint[] constraint,
                          double[] params,
                          int[] start)
This method implements a heuristic to modify a constraint if a number of constraints should be delete.

Parameters:
offset - the offset for the constraints
list - a list of indices of constraints that should be used in this method
constraint - the constraints
params - the parameters
start - the start indices of the constraints in the paramsarray