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

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

public class FSDAGTrainSM
extends DAGTrainSM

This class can be used for any discrete fixed structure directed acyclic graphical model ( FSDAGTrainSM).

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.DAGTrainSM
constraints
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhomogeneousDGTrainSM
DEFAULT_STREAM, sostream
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM
params, trained
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
alphabets, length
 
Constructor Summary
FSDAGTrainSM(FSDAGTrainSMParameterSet params)
          This is the main constructor.
FSDAGTrainSM(StringBuffer xml)
          The standard constructor for the interface Storable.
 
Method Summary
 void drawParameters(DataSet data, double[] weights, int[][] graph)
          This method draws the parameters of the model from the a posteriori density.
 String getInstanceName()
          Should return a short instance name such as iMM(0), BN(2), ...
 byte getMaximalMarkovOrder()
          This method returns the maximal used Markov order, if possible.
 String getStructure()
          Returns a String representation of the underlying graph.
protected  String getXMLTag()
          Returns the XML tag that is used for this model in DiscreteGraphicalTrainSM.fromXML(StringBuffer) and DiscreteGraphicalTrainSM.toXML().
protected  void set(DGTrainSMParameterSet params, boolean trained)
          Sets the parameters as internal parameters and does some essential computations.
 void train(DataSet data, double[] weights)
          Trains the TrainableStatisticalModel object given the data as DataSet using the specified weights.
 void train(DataSet data, double[] weights, int[][] graph)
          Computes the model with structure graph.
static void train(TrainableStatisticalModel[] models, int[][] graph, double[][] weights, DataSet... data)
          Computes the models with structure graph.
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.DAGTrainSM
checkAcyclic, clone, createConstraints, drawParameters, emitDataSet, estimateParameters, getFurtherModelInfos, getLogPriorTerm, getLogProbFor, getNumericalCharacteristics, setFurtherModelInfos, toString
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhomogeneousDGTrainSM
check, setOutputStream
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM
fromXML, getCurrentParameterSet, getDescription, getESS, isInitialized, toXML
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, toString, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSDAGTrainSM

public FSDAGTrainSM(FSDAGTrainSMParameterSet params)
             throws CloneNotSupportedException,
                    IllegalArgumentException,
                    NonParsableException
This is the main constructor. It creates a new FSDAGTrainSM from the given FSDAGTrainSMParameterSet.

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:
DAGTrainSM.DAGTrainSM(de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.parameters.IDGTrainSMParameterSet)

FSDAGTrainSM

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

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

getInstanceName

public String getInstanceName()
Description copied from interface: SequenceScore
Should return a short instance name such as iMM(0), BN(2), ...

Returns:
a short instance name

getMaximalMarkovOrder

public byte getMaximalMarkovOrder()
Description copied from interface: StatisticalModel
This method returns the maximal used Markov order, if possible.

Specified by:
getMaximalMarkovOrder in interface StatisticalModel
Overrides:
getMaximalMarkovOrder in class AbstractTrainableStatisticalModel
Returns:
maximal used Markov order

getXMLTag

protected String getXMLTag()
Description copied from class: DiscreteGraphicalTrainSM
Returns the XML tag that is used for this model in DiscreteGraphicalTrainSM.fromXML(StringBuffer) and DiscreteGraphicalTrainSM.toXML().

Specified by:
getXMLTag in class DiscreteGraphicalTrainSM
Returns:
the XML tag that is used in DiscreteGraphicalTrainSM.fromXML(StringBuffer) and DiscreteGraphicalTrainSM.toXML()
See Also:
DiscreteGraphicalTrainSM.fromXML(StringBuffer), DiscreteGraphicalTrainSM.toXML()

train

public void train(DataSet data,
                  double[] weights)
           throws Exception
Description copied from interface: TrainableStatisticalModel
Trains the TrainableStatisticalModel object given the data as DataSet 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 data set 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 as DataSet
weights - the weights of the elements, each weight should be non-negative
Throws:
Exception - if the training did not succeed (e.g. the dimension of weights and the number of sequences in the data set do not match)
See Also:
DataSet.getElementAt(int), DataSet.ElementEnumerator

train

public void train(DataSet data,
                  double[] weights,
                  int[][] graph)
           throws Exception
Computes the model with structure graph.

Parameters:
data - the DataSet
weights - the weights for the sequences in the DataSet
graph - the graph
Throws:
Exception - if something went wrong

drawParameters

public void drawParameters(DataSet data,
                           double[] weights,
                           int[][] graph)
                    throws Exception
This method draws the parameters of the model from the a posteriori density. For drawing from the prior you have to set the data and their weights to null. Furthermore this method enables you to specify a new graph structure.

Parameters:
data - a DataSet or null
weights - the (positive) weights for each sequence of the DataSet or null
graph - the graph or null for the current graph
Throws:
Exception - if something went wrong
See Also:
DAGTrainSM.drawParameters(DataSet, double[]), DAGTrainSM.checkAcyclic(int, int[][])

train

public static void train(TrainableStatisticalModel[] models,
                         int[][] graph,
                         double[][] weights,
                         DataSet... data)
                  throws Exception
Computes the models with structure graph.

Parameters:
models - an array of AbstractTrainableStatisticalModels containing only instances of FSDAGTrainSM
data - the DataSet
weights - the weights for the sequences in the DataSet
graph - the graph
Throws:
Exception - if something went wrong

set

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

Overrides:
set in class InhomogeneousDGTrainSM
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

getStructure

public String getStructure()
Description copied from class: InhomogeneousDGTrainSM
Returns a String representation of the underlying graph.

Overrides:
getStructure in class DAGTrainSM
Returns:
a String representation of the underlying graph