Documentation of 'smile.sequence.HMM' Java class
HMM
smile.sequence

Class HMM<O>

  • All Implemented Interfaces:
    SequenceLabeler<O>


    public class HMM<O>
    extends java.lang.Object
    implements SequenceLabeler<O>
    First-order Hidden Markov Model. A hidden Markov model (HMM) is a statistical Markov model in which the system being modeled is assumed to be a Markov process with unobserved (hidden) states. An HMM can be considered as the simplest dynamic Bayesian network.

    In a regular Markov model, the state is directly visible to the observer, and therefore the state transition probabilities are the only parameters. In a hidden Markov model, the state is not directly visible, but output, dependent on the state, is visible. Each state has a probability distribution over the possible output tokens. Therefore the sequence of tokens generated by an HMM gives some information about the sequence of states.

    • Constructor Summary

      Constructors 
      Constructor and Description
      HMM(double[] pi, double[][] a, double[][] b)
      Constructor.
      HMM(double[] pi, double[][] a, double[][] b, O[] symbols)
      Constructor.
      HMM(int[][] observations, int[][] labels)
      Learn an HMM from labeled observation sequences by maximum likelihood estimation.
      HMM(O[][] observations, int[][] labels)
      Learn an HMM from labeled observation sequences by maximum likelihood estimation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double[] getInitialStateProbabilities()
      Returns the initial state probabilities.
      double[][] getStateTransitionProbabilities()
      Returns the state transition probabilities.
      double[][] getSymbolEmissionProbabilities()
      Returns the symbol emission probabilities.
      HMM<O> learn(int[][] observations, int iterations)
      With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.
      HMM<O> learn(O[][] observations, int iterations)
      With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.
      double logp(int[] o)
      Returns the logarithm probability of an observation sequence given this HMM.
      double logp(int[] o, int[] s)
      Returns the log joint probability of an observation sequence along a state sequence given this HMM.
      double logp(O[] o)
      Returns the logarithm probability of an observation sequence given this HMM.
      double logp(O[] o, int[] s)
      Returns the log joint probability of an observation sequence along a state sequence given this HMM.
      int numStates()
      Returns the number of states.
      int numSymbols()
      Returns the number of emission symbols.
      double p(int[] o)
      Returns the probability of an observation sequence given this HMM.
      double p(int[] o, int[] s)
      Returns the joint probability of an observation sequence along a state sequence given this HMM.
      double p(O[] o)
      Returns the probability of an observation sequence given this HMM.
      double p(O[] o, int[] s)
      Returns the joint probability of an observation sequence along a state sequence given this HMM.
      int[] predict(int[] o)
      Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability of P(I | O, HMM).
      int[] predict(O[] o)
      Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability of P(I | O, HMM).
      java.lang.String toString() 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HMM

        public HMM(double[] pi,
                   double[][] a,
                   double[][] b)
        Constructor.
        Parameters:
        pi - the initial state probabilities.
        a - the state transition probabilities, of which a[i][j] is P(s_j | s_i);
        b - the symbol emission probabilities, of which b[i][j] is P(o_j | s_i).
      • HMM

        public HMM(double[] pi,
                   double[][] a,
                   double[][] b,
                   O[] symbols)
        Constructor.
        Parameters:
        pi - the initial state probabilities.
        a - the state transition probabilities, of which a[i][j] is P(s_j | s_i);
        b - the symbol emission probabilities, of which b[i][j] is P(o_j | s_i).
        symbols - the list of emission symbols.
      • HMM

        public HMM(int[][] observations,
                   int[][] labels)
        Learn an HMM from labeled observation sequences by maximum likelihood estimation.
        Parameters:
        observations - the observation sequences, of which symbols take values in [0, n), where n is the number of unique symbols.
        labels - the state labels of observations, of which states take values in [0, p), where p is the number of hidden states.
      • HMM

        public HMM(O[][] observations,
                   int[][] labels)
        Learn an HMM from labeled observation sequences by maximum likelihood estimation.
        Parameters:
        observations - the observation sequences.
        labels - the state labels of observations, of which states take values in [0, p), where p is the number of hidden states.
    • Method Detail

      • numStates

        public int numStates()
        Returns the number of states.
      • numSymbols

        public int numSymbols()
        Returns the number of emission symbols.
      • getInitialStateProbabilities

        public double[] getInitialStateProbabilities()
        Returns the initial state probabilities.
      • getStateTransitionProbabilities

        public double[][] getStateTransitionProbabilities()
        Returns the state transition probabilities.
      • getSymbolEmissionProbabilities

        public double[][] getSymbolEmissionProbabilities()
        Returns the symbol emission probabilities.
      • p

        public double p(int[] o,
                        int[] s)
        Returns the joint probability of an observation sequence along a state sequence given this HMM.
        Parameters:
        o - an observation sequence.
        s - a state sequence.
        Returns:
        the joint probability P(o, s | H) given the model H.
      • logp

        public double logp(int[] o,
                           int[] s)
        Returns the log joint probability of an observation sequence along a state sequence given this HMM.
        Parameters:
        o - an observation sequence.
        s - a state sequence.
        Returns:
        the log joint probability P(o, s | H) given the model H.
      • p

        public double p(int[] o)
        Returns the probability of an observation sequence given this HMM.
        Parameters:
        o - an observation sequence.
        Returns:
        the probability of this sequence.
      • logp

        public double logp(int[] o)
        Returns the logarithm probability of an observation sequence given this HMM. A scaling procedure is used in order to avoid underflows when computing the probability of long sequences.
        Parameters:
        o - an observation sequence.
        Returns:
        the log probability of this sequence.
      • predict

        public int[] predict(int[] o)
        Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability of P(I | O, HMM). In the calculation, we may get ties. In this case, one of them is chosen randomly.
        Parameters:
        o - an observation sequence.
        Returns:
        the most likely state sequence.
      • learn

        public HMM<O> learn(O[][] observations,
                            int iterations)
        With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.
        Parameters:
        observations - the observation sequences on which the learning is based. Each sequence must have a length higher or equal to 2.
        iterations - the number of iterations to execute.
        Returns:
        the updated HMM.
      • learn

        public HMM<O> learn(int[][] observations,
                            int iterations)
        With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.
        Parameters:
        observations - the observation sequences on which the learning is based. Each sequence must have a length higher or equal to 2.
        iterations - the number of iterations to execute.
        Returns:
        the updated HMM.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • p

        public double p(O[] o,
                        int[] s)
        Returns the joint probability of an observation sequence along a state sequence given this HMM.
        Parameters:
        o - an observation sequence.
        s - a state sequence.
        Returns:
        the joint probability P(o, s | H) given the model H.
      • logp

        public double logp(O[] o,
                           int[] s)
        Returns the log joint probability of an observation sequence along a state sequence given this HMM.
        Parameters:
        o - an observation sequence.
        s - a state sequence.
        Returns:
        the log joint probability P(o, s | H) given the model H.
      • p

        public double p(O[] o)
        Returns the probability of an observation sequence given this HMM.
        Parameters:
        o - an observation sequence.
        Returns:
        the probability of this sequence.
      • logp

        public double logp(O[] o)
        Returns the logarithm probability of an observation sequence given this HMM. A scaling procedure is used in order to avoid underflows when computing the probability of long sequences.
        Parameters:
        o - an observation sequence.
        Returns:
        the log probability of this sequence.
      • predict

        public int[] predict(O[] o)
        Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability of P(I | O, HMM). In the calculation, we may get ties. In this case, one of them is chosen randomly.
        Specified by:
        predict in interface SequenceLabeler<O>
        Parameters:
        o - an observation sequence.
        Returns:
        the most likely state sequence.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.