Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.jstacs.models.discrete
Class Constraint

    java.lang.Object
      de.jstacs.models.discrete.Constraint

All Implemented Interfaces:
  Storable

Direct Known Subclasses:
  HomogeneousModel.HomCondProb, InhConstraint

    public abstract class Constraint

extends Object
implements Storable

The main class for all constraints on models. This class centralizes all specific constraints (e.g. P(X1=A,X2=A)) from a partitioning constraint (e.g. all specific constraints for some given positions).

Author:
  Jens Keilwagen

Field Summary
`protected double[]` | `counts` The counts for each specific constraint.
`protected double[]` | `freq` The frequencies estimated from the counts.
`protected int[]` | `usedPositions` The used positions.

Constructor Summary
`protected` | `Constraint(int[] usedPositions, int n)` The main constructor.
`protected` | `Constraint(StringBuffer xml)` The standard constructor for the interface `Storable`.

Method Summary
`void` | `add(int index, double weight)` Adds the given `weight` to the count with index `index`.
`void` | `add(Sequence seq, int start, double weight)` This method determines the specific constraint that is fulfilled by the `Sequence` `seq` and adds the `weight` to the specific counter.
`protected abstract void` | `appendAdditionalInfo(StringBuffer xml)` This method appends additional information that is not stored in the base class to the `StringBuffer`.
`protected Constraint` | `clone()`
`abstract void` | `estimate(double ess)` Estimates the (smoothed) relative frequencies using the ess (equivalent sample size).
`protected void` | `estimateUnConditional(int start, int end, double pc, boolean exceptionWhenNoData)` Estimates unconditionally.
`protected abstract void` | `extractAdditionalInfo(StringBuffer xml)` This method parses additional information from the `StringBuffer` that is not parsed in the base class.
`double` | `getCount(int index)` Returns the current count with index `index`.
`abstract String` | `getDescription(AlphabetContainer con, int i)` Returns the decoded symbol for the encoded symbol `i`.
`double` | `getFreq(int index)` Returns the current frequency with index `index`.
`double` | `getFreq(Sequence seq, int start)` This method determines the specific constraint that is fulfilled by the `Sequence` `seq` beginning at position `start`.
`String` | `getFreqInfo(AlphabetContainer con)` Returns an information about the stored frequencies.
`int` | `getMarginalOrder()` Returns the marginal order, i.e. the number of used random variables.
`int` | `getNumberOfSpecificConstraints()` Returns the number of specific constraints.
`int` | `getPosition(int index)` Returns the position with index `index`.
`int[]` | `getPositions()` Returns a clone of the array of used positions.
`protected abstract String` | `getXMLTag()` Returns the XML tag that is used for the class to en- or decode.
`void` | `reset()` This method resets all member variables that are in some way counters, frequencies, ...
`void` | `resetCounts()` This method allows to reset the internal field `counts` that is used for estimating the probabilities.
`abstract int` | `satisfiesSpecificConstraint(Sequence seq, int start)` This method returns the index of the specific constraint that is fulfilled by the `Sequence` `seq` beginning at position `start`.
`abstract String` | `toString()`
`StringBuffer` | `toXML()` This method returns an XML representation as `StringBuffer` of an instance of the implementing class.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### counts

    protected double[] counts

  The counts for each specific constraint.

### freq

    protected double[] freq

  The frequencies estimated from the counts.

### usedPositions

    protected int[] usedPositions

  The used positions.

Constructor Detail

### Constraint

    protected Constraint(int[] usedPositions,
                         int n)
                  throws IllegalArgumentException

  The main constructor. Creates a new `Constraint` and checks that each position is used maximally once.

  Parameters:
    `usedPositions` - the used positions (will be cloned), have to be non-negative
    `n` - the number of specific constraints
  Throws:
    `IllegalArgumentException` - if there are some fundamental errors in the arguments for the positions

### Constraint

    protected Constraint(StringBuffer xml)
                  throws NonParsableException

  The standard constructor for the interface `Storable`. Creates a new `Constraint` out of its XML representation.

  Parameters:
    `xml` - the XML representation as `StringBuffer`
  Throws:
    `NonParsableException` - if the `Constraint` could not be reconstructed out of the XML representation (the `StringBuffer` could not be parsed)
  See Also:
    `Storable`, `extractAdditionalInfo(StringBuffer)`

Method Detail

### add

    public final void add(int index,
                          double weight)

  Adds the given `weight` to the count with index `index`.

  Parameters:
    `index` - the index
    `weight` - the weight

