de.jstacs.models.discrete.inhomogeneous.shared
Class SharedStructureMixture

java.lang.Object
  extended by de.jstacs.models.AbstractModel
      extended by de.jstacs.models.mixture.AbstractMixtureModel
          extended by de.jstacs.models.mixture.MixtureModel
              extended by de.jstacs.models.discrete.inhomogeneous.shared.SharedStructureMixture
All Implemented Interfaces:
Model, Storable, Cloneable

public class SharedStructureMixture
extends MixtureModel

This class handles a mixture of models with the same structure that are learned via EM. One well known example are mixture of trees.

Author:
Jens Keilwagen

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.models.mixture.AbstractMixtureModel
AbstractMixtureModel.Algorithm, AbstractMixtureModel.Parameterization
 
Field Summary
 
Fields inherited from class de.jstacs.models.mixture.AbstractMixtureModel
algorithm, algorithmHasBeenRun, alternativeModel, burnInTest, componentHyperParams, compProb, counter, dimension, estimateComponentProbs, file, filereader, filewriter, initialIteration, logWeights, model, optimizeModel, sample, samplingIndex, sostream, starts, stationaryIteration, weights
 
Fields inherited from class de.jstacs.models.AbstractModel
alphabets, length
 
Constructor Summary
protected SharedStructureMixture(FSDAGModel[] m, StructureLearner.ModelType model, byte order, int starts, boolean estimateComponentProbs, double[] weights, double alpha, double epsilon)
          This constructor is used from the other main constructors.
  SharedStructureMixture(FSDAGModel[] m, StructureLearner.ModelType model, byte order, int starts, double[] weights, double alpha, double epsilon)
          This main constructor creates an instance with fixed component weights.
  SharedStructureMixture(FSDAGModel[] m, StructureLearner.ModelType model, byte order, int starts, double alpha, double epsilon)
          This main constructor creates an instance which estimates the component probabilities.
  SharedStructureMixture(StringBuffer xml)
          The constructor for the Storable interface.
 
Method Summary
 SharedStructureMixture 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.
 String getInstanceName()
          Should return a short instance name such as iMM(0), BN(2), ...
protected  void getNewParameters(int iteration, double[][] seqWeights, double[] w)
          This method trains the internal models on the internal sample and the given weights.
 String getStructure()
           
 StringBuffer toXML()
          This method returns an XML-representation of an instance of the implementing class.
 
Methods inherited from class de.jstacs.models.mixture.MixtureModel
doFirstIteration, doFirstIteration, emitSampleUsingCurrentParameterSet, getLogProbUsingCurrentParameterSetFor, getNewWeights, setTrainData, toString
 
Methods inherited from class de.jstacs.models.mixture.AbstractMixtureModel
algorithmHasBeenRun, checkLength, checkModelsForGibbsSampling, continueIterations, continueIterations, createSeqWeightsArray, doFirstIteration, doFirstIteration, draw, emitSample, extendSampling, extractFurtherInformation, finalize, getCharacteristics, getFurtherInformation, getIndexOfMaximalComponentFor, getLogPriorTerm, getLogPriorTermForComponentProbs, getLogProbFor, getLogProbFor, getLogProbFor, getModel, getModels, getMRG, getMRGParams, getNameOfAlgorithm, getNewComponentProbs, getNewParametersForModel, getNumberOfComponents, getNumericalCharacteristics, getProbFor, getScoreForBestRun, getWeights, initModelForSampling, initWithPrior, isInSamplingMode, isTrained, iterate, iterate, max, modifyWeights, parseNextParameterSet, parseParameterSet, samplingStopped, set, setAlpha, setOutputStream, setThreshold, setWeights, swap, train
 
Methods inherited from class de.jstacs.models.AbstractModel
getAlphabetContainer, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getMaximalMarkovOrder, getPriorTerm, getProbFor, getProbFor, setNewAlphabetContainerInstance, train
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SharedStructureMixture

public SharedStructureMixture(FSDAGModel[] m,
                              StructureLearner.ModelType model,
                              byte order,
                              int starts,
                              double alpha,
                              double epsilon)
                       throws IllegalArgumentException,
                              WrongAlphabetException,
                              CloneNotSupportedException
This main constructor creates an instance which estimates the component probabilities.

