de.jstacs.sequenceScores.statisticalModels.trainable.discrete
Class DiscreteGraphicalTrainSM

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
      extended by de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM
All Implemented Interfaces:
InstantiableFromParameterSet, SequenceScore, StatisticalModel, TrainableStatisticalModel, Storable, Cloneable
Direct Known Subclasses:
HomogeneousTrainSM, InhomogeneousDGTrainSM

public abstract class DiscreteGraphicalTrainSM
extends AbstractTrainableStatisticalModel
implements InstantiableFromParameterSet

This is the main class for all discrete graphical models (DGM).

Author:
Jens Keilwagen
See Also:
DGTrainSMParameterSet

Field Summary
protected  DGTrainSMParameterSet params
          The current parameter set of the model.
protected  boolean trained
          Indicates whether the model is trained or not.
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
alphabets, length
 
Constructor Summary
DiscreteGraphicalTrainSM(DGTrainSMParameterSet params)
          The default constructor.
DiscreteGraphicalTrainSM(StringBuffer representation)
          The standard constructor for the interface Storable.
 
Method Summary
protected  void check(Sequence sequence, int startpos, int endpos)
          Checks some conditions on a Sequence.
 DiscreteGraphicalTrainSM clone()
          Follows the conventions of Object's clone()-method.
protected  void fromXML(StringBuffer representation)
          This method should only be used by the constructor that works on a StringBuffer.
 DGTrainSMParameterSet getCurrentParameterSet()
          Returns the InstanceParameterSet that has been used to instantiate the current instance of the implementing class.
 String getDescription()
          Returns a short description of the model that was given by the user in the parameter set.
 double getESS()
          This method returns the ess (equivalent sample size) that is used in this model.
protected abstract  StringBuffer getFurtherModelInfos()
          Returns further model information as a StringBuffer.
protected abstract  String getXMLTag()
          Returns the XML tag that is used for this model in fromXML(StringBuffer) and toXML().
 boolean isInitialized()
          This method can be used to determine whether the instance is initialized.
protected  void set(DGTrainSMParameterSet params, boolean trained)
          Sets the parameters as internal parameters and does some essential computations.
protected abstract  void setFurtherModelInfos(StringBuffer xml)
          This method replaces the internal model information with those from a StringBuffer.
 String toString(NumberFormat nf)
          This method returns a String representation of the instance.
 StringBuffer toXML()
          This method returns an XML representation as StringBuffer of an instance of the implementing class.
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
emitDataSet, getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getMaximalMarkovOrder, toString, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.trainable.TrainableStatisticalModel
train
 
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.StatisticalModel
getLogPriorTerm, getLogProbFor
 
Methods inherited from interface de.jstacs.sequenceScores.SequenceScore
getInstanceName, getNumericalCharacteristics
 

Field Detail

params

protected DGTrainSMParameterSet params
The current parameter set of the model.


trained

protected boolean trained
Indicates whether the model is trained or not.

Constructor Detail

DiscreteGraphicalTrainSM

public DiscreteGraphicalTrainSM(DGTrainSMParameterSet params)
                         throws CloneNotSupportedException,
                                IllegalArgumentException,
                                NonParsableException
The default constructor. Creates a new DiscreteGraphicalTrainSM from a given DGTrainSMParameterSet.

Parameters:
params - the given parameter set
Throws:
CloneNotSupportedException - if the parameter set could not be cloned
IllegalArgumentException - if the parameter set is not instantiated
NonParsableException - if the parameter set is not parsable
See Also:
AbstractTrainableStatisticalModel.AbstractTrainableStatisticalModel(de.jstacs.data.AlphabetContainer, int)

DiscreteGraphicalTrainSM

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

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

clone

public DiscreteGraphicalTrainSM clone()
                               throws CloneNotSupportedException
Description copied from class: AbstractTrainableStatisticalModel
Follows the conventions of Object's clone()-method.