### add

    public void add(Sequence seq,
                    int start,
                    double weight)

  This method determines the specific constraint that is fulfilled by the `Sequence` `seq` and adds the `weight` to the specific counter.

  Parameters:
    `seq` - the sequence
    `start` - the start position
    `weight` - the weight for the sequence
  See Also:
    `satisfiesSpecificConstraint(Sequence, int)`, `add(int, double)`

### clone

    protected Constraint clone()
                        throws CloneNotSupportedException

  Overrides:
    `clone` in class `Object`
  Throws:
    `CloneNotSupportedException`

### estimate

    public abstract void estimate(double ess)

  Estimates the (smoothed) relative frequencies using the ess (equivalent sample size).

  Parameters:
    `ess` - the ess

### estimateUnConditional

    protected void estimateUnConditional(int start,
                                         int end,
                                         double pc,
                                         boolean exceptionWhenNoData)

  Estimates unconditionally.

  Parameters:
    `start` - the start index
    `end` - the end index
    `pc` - the pseudocount for each parameter
    `exceptionWhenNoData` - indicates if an (runtime) exception is thrown if no data was available to estimate the parameters

### appendAdditionalInfo

    protected abstract void appendAdditionalInfo(StringBuffer xml)

  This method appends additional information that is not stored in the base class to the `StringBuffer`.

  Parameters:
    `xml` - the `StringBuffer` that is used for appending additional information

### getCount

    public double getCount(int index)

  Returns the current count with index `index`.

  Parameters:
    `index` - the index
  Returns:
    the current count

### getFreq

    public double getFreq(int index)

  Returns the current frequency with index `index`.

  Parameters:
    `index` - the index
  Returns:
    the current frequency

### getFreq

    public double getFreq(Sequence seq,
                          int start)

  This method determines the specific constraint that is fulfilled by the `Sequence` `seq` beginning at position `start`.

  Parameters:
    `seq` - the `Sequence`
    `start` - the start position
  Returns:
    the according frequency
  See Also:
    `satisfiesSpecificConstraint(Sequence, int)`, `getFreq(int)`

### getMarginalOrder

    public int getMarginalOrder()

  Returns the marginal order, i.e. the number of used random variables.

  Returns:
    the marginal order

### getNumberOfSpecificConstraints

    public int getNumberOfSpecificConstraints()

  Returns the number of specific constraints.

  Returns:
    the number of specific constraints

### getPosition

    public int getPosition(int index)

  Returns the position with index `index`.

  Parameters:
    `index` - the index
  Returns:
    the position with index `index`

### getPositions

    public int[] getPositions()

  Returns a clone of the array of used positions.

  Returns:
    a clone of the array of used positions

### getXMLTag

    protected abstract String getXMLTag()

  Returns the XML tag that is used for the class to en- or decode.

  Returns:
    the XML tag that is used for the class to en- or decode

### reset

    public void reset()

  This method resets all member variables that are in some way counters, frequencies, ...

### satisfiesSpecificConstraint

    public abstract int satisfiesSpecificConstraint(Sequence seq,
                                                    int start)

  This method returns the index of the specific constraint that is fulfilled by the `Sequence` `seq` beginning at position `start`.

  Parameters:
    `seq` - the sequence
    `start` - the start position
  Returns:
    the index of the fulfilled, specific constraint

### extractAdditionalInfo

    protected abstract void extractAdditionalInfo(StringBuffer xml)
                                           throws NonParsableException

  This method parses additional information from the `StringBuffer` that is not parsed in the base class.

  Parameters:
    `xml` - the `StringBuffer` to be parsed
  Throws:
    `NonParsableException` - if something with the parsing went wrong

### toString

    public abstract String toString()

  Overrides:
    `toString` in class `Object`

### toXML

    public StringBuffer toXML()

  Description copied from interface: `Storable`
  This method returns an XML representation as `StringBuffer` of an instance of the implementing class.

  Specified by:
    `toXML` in interface `Storable`
  Returns:
    the XML representation

### getDescription

    public abstract String getDescription(AlphabetContainer con,
                                          int i)

  Returns the decoded symbol for the encoded symbol `i`.

  Parameters:
    `con` - the `AlphabetContainer`
    `i` - the encoded symbol
  Returns:
    the decoded symbol for the encoded symbol `i`

### getFreqInfo

    public String getFreqInfo(AlphabetContainer con)

  Returns an information about the stored frequencies.

  Parameters:
    `con` - the `AlphabetContainer`
  Returns:
    an information about the stored frequencies

### resetCounts

    public void resetCounts()

  This method allows to reset the internal field `counts` that is used for estimating the probabilities.

  See Also:
    `add(int, double)`, `add(Sequence, int, double)`, `estimate(double)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD