de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.emissions.continuous
Class MultivariateGaussianEmission

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.emissions.continuous.MultivariateGaussianEmission
All Implemented Interfaces:
Emission, Storable, Cloneable

public class MultivariateGaussianEmission
extends Object
implements Emission

Multivariate Gaussian emission density for a Hidden Markov Model.

Author:
Michael Seifert, Jens Keilwagen

Field Summary
protected  HashMap<Sequence,double[]> gammas
          Contains the emission sequences and corresponding gammas (state-posteriors) required for the estimation of the standard deviation.
 
Constructor Summary
MultivariateGaussianEmission(double[] mean, double[] sds, double[][] correlation, double scaleMean, double[] aprioriMean, double shapeSd, double[][] scaleSd)
          Creates a Multivariate Gaussian emission density.
MultivariateGaussianEmission(StringBuffer xml)
          Creates a MultivariateGaussianEmission from its XML representation.
 
Method Summary
 void addToStatistic(boolean forward, int startPos, int endPos, double weight, Sequence seq)
          This method adds the weight to the internal sufficient statistic.
 MultivariateGaussianEmission clone()
           
 void estimateFromStatistic()
          This method estimates the parameters from the internal sufficient statistic.
protected  void fromXML(StringBuffer xml)
           
 AlphabetContainer getAlphabetContainer()
          This method returns the AlphabetContainer of this emission.
 double getLogPriorTerm()
          Returns a value that is proportional to the log of the prior.
 double getLogProbFor(boolean forward, int startPos, int endPos, Sequence seq)
          This method computes the logarithm of the likelihood.
 String getNodeLabel(double weight, String name, NumberFormat nf)
          Returns the graphviz label of the node containing this emission.
 String getNodeShape(boolean forward)
          Returns the graphviz string for the shape of the node.
 void initializeFunctionRandomly()
          This method initializes the emission randomly.
 void joinStatistics(Emission... emissions)
          This method joins the statistics of different instances and sets this joined statistic as statistic of each instance.
 void resetStatistic()
          This method resets the internal sufficient statistic.
 void setParameters(Emission t)
          Set values of parameters of the instance to the value of the parameters of the given instance.
 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 java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

gammas

protected HashMap<Sequence,double[]> gammas
Contains the emission sequences and corresponding gammas (state-posteriors) required for the estimation of the standard deviation.

Constructor Detail

MultivariateGaussianEmission

public MultivariateGaussianEmission(double[] mean,
                                    double[] sds,
                                    double[][] correlation,
                                    double scaleMean,
                                    double[] aprioriMean,
                                    double shapeSd,
                                    double[][] scaleSd)
Creates a Multivariate Gaussian emission density.

Parameters:
mean - mean vector
sds - standard deviation vector
correlation - correlation matrix
scaleMean - scale of a priori mean
aprioriMean - a priori mean
shapeSd - scale for scaleSd (a covariance matrix)
scaleSd - a priori covariance matrix

MultivariateGaussianEmission

public MultivariateGaussianEmission(StringBuffer xml)
                             throws NonParsableException
Creates a MultivariateGaussianEmission from its XML representation.

Parameters:
xml - the XML representation.
Throws:
NonParsableException - if the XML representation could not be parsed
Method Detail

addToStatistic

public void addToStatistic(boolean forward,
                           int startPos,
                           int endPos,
                           double weight,
                           Sequence seq)
                    throws OperationNotSupportedException
Description copied from interface: Emission
This method adds the weight to the internal sufficient statistic.

Specified by:
addToStatistic in interface Emission
Parameters:
forward - whether to use the forward or the reverse strand
startPos - the start position
endPos - the end position
weight - the weight of the sequence
seq - the sequence
Throws:
OperationNotSupportedException - if forward=false and the reverse complement of the sequence seq is not defined

joinStatistics

public void joinStatistics(Emission... emissions)
Description copied from interface: Emission
This method joins the statistics of different instances and sets this joined statistic as statistic of each instance. This method might be used for instance in a multi-threaded optimization to join partial statistics.

Specified by:
joinStatistics in interface Emission
Parameters:
emissions - the emissions to be joined

estimateFromStatistic

public void estimateFromStatistic()
Description copied from interface: Emission
This method estimates the parameters from the internal sufficient statistic.

Specified by:
estimateFromStatistic in interface Emission

getAlphabetContainer

public AlphabetContainer getAlphabetContainer()
Description copied from interface: Emission
This method returns the AlphabetContainer of this emission.

Specified by:
getAlphabetContainer in interface Emission
Returns:
the AlphabetContainer of this emission

getLogPriorTerm

public double getLogPriorTerm()
Description copied from interface: Emission
Returns a value that is proportional to the log of the prior. For maximum likelihood (ML) 0 should be returned.

Specified by:
getLogPriorTerm in interface Emission
Returns:
a value that is proportional to the log of the prior
See Also:
StatisticalModel.getLogPriorTerm()

getLogProbFor

public double getLogProbFor(boolean forward,
                            int startPos,
                            int endPos,
                            Sequence seq)
                     throws OperationNotSupportedException
Description copied from interface: Emission
This method computes the logarithm of the likelihood.

Specified by:
getLogProbFor in interface Emission
Parameters:
forward - whether to use the forward or the reverse strand
startPos - the start position
endPos - the end position
seq - the sequence
Returns:
the logarithm of the probability
Throws:
OperationNotSupportedException - if forward=false and the reverse complement of the sequence seq is not defined

getNodeLabel

public String getNodeLabel(double weight,
                           String name,
                           NumberFormat nf)
Description copied from interface: Emission
Returns the graphviz label of the node containing this emission.

Specified by:
getNodeLabel in interface Emission
Parameters:
weight - the weight of the node which is represented by the color of the node, or -1 for no representation, i.e., white background
name - the name of the state using this emission
nf - the NumberFormat for formatting the textual representation of this emission
Returns:
the label

getNodeShape

public String getNodeShape(boolean forward)
Description copied from interface: Emission
Returns the graphviz string for the shape of the node.

Specified by:
getNodeShape in interface Emission
Parameters:
forward - if this emission is used on the forward strand
Returns:
the shape

initializeFunctionRandomly

public void initializeFunctionRandomly()
Description copied from interface: Emission
This method initializes the emission randomly.

Specified by:
initializeFunctionRandomly in interface Emission

resetStatistic

public void resetStatistic()
Description copied from interface: Emission
This method resets the internal sufficient statistic.

Specified by:
resetStatistic in interface Emission

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
Returns:
the XML representation

fromXML

protected void fromXML(StringBuffer xml)
                throws NonParsableException
Throws:
NonParsableException

toString

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

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

clone

public MultivariateGaussianEmission clone()
                                   throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

setParameters

public void setParameters(Emission t)
                   throws IllegalArgumentException
Description copied from interface: Emission
Set values of parameters of the instance to the value of the parameters of the given instance. It can be assumed that the given instance and the current instance are from the same class. This method might be used for instance in a multi-threaded optimization to broadcast the parameters.

Specified by:
setParameters in interface Emission
Parameters:
t - the emission with the parameters to be set
Throws:
IllegalArgumentException - if the assumption about the same class for given and current instance is wrong