Giter Site home page Giter Site logo

tensorflow_hmm's Introduction

Build Status

tensorflow_hmm

Tensorflow and numpy implementations of the HMM viterbi and forward/backward algorithms.

See Keras example for an example of how to use the Keras HMMLayer.

See test_hmm.py for usage examples. Here is an excerpt of the documentation from hmm.py for reference for now.

See also viterbi_wikipedia_example.py which replicates the viterbi example on wikipedia.

class HMM(object):
    """
    A class for Hidden Markov Models.

    The model attributes are:
    - K :: the number of states
    - P :: the K by K transition matrix (from state i to state j,
        (i, j) in [1..K])
    - p0 :: the initial distribution (defaults to starting in state 0)
    """

    def __init__(self, P, p0=None):

class HMMTensorflow(HMM):
      def forward_backward(self, y):
          """
          runs forward backward algorithm on state probabilities y
      
          Arguments
          ---------
          y : np.array : shape (T, K) where T is number of timesteps and
              K is the number of states
      
          Returns
          -------
          (posterior, forward, backward)
          posterior : list of length T of tensorflow graph nodes representing
              the posterior probability of each state at each time step
          forward : list of length T of tensorflow graph nodes representing
              the forward probability of each state at each time step
          backward : list of length T of tensorflow graph nodes representing
              the backward probability of each state at each time step
          """
      
      
      def viterbi_decode(self, y, nT):
          """
          Runs viterbi decode on state probabilies y.
      
          Arguments
          ---------
          y : np.array : shape (T, K) where T is number of timesteps and
              K is the number of states
          nT : int : number of timesteps in y
      
          Returns
          -------
          (s, pathScores)
          s : list of length T of tensorflow ints : represents the most likely
              state at each time step.
          pathScores : list of length T of tensorflow tensor of length K
              each value at (t, k) is the log likliehood score in state k at
              time t.  sum(pathScores[t, :]) will not necessary == 1
          """

tensorflow_hmm's People

Contributors

dwiel avatar kgupta15 avatar michaelgruner avatar zach-nervana avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.