de.jstacs.models.hmm
Class HMMFactory

java.lang.Object
  extended by de.jstacs.models.hmm.HMMFactory

public class HMMFactory
extends Object

This class allows to create some frequently used HMMs.

Author:
Jan Grau, Jens Keilwagen

Nested Class Summary
static class HMMFactory.HMMType
          This enum defines some standard architecture of profile HMMs.
 
Constructor Summary
HMMFactory()
           
 
Method Summary
static AbstractHMM createErgodicHMM(HMMTrainingParameterSet pars, int order, double ess, double selfTranistionPart, double expectedSequenceLength, Emission... emission)
          This method creates an ergodic, i.e. a completely connected, HMM using the given emissions.
static AbstractHMM createProfileHMM(MaxHMMTrainingParameterSet trainingParameterSet, double[][] initFromTo, boolean likelihood, int order, int numLayers, AlphabetContainer con, double ess, boolean conditionalMain, boolean closeCircle, double[][] conditionInitProbs)
          Creates a new profile HMM for a given architecture and number of layers.
static AbstractHMM createProfileHMM(MaxHMMTrainingParameterSet trainingParameterSet, HMMFactory.HMMType type, boolean likelihood, int order, int numLayers, AlphabetContainer con, double ess, boolean conditionalMain, boolean closeCircle, double[][] conditionInitProbs)
          Creates a new profile HMM for a given architecture and number of layers.
static AbstractHMM createSunflowerHMM(HMMTrainingParameterSet pars, AlphabetContainer con, double ess, int expectedSequenceLength, boolean startCentral, int... motifLength)
          This method creates a first order sunflower HMM.
static AbstractHMM createSunflowerHMM(HMMTrainingParameterSet pars, AlphabetContainer con, double ess, int expectedSequenceLength, boolean startCentral, PhyloTree[] t, double[] motifProb, int[] motifLength)
          This method creates a first order sunflower HMM allowing phylogenetic emissions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HMMFactory

public HMMFactory()
Method Detail

createErgodicHMM

public static AbstractHMM createErgodicHMM(HMMTrainingParameterSet pars,
                                           int order,
                                           double ess,
                                           double selfTranistionPart,
                                           double expectedSequenceLength,
                                           Emission... emission)
                                    throws Exception
This method creates an ergodic, i.e. a completely connected, HMM using the given emissions.

Parameters:
pars - the parameter determining the training procedure of the HMM
order - the Markov order of the HMM
ess - the ess to be used for the HMM
selfTranistionPart - the a-priori probability of any self transition
expectedSequenceLength - the expected length of sequences to be modeled
emission - the emissions of the states
Returns:
an ergodic HMM
Throws:
Exception - if the HMM can not be created properly

createSunflowerHMM

public static AbstractHMM createSunflowerHMM(HMMTrainingParameterSet pars,
                                             AlphabetContainer con,
                                             double ess,
                                             int expectedSequenceLength,
                                             boolean startCentral,
                                             int... motifLength)
                                      throws Exception
This method creates a first order sunflower HMM. The current implementation does not set any hyper parameters for the prior.

Parameters:
pars - the parameter determining the training procedure of the HMM
con - the AlphabetContainer of the HMM
ess - the equivalent sample size (ess) of this model
expectedSequenceLength - the expected sequence length to be modeled; this parameter is used to determine the prior
startCentral - a switch for deciding between starting in the central state or in all states
motifLength - the length of the motifs building the petals of the sunflower
Returns:
a first order sunflower HMM
Throws:
Exception - if the HMM can not be created properly
See Also:
createSunflowerHMM(HMMTrainingParameterSet, AlphabetContainer, double, int, boolean, PhyloTree[], double[], int[])

createSunflowerHMM

public static AbstractHMM createSunflowerHMM(HMMTrainingParameterSet pars,
                                             AlphabetContainer con,
                                             double ess,
                                             int expectedSequenceLength,
                                             boolean startCentral,
                                             PhyloTree[] t,
                                             double[] motifProb,
                                             int[] motifLength)
                                      throws Exception