Specified by:
clone in interface SequenceScore
Specified by:
clone in interface TrainableStatisticalModel
Overrides:
clone in class AbstractTrainableStatisticalModel
Returns:
an object, that is a copy of the current AbstractTrainableStatisticalModel (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 AbstractTrainableStatisticalModel. 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 - if something went wrong while cloning

getCurrentParameterSet

public final DGTrainSMParameterSet getCurrentParameterSet()
                                                   throws Exception
Description copied from interface: InstantiableFromParameterSet
Returns the InstanceParameterSet that has been used to instantiate the current instance of the implementing class. If the current instance was not created using an InstanceParameterSet, an equivalent InstanceParameterSet should be returned, so that an instance created using this InstanceParameterSet would be in principle equal to the current instance.

Specified by:
getCurrentParameterSet in interface InstantiableFromParameterSet
Returns:
the current InstanceParameterSet
Throws:
Exception - if the InstanceParameterSet could not be returned

getDescription

public final String getDescription()
Returns a short description of the model that was given by the user in the parameter set.

Returns:
a short description of the model

getESS

public final double getESS()
This method returns the ess (equivalent sample size) that is used in this model.

Returns:
the ess

fromXML

protected final void fromXML(StringBuffer representation)
                      throws NonParsableException
Description copied from class: AbstractTrainableStatisticalModel
This method should only be used by the constructor that works on a StringBuffer. It is the counter part of Storable.toXML().

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

isInitialized

public final boolean isInitialized()
Description copied from interface: SequenceScore
This method can be used to determine whether the instance is initialized. If the instance is initialized you should be able to invoke SequenceScore.getLogScoreFor(Sequence).

Specified by:
isInitialized in interface SequenceScore
Returns:
true if the instance is initialized, false otherwise

toString

public String toString(NumberFormat nf)
Description copied from interface: SequenceScore
This method returns a String representation of the instance.

Specified by:
toString in interface SequenceScore
Parameters:
nf - the NumberFormat for the String representation of parameters or probabilities
Returns:
a String representation of the instance

toXML

public final 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

check

protected void check(Sequence sequence,
                     int startpos,
                     int endpos)
              throws NotTrainedException,
                     IllegalArgumentException
Checks some conditions on a Sequence. These are in general conditions on the AlphabetContainer of a (sub) Sequence between startpos und endpos.

Overrides:
check in class AbstractTrainableStatisticalModel
Parameters:
sequence - the Sequence
startpos - the startposition
endpos - the endposition
Throws:
NotTrainedException - if the model is not trained
IllegalArgumentException - if some constraints are not fulfilled

getFurtherModelInfos

protected abstract StringBuffer getFurtherModelInfos()
Returns further model information as a StringBuffer.

Returns:
further model information like parameters of the distribution etc. in XML format
See Also:
toXML()

getXMLTag

protected abstract String getXMLTag()
Returns the XML tag that is used for this model in fromXML(StringBuffer) and toXML().

Returns:
the XML tag that is used in fromXML(StringBuffer) and toXML()
See Also:
fromXML(StringBuffer), toXML()

setFurtherModelInfos

protected abstract void setFurtherModelInfos(StringBuffer xml)
                                      throws NonParsableException
This method replaces the internal model information with those from a StringBuffer.

Parameters:
xml - contains the model information like parameters of the distribution etc. in XML format
Throws:
NonParsableException - if the StringBuffer could not be parsed
See Also:
fromXML(StringBuffer)

set

protected void set(DGTrainSMParameterSet params,
                   boolean trained)
            throws CloneNotSupportedException,
                   NonParsableException
Sets the parameters as internal parameters and does some essential computations. Used in fromParameterSet-methods.

Parameters:
params - the new ParameterSet
trained - indicates if the model is trained or not
Throws:
CloneNotSupportedException - if the parameter set could not be cloned
NonParsableException - if the parameters of the model could not be parsed