de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif
Class MixtureDurationDiffSM

java.lang.Object
  extended by de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore
      extended by de.jstacs.sequenceScores.statisticalModels.differentiable.AbstractDifferentiableStatisticalModel
          extended by de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.PositionDiffSM
              extended by de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.DurationDiffSM
                  extended by de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.MixtureDurationDiffSM
All Implemented Interfaces:
DifferentiableSequenceScore, SequenceScore, DifferentiableStatisticalModel, StatisticalModel, Storable, Cloneable

public class MixtureDurationDiffSM
extends DurationDiffSM

This class implements a mixture of DurationDiffSMs.

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.DurationDiffSM
delta, ess, max, min
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.PositionDiffSM
internal
 
Fields inherited from class de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore
alphabets, length, r
 
Fields inherited from interface de.jstacs.sequenceScores.differentiable.DifferentiableSequenceScore
UNKNOWN
 
Constructor Summary
MixtureDurationDiffSM(int starts, DurationDiffSM... function)
          The main constructor of a MixtureDurationDiffSM.
MixtureDurationDiffSM(StringBuffer source)
          This is the constructor for Storable.
 
Method Summary
 void addGradientOfLogPriorTerm(double[] grad, int start)
          This method computes the gradient of DifferentiableStatisticalModel.getLogPriorTerm() for each parameter of this model.
 void adjust(int[] length, double[] weight)
          This method adjust the parameter based on the given statistic.
 MixtureDurationDiffSM clone()
          Creates a clone (deep copy) of the current DifferentiableSequenceScore instance.
protected  void fromXML(StringBuffer rep)
          This method is called in the constructor for the Storable interface to create a scoring function from a StringBuffer.
 double[] getCurrentParameterValues()
          Returns a double array of dimension DifferentiableSequenceScore.getNumberOfParameters() containing the current parameter values.
 String getInstanceName()
          Should return a short instance name such as iMM(0), BN(2), ...
 double getLogPriorTerm()
          This method computes a value that is proportional to
 double getLogScore(int... values)
          This method enables the user to get the log-score without using a sequence object.
 double getLogScoreAndPartialDerivation(IntList indices, DoubleList partialDer, int... values)
          This method enables the user to get the log-score and the partial derivations without using a sequence object.
 int getNumberOfParameters()
          Returns the number of parameters in this DifferentiableSequenceScore.
 int getNumberOfRecommendedStarts()
          This method returns the number of recommended optimization starts.
protected  String getRNotation(String distributionName, NumberFormat nf)
          This method returns the distribution in R notation.
 void initializeFunction(int index, boolean freeParams, DataSet[] data, double[][] weights)
          This method creates the underlying structure of the DifferentiableSequenceScore.
 void initializeFunctionRandomly(boolean freeParams)
          This method initializes the DifferentiableSequenceScore randomly.
 void initializeUniformly()
          This method set special parameters that lead to an uniform distribution.
 boolean isInitialized()
          This method can be used to determine whether the instance is initialized.
 boolean isNormalized()
          This method indicates whether the implemented score is already normalized to 1 or not.
 void modify(int delta)
          This method modifies the underlying AlphabetContainer.
 void setParameters(double[] params, int start)
          This method sets the internal parameters to the values of params between start and start + DifferentiableSequenceScore.getNumberOfParameters() - 1
 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.differentiable.mixture.motif.DurationDiffSM
getESS, getLogNormalizationConstant, getLogPartialNormalizationConstant, getMax, getMin, getNumberOfPossibilities, getSizeOfEventSpaceForRandomVariablesOfParameter, isPossible, next, reset, toString
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.motif.PositionDiffSM
getInternalPosition, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivationForInternal, getLogScoreFor, getLogScoreForInternal, getValuesFromSequence
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.differentiable.AbstractDifferentiableStatisticalModel
emitDataSet, getInitialClassParam, getLogProbFor, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getMaximalMarkovOrder, isNormalized
 
Methods inherited from class de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore
getAlphabetContainer, getCharacteristics, getLength, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation, getLogScoreFor, getLogScoreFor, getNumberOfStarts, getNumericalCharacteristics
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jstacs.sequenceScores.differentiable.DifferentiableSequenceScore
getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation
 
