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
Class CompositeModel

    java.lang.Object
      de.jstacs.models.AbstractModel
          de.jstacs.models.CompositeModel

All Implemented Interfaces:
  Model, Storable, Cloneable

    public class CompositeModel

extends AbstractModel

This class is for modelling sequences by modelling the different positions of the each sequence by different models. For instance one can used this class to model a sequence of subsequences, where each subsequence is modelled by a different model.

Author:
  Jens Keilwagen

Field Summary
`protected int[][]` | `lengths` The length for each component.
`protected Model[]` | `models` The models for the components
`protected int[][]` | `starts` The start indices.

Fields inherited from class de.jstacs.models.AbstractModel
`alphabets, length`

Constructor Summary
`CompositeModel(AlphabetContainer alphabets, int[] assignment, Model... models)`
`CompositeModel(StringBuffer stringBuff)` The constructor for the `Storable` interface.

Method Summary
`CompositeModel` | `clone()` Follows the conventions of `Object`'s clone-method.
`void` | `fromXML(StringBuffer representation)` This method should only be used by the constructor that works on StringBuffer.
`ResultSet` | `getCharacteristics()` Returns some information characterizing or describing the current instance of the model.
`String` | `getInstanceName()` Should return a short instance name such as iMM(0), BN(2), ...
`int[]` | `getLengthOfModels()` This method returns the length of the models in the CompositeModel
`double` | `getLogPriorTerm()` Returns a value that is proportional to the log of the prior.
`double` | `getLogProbFor(Sequence sequence, int startpos, int endpos)` Returns the logarithm of the probability of the given sequence given the model.
`byte` | `getMaximalMarkovOrder()` This method returns the maximal used markov order if possible.
`Model[]` | `getModels()` Returns the a deep copy of the models.
`int` | `getNumberOfModels()` This method returns the number of models in the CompositeModel
`NumericalResultSet` | `getNumericalCharacteristics()` Returns the subset of numerical values that are also returned by `getCharacteristsics`.
`double` | `getProbFor(Sequence sequence, int startpos, int endpos)` Returns the probability of the given sequence given the model.
`boolean` | `isTrained()` Returns true if the model has been trained successfully, false otherwise.
`protected void` | `set(AlphabetContainer abc)` This method should only be invoked by the method `setNewAlphabetContainerInstance( AlphabetContainer )` and not be made public.
`String` | `toString()` Should give a simple representation (text) of the model as String.
`StringBuffer` | `toXML()` This method returns an XML-representation of an instance of the implementing class.
`void` | `train(Sample data, double[] weights)` Trains the Model object given the data as `Sample` using the specified weights.

Methods inherited from class de.jstacs.models.AbstractModel
`emitSample, getAlphabetContainer, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getPriorTerm, getProbFor, getProbFor, setNewAlphabetContainerInstance, train`

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

Field Detail

### models

    protected Model[] models

  The models for the components

### starts

    protected int[][] starts

  The start indices.

### lengths

    protected int[][] lengths

  The length for each component.

Constructor Detail

### CompositeModel

    public CompositeModel(AlphabetContainer alphabets,
                          int[] assignment,
                          Model... models)
                   throws IllegalArgumentException,
                          WrongAlphabetException,
                          CloneNotSupportedException

Parameters:
  `alphabets` - the alphabets
  `assignment` - an array assigning each position to a model
  `models` - the single models
Throws:
  `IllegalArgumentException`
  `WrongAlphabetException` - if (the parts of) the alphabet does not match with the alphabets of the models
  `CloneNotSupportedException` - if the models could not be cloned

### CompositeModel

    public CompositeModel(StringBuffer stringBuff)
                   throws NonParsableException

  The constructor for the `Storable` interface.

  Parameters:
    `stringBuff` - the StringBuffer
  Throws:
    `NonParsableException` - if the StringBuffer is not parsable

Method Detail