This method creates a first order sunflower HMM allowing phylogenetic emissions. The current implementation does not set any hyper parameters for the prior.

Parameters:
pars - the parameter determining the training procedure of the HMM
con - the AlphabetContainer of the HMM
ess - the equivalent sample size (ess) of this model
expectedSequenceLength - the expected sequence length to be modeled; this parameter is used to determine the prior
startCentral - a switch for deciding between starting in the central state or in all states
t - an array of length two that contains a PhyloTree for the background and the motif, can be null than a normal sunflower HMM is returned
motifProb - the a-priori probabilities for each motif, i.e., the a-priori probabilities for the edges from the central node to the first motif states
motifLength - the length of the motifs building the petals of the sunflower
Returns:
a first order sunflower HMM
Throws:
Exception - if the HMM can not be created properly

createProfileHMM

public static AbstractHMM createProfileHMM(MaxHMMTrainingParameterSet trainingParameterSet,
                                           HMMFactory.HMMType type,
                                           boolean likelihood,
                                           int order,
                                           int numLayers,
                                           AlphabetContainer con,
                                           double ess,
                                           boolean conditionalMain,
                                           boolean closeCircle,
                                           double[][] conditionInitProbs)
                                    throws Exception
Creates a new profile HMM for a given architecture and number of layers.

Parameters:
trainingParameterSet - the parameters of the algorithm for learning the model parameters
type - the type of the HMM, i.e., its architecture
likelihood - if true, the likelihood is considered as score of a sequence, and the probability of the Viterbi path otherwise
order - the order of the HMM, i.e., the number of previous states that are considered for a transition probability
numLayers - the number of layers of the profile HMM
con - the alphabet of the profile HMM
ess - the equivalent sample size, is propagated between states to obtain consistent hyper-parameters for all parameters
conditionalMain - if true, the match states have ReferenceSequenceDiscreteEmissions, and DiscreteEmissions otherwise
closeCircle - if true the circle from end to initial state is closed, i.e., the HMM can be traversed several times
conditionInitProbs - the hyper-parameters for initializing the match states if conditionalMain is true. May be null for using the hyper-parameters of the prior
Returns:
the profile HMM
Throws:
Exception - if the profile HMM could not be created

createProfileHMM

public static AbstractHMM createProfileHMM(MaxHMMTrainingParameterSet trainingParameterSet,
                                           double[][] initFromTo,
                                           boolean likelihood,
                                           int order,
                                           int numLayers,
                                           AlphabetContainer con,
                                           double ess,
                                           boolean conditionalMain,
                                           boolean closeCircle,
                                           double[][] conditionInitProbs)
                                    throws Exception
Creates a new profile HMM for a given architecture and number of layers.

Parameters:
trainingParameterSet - the parameters of the algorithm for learning the model parameters
initFromTo - hyper-parameters of the transition from each state (first dimension) of the current layer to each other state in the same layer (first three entries of the second dimension) and the next layer (next three entries in the second dimension). If a hyper-parameter is set to Double.NaN, the corresponding transition is not allowed
likelihood - if true, the likelihood is considered as score of a sequence, and the probability of the Viterbi path otherwise
order - the order of the HMM, i.e., the number of previous states that are considered for a transition probability
numLayers - the number of layers of the profile HMM
con - the alphabet of the profile HMM
ess - the equivalent sample size, is propagated between states to obtain consistent hyper-parameters for all parameters
conditionalMain - if true, the match states have ReferenceSequenceDiscreteEmissions, and DiscreteEmissions otherwise
closeCircle - if true the circle from end to initial state is closed, i.e., the HMM can be traversed several times
conditionInitProbs - the hyper-parameters for initializing the match states if conditionalMain is true. May be null for using the hyper-parameters of the prior
Returns:
the profile HMM
Throws:
Exception - if the profile HMM could not be created