Methods inherited from interface de.jstacs.sequenceScores.SequenceScore
getAlphabetContainer, getCharacteristics, getLength, getLogScoreFor, getLogScoreFor, getNumericalCharacteristics
 

Constructor Detail

MixtureDurationDiffSM

public MixtureDurationDiffSM(int starts,
                             DurationDiffSM... function)
                      throws WrongAlphabetException,
                             CloneNotSupportedException,
                             IllegalArgumentException
The main constructor of a MixtureDurationDiffSM.

Parameters:
starts - the number of recommended starts
function - the DurationDiffSMs for the components
Throws:
CloneNotSupportedException - if at least one element of functions could not be cloned
IllegalArgumentException - if the starts is smaller than zero (0)
WrongAlphabetException - if at least one element of function has an AlphabetContainer that is not equal to those of the other elements of function

MixtureDurationDiffSM

public MixtureDurationDiffSM(StringBuffer source)
                      throws NonParsableException
This is the constructor for Storable. Creates a new MixtureDurationDiffSM out of a StringBuffer.

Parameters:
source - the XML representation as StringBuffer
Throws:
NonParsableException - if the XML representation could not be parsed
Method Detail

clone

public MixtureDurationDiffSM clone()
                            throws CloneNotSupportedException
Description copied from interface: DifferentiableSequenceScore
Creates a clone (deep copy) of the current DifferentiableSequenceScore instance.

Specified by:
clone in interface DifferentiableSequenceScore
Specified by:
clone in interface SequenceScore
Overrides:
clone in class PositionDiffSM
Returns:
the cloned instance of the current DifferentiableSequenceScore
Throws:
CloneNotSupportedException - if something went wrong while cloning the DifferentiableSequenceScore

adjust

public void adjust(int[] length,
                   double[] weight)
Description copied from class: DurationDiffSM
This method adjust the parameter based on the given statistic.

Specified by:
adjust in class DurationDiffSM
Parameters:
length - an array containing length values
weight - an array containing corresponding weight values

getLogScore

public double getLogScore(int... values)
Description copied from class: PositionDiffSM
This method enables the user to get the log-score without using a sequence object.

Specified by:
getLogScore in class PositionDiffSM
Parameters:
values - the values
Returns:
the score

getLogScoreAndPartialDerivation

public double getLogScoreAndPartialDerivation(IntList indices,
                                              DoubleList partialDer,
                                              int... values)
Description copied from class: PositionDiffSM
This method enables the user to get the log-score and the partial derivations without using a sequence object.

Specified by:
getLogScoreAndPartialDerivation in class PositionDiffSM
Parameters:
indices - a list for the indices of the parameters
partialDer - a list of the partial derivations
values - the values
Returns:
the score

addGradientOfLogPriorTerm

public void addGradientOfLogPriorTerm(double[] grad,
                                      int start)
                               throws Exception
Description copied from interface: DifferentiableStatisticalModel
This method computes the gradient of DifferentiableStatisticalModel.getLogPriorTerm() for each parameter of this model. The results are added to the array grad beginning at index start.

Parameters:
grad - the array of gradients
start - the start index in the grad array, where the partial derivations for the parameters of this models shall be entered
Throws:
Exception - if something went wrong with the computing of the gradients
See Also:
DifferentiableStatisticalModel.getLogPriorTerm()

getLogPriorTerm

public double getLogPriorTerm()
Description copied from interface: DifferentiableStatisticalModel
This method computes a value that is proportional to

DifferentiableStatisticalModel.getESS() * DifferentiableStatisticalModel.getLogNormalizationConstant() + Math.log( prior )

where prior is the prior for the parameters of this model.

Returns:
a value that is proportional to DifferentiableStatisticalModel.getESS() * DifferentiableStatisticalModel.getLogNormalizationConstant() + Math.log( prior ).
See Also:
DifferentiableStatisticalModel.getESS(), DifferentiableStatisticalModel.getLogNormalizationConstant()

getCurrentParameterValues

public double[] getCurrentParameterValues()
                                   throws Exception
Description copied from interface: DifferentiableSequenceScore
Returns a double array of dimension DifferentiableSequenceScore.getNumberOfParameters() containing the current parameter values. If one likes to use these parameters to start an optimization it is highly recommended to invoke DifferentiableSequenceScore.initializeFunction(int, boolean, DataSet[], double[][]) before. After an optimization this method can be used to get the current parameter values.