### clone

    public CompositeModel clone()
                         throws CloneNotSupportedException

  Description copied from class: `AbstractModel`
  Follows the conventions of `Object`'s clone-method.

  Specified by:
    `clone` in interface `Model`
  Overrides:
    `clone` in class `AbstractModel`
  Returns:
    an object, that is a copy of the current `AbstractModel` (the member-`AlphabetContainer` isn't deeply cloned since it is assumed to be immutable). The type of the returned object is defined by the class `X` directly inherited from `AbstractModel`. Hence `X`'s clone-method should work as:
    1. `Object o = (X)super.clone();` 2. all additional member variables of `o` defined by `X` that are not of simple data-types like int, double, ... , have to be deeply copied 3. `return o`
  Throws:
    `CloneNotSupportedException`

### getCharacteristics

    public ResultSet getCharacteristics()
                                 throws Exception

  Description copied from interface: `Model`
  Returns some information characterizing or describing the current instance of the model. This could be e.g. the number of edges for a Bayesian network or an image showing some representation of the model. The set of characteristics should always include the XML-representation of the model. The corresponding result type is `ObjectResult`

  Specified by:
    `getCharacteristics` in interface `Model`
  Overrides:
    `getCharacteristics` in class `AbstractModel`
  Returns:
    the characteristics
  Throws:
    `Exception` - an `Exception` is thrown if some of the characteristics could not be defined
  See Also:
    `StorableResult`

### getInstanceName

    public String getInstanceName()

  Description copied from interface: `Model`
  Should return a short instance name such as iMM(0), BN(2), ...

  Returns:
    a short instance name

### getLengthOfModels

    public int[] getLengthOfModels()

  This method returns the length of the models in the CompositeModel

  Returns:
    the length of the models

### getMaximalMarkovOrder

    public byte getMaximalMarkovOrder()
                               throws UnsupportedOperationException

  Description copied from interface: `Model`
  This method returns the maximal used markov order if possible.

  Specified by:
    `getMaximalMarkovOrder` in interface `Model`
  Overrides:
    `getMaximalMarkovOrder` in class `AbstractModel`
  Returns:
    maximal used markov order
  Throws:
    `UnsupportedOperationException` - if the model can't give a proper answer

### getNumericalCharacteristics

    public NumericalResultSet getNumericalCharacteristics()
                                                   throws Exception

  Description copied from interface: `Model`
  Returns the subset of numerical values that are also returned by `getCharacteristsics`.

  Returns:
    the numerical characteristics
  Throws:
    `Exception` - an `Exception` is thrown if some of the characteristics could not be defined

### getModels

    public Model[] getModels()
                      throws CloneNotSupportedException

  Returns the a deep copy of the models.

  Returns:
    an array of `AbstractModel`s
  Throws:
    `CloneNotSupportedException`

### getNumberOfModels

    public int getNumberOfModels()

  This method returns the number of models in the CompositeModel

  Returns:
    the number of models

### getLogPriorTerm

    public double getLogPriorTerm()
                           throws Exception

  Description copied from interface: `Model`
  Returns a value that is proportional to the log of the prior. For ML 0 should be returned.

  Returns:
    a value that is proportional to the log of the prior
  Throws:
    `Exception` - if something went wrong
  See Also:
    `Model.getPriorTerm()`

### getProbFor

    public double getProbFor(Sequence sequence,
                             int startpos,
                             int endpos)
                      throws NotTrainedException,
                             Exception

  Description copied from interface: `Model`
  Returns the probability of the given sequence given the model. If a least one random variable is continuous the value of density function is returned.
  It extends the possibility given by the method getProbFor(Sequence sequence, int startpos) by the fact, that the model could be e.g. homogeneous and therefore the length of the sequences, whose probability should be returned, is not fixed. Additionally the end position of the part of the given sequence is given and the probability of the part from position `startpos` to `endpos` (inclusive) should be returned.
  The `length` and `alphabets` define the type of data that can be modeled and therefore both has to be checked.

  Parameters:
    `sequence` - the sequence
    `startpos` - the start position
    `endpos` - the last position to be taken into account
  Returns:
    the probability or the value of the density function of the part of the given sequence given the model
  Throws:
    `NotTrainedException` - a NotTrainedException should be thrown if the model is not trained yet.
    `Exception` - an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos > sequence.length, ...) by the model

### getLogProbFor

    public double getLogProbFor(Sequence sequence,
                                int startpos,
                                int endpos)
                         throws NotTrainedException,
                                Exception

  Description copied from interface: `Model`
  Returns the logarithm of the probability of the given sequence given the model. If a least one random variable is continuous the value of density function is returned.
  For more details see `Model.getProbFor(Sequence, int, int)`

  Specified by:
    `getLogProbFor` in interface `Model`
  Overrides:
    `getLogProbFor` in class `AbstractModel`
  Parameters:
    `sequence` - the sequence
    `startpos` - the start position
    `endpos` - the last position to be taken into account
  Returns:
    the logarithm of probability or the value of the density function of the part of the given sequence given the model
  Throws:
    `NotTrainedException` - a NotTrainedException should be thrown if the model is not trained yet.
    `Exception` - an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos > sequence.length, ...) by the model
  See Also:
    `Model.getProbFor(Sequence, int, int)`

### isTrained

    public boolean isTrained()

  Description copied from interface: `Model`
  Returns true if the model has been trained successfully, false otherwise.

  Returns:
    true if the model has been trained successfully, false otherwise.

### fromXML

    public void fromXML(StringBuffer representation)
                 throws NonParsableException

  Description copied from class: `AbstractModel`
  This method should only be used by the constructor that works on StringBuffer. It is the counter part of `toXML()`.

  Specified by:
    `fromXML` in class `AbstractModel`
  Parameters:
    `representation` - the representation
  Throws:
    `NonParsableException` - if the StringBuffer is not parsable or the representation is conflicting
  See Also:
    `AbstractModel.AbstractModel(StringBuffer)`

### toXML

    public StringBuffer toXML()

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

  Returns:
    the XML-representation

### train

    public void train(Sample data,
                      double[] weights)
               throws Exception

  Description copied from interface: `Model`
  Trains the Model object given the data as `Sample` using the specified weights. The weight at position i belongs to the element at position i. So the array `weight` should have the number of sequences in the sample as dimension. (Optionally it is possible to use `weight == null` if all weights have the value one.)
  This method should work non-incrementally. That means the result of the following series: train(data1); train(data2) should be a fully trained model over data2 and not over data1+data2. All parameters of the model were given by the call of the constructor.

  Parameters:
    `data` - the given sequences
    `weights` - the weights of the elements, each weight should be non-negative
  Throws:
    `Exception` - an Exception should be thrown if the training did not succeed (e.g. the weights dimension of weights and number of samples does not match).
  See Also:
    `Sample.getElementAt(int)`, `Sample.ElementEnumerator`

### toString

    public String toString()

  Description copied from interface: `Model`
  Should give a simple representation (text) of the model as String.

  Specified by:
    `toString` in interface `Model`
  Overrides:
    `toString` in class `Object`
  Returns:
    the representation as String

### set

    protected void set(AlphabetContainer abc)

  Description copied from class: `AbstractModel`
  This method should only be invoked by the method `setNewAlphabetContainerInstance( AlphabetContainer )` and not be made public.
  It enables you to do more with the method `setNewAlphabetContainerInstance( AlphabetContainer )`, e.g. setting a new AlphabetContainer instance for subcomponents.

  Overrides:
    `set` in class `AbstractModel`
  Parameters:
    `abc` - the new instance

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