de.jstacs.models.discrete
Class DiscreteGraphicalModel

java.lang.Object
  extended by de.jstacs.models.AbstractModel
      extended by de.jstacs.models.discrete.DiscreteGraphicalModel
All Implemented Interfaces:
InstantiableFromParameterSet, Model, Storable, Cloneable
Direct Known Subclasses:
InhomogeneousDGM

public abstract class DiscreteGraphicalModel
extends AbstractModel
implements InstantiableFromParameterSet

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

Author:
Jens Keilwagen
See Also:
DGMParameterSet

Field Summary
protected  DGMParameterSet 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.models.AbstractModel
alphabets, length
 
Constructor Summary
DiscreteGraphicalModel(DGMParameterSet params)
          The default constructor.
DiscreteGraphicalModel(StringBuffer representation)
          The constructor for a model in xml format.
 
Method Summary
protected  void check(Sequence sequence, int startpos, int endpos)
          Checks some conditions on a sequence.
 DiscreteGraphicalModel 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 StringBuffer.
 DGMParameterSet getCurrentParameterSet()
          Returns the ParameterSet that has been used to instantiate the current instance of the implementing class.
 String getDescription()
          Returns a short description of the model the was given by the user in the parameter set.
 double getESS()
          This method return the ess that is used in this model.
protected abstract  StringBuffer getFurtherModelInfos()
           
protected abstract  String getXMLTag()
           
 boolean isTrained()
          Returns true if the model has been trained successfully, false otherwise.
protected  void set(DGMParameterSet 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 infos with those from the StringBuffer.
 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.
 
Methods inherited from class de.jstacs.models.AbstractModel
emitSample, getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getMaximalMarkovOrder, getPriorTerm, getProbFor, getProbFor, set, setNewAlphabetContainerInstance, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.jstacs.models.Model
getInstanceName, getLogPriorTerm, getNumericalCharacteristics, getProbFor, train
 

Field Detail

params

protected DGMParameterSet params
The current parameter set of the model


trained

protected boolean trained
Indicates whether the model is trained or not

Constructor Detail

DiscreteGraphicalModel

public DiscreteGraphicalModel(DGMParameterSet params)
                       throws CloneNotSupportedException,
                              IllegalArgumentException,
                              NonParsableException
The default constructor.

Parameters:
params - the 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

DiscreteGraphicalModel

public DiscreteGraphicalModel(StringBuffer representation)
                       throws NonParsableException
The constructor for a model in xml format.

Parameters:
representation - the model in xml format
Throws:
NonParsableException - if the StringBuffer could not be parsed
Method Detail

clone

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

getCurrentParameterSet

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

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

getDescription

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

Returns:
a short description

getESS

public final double getESS()
This method return the ess that is used in this model.

Returns:
the ESS

fromXML

protected final 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)

isTrained

public final boolean isTrained()
Description copied from interface: Model
Returns true if the model has been trained successfully, false otherwise.

Specified by:
isTrained in interface Model
Returns:
true if the model has been trained successfully, false otherwise.

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

toXML

public final StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML-representation 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.

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:
the model infos like parameters of the distibution ... in xml format
See Also:
toXML()

getXMLTag

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

setFurtherModelInfos

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

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

set

protected void set(DGMParameterSet 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 - the indicator for the model
Throws:
CloneNotSupportedException - if the parmeterSet could not be cloned
NonParsableException - if the parameters of the model could not be parsed