Returns:
the current parameter values
Throws:
Exception - if no parameters exist (yet)

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

getNumberOfParameters

public int getNumberOfParameters()
Description copied from interface: DifferentiableSequenceScore
Returns the number of parameters in this DifferentiableSequenceScore. If the number of parameters is not known yet, the method returns DifferentiableSequenceScore.UNKNOWN.

Returns:
the number of parameters in this DifferentiableSequenceScore
See Also:
DifferentiableSequenceScore.UNKNOWN

initializeFunction

public void initializeFunction(int index,
                               boolean freeParams,
                               DataSet[] data,
                               double[][] weights)
                        throws Exception
Description copied from interface: DifferentiableSequenceScore
This method creates the underlying structure of the DifferentiableSequenceScore.

Parameters:
index - the index of the class the DifferentiableSequenceScore models
freeParams - indicates whether the (reduced) parameterization is used
data - the data sets
weights - the weights of the sequences in the data sets
Throws:
Exception - if something went wrong

initializeUniformly

public void initializeUniformly()
Description copied from class: DurationDiffSM
This method set special parameters that lead to an uniform distribution.

Specified by:
initializeUniformly in class DurationDiffSM

initializeFunctionRandomly

public void initializeFunctionRandomly(boolean freeParams)
                                throws Exception
Description copied from interface: DifferentiableSequenceScore
This method initializes the DifferentiableSequenceScore randomly. It has to create the underlying structure of the DifferentiableSequenceScore.

Parameters:
freeParams - indicates whether the (reduced) parameterization is used
Throws:
Exception - if something went wrong

isInitialized

public 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).

Returns:
true if the instance is initialized, false otherwise

isNormalized

public boolean isNormalized()
Description copied from interface: DifferentiableStatisticalModel
This method indicates whether the implemented score is already normalized to 1 or not. The standard implementation returns false.

Specified by:
isNormalized in interface DifferentiableStatisticalModel
Overrides:
isNormalized in class AbstractDifferentiableStatisticalModel
Returns:
true if the implemented score is already normalized to 1, false otherwise

setParameters

public void setParameters(double[] params,
                          int start)
Description copied from interface: DifferentiableSequenceScore
This method sets the internal parameters to the values of params between start and start + DifferentiableSequenceScore.getNumberOfParameters() - 1

Parameters:
params - the new parameters
start - the start index in params

getRNotation

protected String getRNotation(String distributionName,
                              NumberFormat nf)
Description copied from class: DurationDiffSM
This method returns the distribution in R notation.

Specified by:
getRNotation in class DurationDiffSM
Parameters:
distributionName - the name of the distribution, e.g., "p"
nf - the NumberFormat to be used, can be null
Returns:
the distribution in R notation
See Also:
REnvironment

modify

public void modify(int delta)
Description copied from class: DurationDiffSM
This method modifies the underlying AlphabetContainer. This might be necessary if the motif length changed.

Overrides:
modify in class DurationDiffSM
Parameters:
delta - the change
See Also:
Mutable.modify(int, int), MutableMotifDiscoverer.modifyMotif(int, int, int)

getNumberOfRecommendedStarts

public int getNumberOfRecommendedStarts()
Description copied from interface: DifferentiableSequenceScore
This method returns the number of recommended optimization starts. The standard implementation returns 1.

Specified by:
getNumberOfRecommendedStarts in interface DifferentiableSequenceScore
Overrides:
getNumberOfRecommendedStarts in class AbstractDifferentiableSequenceScore
Returns:
the number of recommended optimization starts

fromXML

protected void fromXML(StringBuffer rep)
                throws NonParsableException
Description copied from class: AbstractDifferentiableSequenceScore
This method is called in the constructor for the Storable interface to create a scoring function from a StringBuffer.

Overrides:
fromXML in class DurationDiffSM
Parameters:
rep - the XML representation as StringBuffer
Throws:
NonParsableException - if the StringBuffer could not be parsed
See Also:
AbstractDifferentiableSequenceScore.AbstractDifferentiableSequenceScore(StringBuffer)

toXML

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