Parameters:
m - the single models building the Mixture
model - the model type
order - the model order
starts - the number of times the algorithm will be started in the train method, at least 1
alpha - the positive parameter for the Dirichlet which is used when you invoke train to initialize the gammas. It is recommended to use alpha = 1 (uniform distribution on a simplex).
epsilon - the non-negative threshold for stopping the EM-algorithm
Throws:
IllegalArgumentException - if
  • the models are not able to score the sequences of same length
  • dimension < 1
  • weights != null && weights.length != dimension
  • weights != null and it exists an i where weights[i] < 0
  • starts < 1
  • componentHyperParams are not correct
WrongAlphabetException - if not all models work on the same alphabet
CloneNotSupportedException - if the models can not be cloned

SharedStructureMixture

public SharedStructureMixture(FSDAGModel[] m,
                              StructureLearner.ModelType model,
                              byte order,
                              int starts,
                              double[] weights,
                              double alpha,
                              double epsilon)
                       throws IllegalArgumentException,
                              WrongAlphabetException,
                              CloneNotSupportedException
This main constructor creates an instance with fixed component weights.

Parameters:
m - the single models building the Mixture
model - the model type
order - the model order
starts - the number of times the algorithm will be started in the train method, at least 1
weights - null or the weights for the components (than weights.length == models.length)
alpha - the positive parameter for the Dirichlet which is used when you invoke train to initialize the gammas. It is recommended to use alpha = 1 (uniform distribution on a simplex).
epsilon - the non-negative threshold for stopping the EM-algorithm
Throws:
IllegalArgumentException - if
  • the models are not able to score the sequences of same length
  • dimension < 1
  • weights != null && weights.length != dimension
  • weights != null and it exists an i where weights[i] < 0
  • starts < 1
  • componentHyperParams are not correct
WrongAlphabetException - if not all models work on the same alphabet
CloneNotSupportedException - if the models can not be cloned

SharedStructureMixture

protected SharedStructureMixture(FSDAGModel[] m,
                                 StructureLearner.ModelType model,
                                 byte order,
                                 int starts,
                                 boolean estimateComponentProbs,
                                 double[] weights,
                                 double alpha,
                                 double epsilon)
                          throws IllegalArgumentException,
                                 WrongAlphabetException,
                                 CloneNotSupportedException
This constructor is used from the other main constructors.

Parameters:
m - the single models building the Mixture
model - the model type
order - the model order
starts - the number of times the algorithm will be started in the train method, at least 1
estimateComponentProbs - the switch for estimating the component probabilities in the algorithm or to hold them fixed; if the component parameters are fixed, the values of weights will be used, otherwise the componentHyperParams will be incorporated in the adjustment
weights - null or the weights for the components (than weights.length == models.length)
alpha - the positive parameter for the Dirichlet which is used when you invoke train to initialize the gammas. It is recommended to use alpha = 1 (uniform distribution on a simplex).
epsilon - the non-negative threshold for stopping the EM-algorithm
Throws:
IllegalArgumentException - if
  • the models are not able to score the sequences of same length
  • dimension < 1
  • weights != null && weights.length != dimension
  • weights != null and it exists an i where weights[i] < 0
  • starts < 1
  • componentHyperParams are not correct
WrongAlphabetException - if not all models work on the same alphabet
CloneNotSupportedException - if the models can not be cloned

SharedStructureMixture

public SharedStructureMixture(StringBuffer xml)
                       throws NonParsableException
The constructor for the Storable interface.

Parameters:
xml - the StringBuffer
Throws:
NonParsableException - if the StringBuffer is not parsable
Method Detail

clone

public SharedStructureMixture 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 AbstractMixtureModel
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

getStructure

public String getStructure()
                    throws NotTrainedException
Returns:
a string representation of the structure of the used models
Throws:
NotTrainedException - if the classifier is not trained yet

getInstanceName

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

Specified by:
getInstanceName in interface Model
Overrides:
getInstanceName in class AbstractMixtureModel
Returns:
a short instance name

toXML

public 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
Overrides:
toXML in class AbstractMixtureModel
Returns:
the XML-representation

fromXML

protected 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().

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

getNewParameters

protected void getNewParameters(int iteration,
                                double[][] seqWeights,
                                double[] w)
                         throws Exception
Description copied from class: AbstractMixtureModel
This method trains the internal models on the internal sample and the given weights.

Overrides:
getNewParameters in class AbstractMixtureModel
Parameters:
iteration - the number this method has been invoked
seqWeights - the weights for each model and sequence
w - the weights for the components
Throws:
Exception - if the training of the internal models went wrong