Lennard-Jones potential: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Dratman
Limitations of the Lennard-Jones Potential: "arises" is misleading, as though this were an approximation in a real problem. Rather it is a model interaction.
en>Knordlun
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
The '''Viterbi algorithm''' is a [[dynamic programming]] [[algorithm]] for finding the most [[likelihood function|likely]] sequence of hidden states – called the '''Viterbi path''' – that results in a sequence of observed events, especially in the context of [[Markov information source]]s and [[hidden Markov model]]s.
Eusebio Stanfill is what's written on my birth marriage certificate although it is not the name on several other birth certificate. Vermont can be where my home was. Software building up has been my day job for a but. To prepare is the only pasttime my wife doesn't approve of. You can seek out my website here: http://prometeu.net<br><br>my website - clash of clans hack tool ([http://prometeu.net Continue Reading])
 
The terms ''Viterbi path'' and ''Viterbi algorithm'' are also applied to related dynamic programming algorithms that discover the single most likely explanation for an observation. For example, in [[statistical parsing]] a dynamic programming algorithm can be used to discover the single most likely context-free derivation (parse) of a string, which is sometimes called the ''Viterbi parse''.
 
The Viterbi algorithm was proposed by [[Andrew Viterbi]] in 1967 as a decoding algorithm for [[Convolution code|convolutional codes]] over noisy digital communication links.<ref>[http://arxiv.org/abs/cs/0504020v2 29 Apr 2005, G. David Forney Jr: The Viterbi Algorithm: A Personal History]</ref> The algorithm has found universal application in decoding the [[convolutional code]]s used in both [[CDMA]] and [[GSM]] digital cellular, [[dial-up]] modems, satellite, deep-space communications, and [[802.11]] wireless LANs. It is now also commonly used in [[speech recognition]], [[speech synthesis]], [[keyword spotting]], [[computational linguistics]], and [[bioinformatics]]. For example, in [[speech-to-text]] (speech recognition), the acoustic signal is treated as the observed sequence of events, and a string of text is considered to be the "hidden cause" of the acoustic signal. The Viterbi algorithm finds the most likely string of text given the acoustic signal.
 
==Algorithm==
Suppose we are given a [[Hidden Markov Model]] (HMM) with state space <math>S</math>, initial probabilities <math>\pi_i</math> of being in state <math>i</math> and transition probabilities <math>a_{i,j}</math> of transitioning from state <math>i</math> to state <math>j</math>.  Say we observe outputs <math>y_1,\dots, y_T</math>.  The most likely state sequence <math>x_1,\dots,x_T</math> that produces the observations is given by the recurrence relations:<ref>Xing E, slide 11</ref>
 
:<math>
\begin{array}{rcl}
V_{1,k} &=& \mathrm{P}\big( y_1 \ | \ k \big) \cdot \pi_k \\
V_{t,k} &=& \mathrm{P}\big( y_t \ | \ k \big) \cdot \max_{x \in S} \left( a_{x,k} \cdot V_{t-1,x}\right)
\end{array}
</math>
 
Here <math>V_{t,k}</math> is the probability of the most probable state sequence responsible for the first <math>t</math> observations that has <math>k</math> as its final state.  The Viterbi path can be retrieved by saving back pointers that remember which state <math>x</math> was used in the second equation.  Let <math>\mathrm{Ptr}(k,t)</math> be the function that returns the value of <math>x</math> used to compute <math>V_{t,k}</math> if <math>t > 1</math>, or <math>k</math> if <math>t=1</math>.  Then:
 
:<math>
\begin{array}{rcl}
x_T &=& \arg\max_{x \in S} (V_{T,x}) \\
x_{t-1} &=& \mathrm{Ptr}(x_t,t)
\end{array}
</math>
Here we're using the standard definition of [[arg max]].<br>
The complexity of this algorithm is <math>O(T\times\left|{S}\right|^2)</math>.
 
==Pseudocode==
Given the observation space <math> O=\{o_1,o_2,\dots,o_N\}</math>, the state space <math> S=\{s_1,s_2,\dots,s_K\} </math>, a sequence of observations <math> Y=\{y_1,y_2,\ldots, y_T\} </math>, transition matrix <math> A </math> of size <math> K\times K </math> such that <math> A_{ij} </math> stores the transition probability of transiting from state <math> s_i </math> to state <math> s_j </math>, emission matrix <math> B </math> of size <math> K\times N </math> such that <math> B_{ij} </math> stores the probability of observing <math> o_j </math> from  state <math> s_i </math>, an array of initial probabilities <math> \pi </math> of size <math> K </math> such that <math> \pi_i </math> stores the probability that <math> x_1 ==  s_i </math>.We say a path <math> X=\{x_1,x_2,\ldots,x_T\} </math> is a sequence of states that generate the observations <math> Y=\{y_1,y_2,\ldots, y_T\} </math>.
 
In this dynamic programming problem, we construct two 2-dimensional tables <math>T_1, T_2</math> of size <math>K\times T</math>. Each element of <math>T_1</math>, <math>T_1[i,j]</math>, stores the probability of the most likely path so far <math> \hat{X}=\{\hat{x}_1,\hat{x}_2,\ldots,\hat{x}_j\} </math> with <math>\hat{x}_j=s_i </math> that generates <math> Y=\{y_1,y_2,\ldots, y_j\}</math>. Each element of <math>T_2 </math>, <math>T_2[i,j] </math>, stores <math>\hat{x}_{j-1} </math> of the most likely path so far <math> \hat{X}=\{\hat{x}_1,\hat{x}_2,\ldots,\hat{x}_{j-1},\hat{x}_j\}</math> for <math>\forall j, 2\leq j \leq T  </math>
 
We fill entries of two tables <math> T_1[i,j],T_2[i,j]</math> by increasing order of <math>K\cdot j+i </math>.
 
:<math>T_1[i,j]=\max_{k}{(T_1[k,j-1]\cdot A_{ki}\cdot B_{iy_j})} </math>, and
:<math> T_2[i,j]=\arg\max_{k}{(T_1[k,j-1]\cdot A_{ki}\cdot B_{iy_j})} </math>
 
Note that <math>B_{iy_j}</math> does not need to appear in the latter expression, as it's constant with {{math|''i''}} and {{math|''j''}} and does not affect the argmax.
 
    INPUT:  The observation space <math> O=\{o_1,o_2,\dots,o_N\}</math>,
            the state space <math> S=\{s_1,s_2,\dots,s_K\} </math>,
            a sequence of observations  <math> Y=\{y_1,y_2,\ldots, y_T\} </math> such that <math> y_t==i </math> if the
              observation at time <math> t </math> is <math> o_i </math>,
            transition matrix <math> A </math> of size <math> K\cdot K </math> such that <math> A_{ij} </math> stores the transition
              probability of transiting from state <math> s_i </math> to state <math> s_j </math>,
            emission matrix <math> B </math> of size <math> K\cdot N </math> such that <math> B_{ij} </math> stores the probability of
              observing <math> o_j </math> from  state <math> s_i </math>,
            an array of initial probabilities <math> \pi </math> of size <math> K </math> such that <math> \pi_i </math> stores the probability
              that <math> x_1 ==  s_i </math>
    OUTPUT: The most likely hidden state sequence <math> X=\{x_1,x_2,\ldots,x_T\} </math>
A01 '''function''' ''VITERBI''( ''O'', ''S'',''π'',''Y'',''A'',''B'' ) : ''X''
A02    '''for''' each state ''s<sub>i</sub>'' '''do'''
A03        ''T<sub>1</sub>[i,1]''←''π<sub>i</sub>''<math>\cdot</math>''B<sub>iy<sub>1</sub></sub>
A04        ''T<sub>2</sub>[i,1]''←0
A05    '''end for'''
A06    '''for''' ''i''←''2'',''3'',...,''T'' '''do'''
A07        '''for''' each state ''s<sub>j</sub>'' '''do'''
A08            ''T<sub>1</sub>[j,i]''←<math>\max_{k}{(T_1[k,i-1]\cdot A_{kj}\cdot B_{jy_i})} </math>
A09            ''T<sub>2</sub>[j,i]''←<math>\arg\max_{k}{(T_1[k,i-1]\cdot A_{kj}\cdot B_{jy_i})} </math>
A10        '''end for'''
A11    '''end for'''
A12    ''z<sub>T</sub>''←<math>\arg\max_{k}{(T_1[k,T])} </math>
A13    ''x<sub>T</sub>''←s<sub>z<sub>T</sub></sub>
A14    '''for''' ''i''←''T'',''T-1'',...,''2'' '''do'''
A15        ''z<sub>i-1</sub>''←T<sub>2</sub>[z<sub>i</sub>,i]
A16        ''x<sub>i-1</sub>''←''s<sub>z<sub>i-1</sub></sub>''
A17    '''end for'''
A18    '''return''' ''X''
A19 '''end function'''
 
==Example==
Consider a primitive clinic in a village. People in the village have a very nice property that they are either healthy or have a fever. They can only tell if they have a fever by asking a doctor in the clinic. The wise doctor makes a diagnosis of fever by asking patients how they feel. Villagers only answer that they feel normal, dizzy, or cold.
 
Suppose a patient comes to the clinic each day and tells the doctor how she feels. The doctor believes that the health condition of this patient operates as a discrete [[Markov chain]]. There are two states, "Healthy" and "Fever", but the doctor cannot observe them directly, that is, they are ''hidden'' from him. On each day, there is a certain chance that the patient will tell the doctor she has one of the following feelings, depending on her health condition: "normal", "cold", or "dizzy". Those are the ''observations''. The entire system is that of a hidden Markov model (HMM).
 
The doctor knows the villager's general health condition, and what symptoms patients complain of with or without fever on average. In other words, the parameters of the HMM are known. They can be represented as follows in the [[Python programming language]]:
<source lang="python">
states = ('Healthy', 'Fever')
observations = ('normal', 'cold', 'dizzy')
start_probability = {'Healthy': 0.6, 'Fever': 0.4}
transition_probability = {
  'Healthy' : {'Healthy': 0.7, 'Fever': 0.3},
  'Fever' : {'Healthy': 0.4, 'Fever': 0.6},
  }
emission_probability = {
  'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
  'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6},
  }
</source>
In this piece of code, <code>start_probability</code> represents the doctor's belief about which state the HMM is in when the patient first visits (all he knows is that the patient tends to be healthy). The particular probability distribution used here is not the equilibrium one, which is (given the transition probabilities) approximately <code>{'Healthy': 0.57, 'Fever': 0.43}</code>. The <code>transition_probability</code> represents the change of the health condition in the underlying Markov chain. In this example, there is only a 30% chance that tomorrow the patient will have a fever if he is healthy today. The <code>emission_probability</code> represents how likely the patient is to feel on each day. If he is healthy, there is a 50% chance that he feels normal; if he has a fever, there is a 60% chance that he feels dizzy.
 
[[File:An example of HMM.png|border|center|400px|Graphical representation of the given HMM]]
 
The patient visits three days in a row and the doctor discovers that on the first day she feels normal, on the second day she feels cold, on the third day she feels dizzy. The doctor has a question: what is the most likely sequence of health condition of the patient would explain these observations? This is answered by the Viterbi algorithm.
 
<source lang="python">
# Helps visualize the steps of Viterbi.
def print_dptable(V):
    s = "    " + " ".join(("%7d" % i) for i in range(len(V))) + "\n"
    for y in V[0]:
        s += "%.5s: " % y
        s += " ".join("%.7s" % ("%f" % v[y]) for v in V)
        s += "\n"
    print(s)
 
def viterbi(obs, states, start_p, trans_p, emit_p):
    V = [{}]
    path = {}
   
    # Initialize base cases (t == 0)
    for y in states:
        V[0][y] = start_p[y] * emit_p[y][obs[0]]
        path[y] = [y]
   
    # alternative Python 2.7+ initialization syntax
    # V = [{y:(start_p[y] * emit_p[y][obs[0]]) for y in states}]
    # path = {y:[y] for y in states}
   
    # Run Viterbi for t > 0
    for t in range(1, len(obs)):
        V.append({})
        newpath = {}
 
        for y in states:
            (prob, state) = max((V[t-1][y0] * trans_p[y0][y] * emit_p[y][obs[t]], y0) for y0 in states)
            V[t][y] = prob
            newpath[y] = path[state] + [y]
 
        # Don't need to remember the old paths
        path = newpath
 
    print_dptable(V)
    (prob, state) = max((V[t][y], y) for y in states)
    return (prob, path[state])
 
</source>
The function <code>viterbi</code> takes the following arguments: <code>obs</code> is the sequence of observations, e.g. <code>['normal', 'cold', 'dizzy']</code>; <code>states</code> is the set of hidden states; <code>start_p</code> is the start probability; <code>trans_p</code> are the transition probabilities; and <code>emit_p</code> are the emission probabilities.  For simplicity of code, we assume that the observation sequence <code>obs</code> is non-empty and that  <code>trans_p[i][j]</code> and <code>emit_p[i][j]</code> is defined for all states i,j.
 
In the running example, the forward/Viterbi algorithm is used as follows:
 
<source lang="python">
def example():
    return viterbi(observations,
                  states,
                  start_probability,
                  transition_probability,
                  emission_probability)
print(example())
</source>
 
This reveals that the observations <code>['normal', 'cold', 'dizzy']</code> were most likely generated by states <code>['Healthy', 'Healthy', 'Fever']</code>. In other words, given the observed activities, the patient was most likely to have been healthy both on the first day when she felt normal as well as on the second day when she felt cold, and then she contracted a fever the third day.
 
The operation of Viterbi's algorithm can be visualized by means of a
[[Trellis_diagram#Trellis_diagram|trellis diagram]]. The Viterbi path is essentially the shortest
path through this trellis. The trellis for the clinic example is shown below; the corresponding
Viterbi path is in bold:
[[Image:Viterbi animated demo.gif|border|center|Animation of the trellis diagram for the Viterbi algorithm. After Day 3, the most likely path is <code>['Healthy', 'Healthy', 'Fever']</code>]]
 
When implementing Viterbi's algorithm, it should be noted that many languages use [[floating point]] arithmetic - as p is small, this may lead to [[Arithmetic underflow|underflow]] in the results. A common technique to avoid this is to take the [[log probability|logarithm of the probabilities]] and use it throughout the computation,  the same technique used in the [[Logarithmic Number System]]. Once the algorithm has terminated, an accurate value can be obtained by performing the appropriate exponentiation.
 
==Extensions==
A generalization of the Viterbi algorithm, termed the ''max-sum algorithm'' (or ''max-product algorithm'') can be used to find the most likely assignment of all or some subset of [[latent variable]]s in a large number of [[graphical model]]s, e.g. [[Bayesian network]]s, [[Markov random field]]s and [[conditional random field]]s.  The latent variables need in general to be connected in a way somewhat similar to an HMM, with a limited number of connections between variables and some type of linear structure among the variables.  The general algorithm involves ''message passing'' and is substantially similar to the [[belief propagation]] algorithm (which is the generalization of the [[forward-backward algorithm]]).
 
With the algorithm called [[iterative Viterbi decoding]] one can find the subsequence of an observation that matches best (on average) to a given HMM. This algorithm is proposed by Qi Wang, etc.<ref>{{cite journal|author = Qi Wang |coauthors= Lei Wei; Rodney A. Kennedy | year=2002|title= Iterative Viterbi Decoding, Trellis Shaping,and Multilevel Structure for High-Rate Parity-Concatenated TCM| journal= IEEE TRANSACTIONS ON COMMUNICATIONS|volume= 50 | pages = 48–55}}
</ref> to deal with [[turbo code]]. Iterative Viterbi decoding works by iteratively invoking a modified Viterbi algorithm, reestimating the score for a filler until convergence.
 
An alternative algorithm, the [[Lazy Viterbi algorithm]], has been proposed recently.<ref>{{cite conference|url=http://people.csail.mit.edu/jonfeld/pubs/lazyviterbi.pdf |title=A fast maximum-likelihood decoder for convolutional codes |date=December 2002 |conference= Vehicular Technology Conference |conferenceurl=http://www.ieeevtc.org/ |pages=371–375 |format=PDF |doi=10.1109/VETECF.2002.1040367}}</ref> For many codes of practical interest, under reasonable noise conditions, the lazy
decoder (using Lazy Viterbi algorithm) is much faster than the original Viterbi decoder (using Viterbi algorithm).<ref>{{cite conference|url=http://people.csail.mit.edu/jonfeld/pubs/lazyviterbi.pdf |title=A fast maximum-likelihood decoder for convolutional codes |date=December 2002 |conference= Vehicular Technology Conference |conferenceurl=http://www.ieeevtc.org/ |page=371 |format=PDF |doi=10.1109/VETECF.2002.1040367}}</ref> This algorithm works by not expanding any nodes until it really needs to, and usually manages to get away with doing a lot less work (in software) than the ordinary Viterbi algorithm for the same result - however, it is not so easy to parallelize in hardware.
 
Moreover, the Viterbi algorithm has been extended to operate with a deterministic finite automaton in order to improve speed for use in stochastic letter-to-phoneme conversion.<ref>{{cite journal|author = Luk, R.W.P. |coauthors= R.I. Damper | year=1998|title= Computational complexity of a fast Viterbi decoding algorithm for stochastic letter-phoneme transduction| journal= IEEE Trans. Speech and Audio Processing|volume= 6 | issue = 3| pages = 217–225| doi=10.1109/89.668816}}
</ref>
 
==See also==
* [[Expectation–maximization algorithm]]
* [[Baum–Welch algorithm]]
* [[Forward-backward algorithm]]
* [[Forward algorithm]]
* [[Error-correcting code]]
* [[Soft output Viterbi algorithm]]
* [[Viterbi decoder]]
* [[Hidden Markov model]]
* [[Part-of-speech tagging]]
 
==Notes==
<references />
 
==References==
* {{cite journal |doi=10.1109/TIT.1967.1054010 |author=Viterbi AJ |title=Error bounds for convolutional codes and an asymptotically optimum decoding algorithm |journal=IEEE Transactions on Information Theory |volume=13 |issue=2 |pages=260–269 |date=April 1967 |url=http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1054010}} (note: the Viterbi decoding algorithm is described in section IV.) Subscription required.
* {{cite journal |author=Feldman J, Abou-Faycal I, Frigo M |title=A Fast Maximum-Likelihood Decoder for Convolutional Codes |journal=Vehicular Technology Conference |volume=1 |pages=371–375 |year=2002 |doi=10.1109/VETECF.2002.1040367}}
* {{cite journal |doi=10.1109/PROC.1973.9030 |author=Forney GD |title=The Viterbi algorithm |journal=Proceedings of the IEEE |volume=61 |issue=3 |pages=268–278 |date=March 1973 |url=http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1450960}} Subscription required.
*{{Cite book | last1=Press | first1=WH | last2=Teukolsky | first2=SA | last3=Vetterling | first3=WT | last4=Flannery | first4=BP | year=2007 | title=Numerical Recipes: The Art of Scientific Computing | edition=3rd | publisher=Cambridge University Press |  publication-place=New York | isbn=978-0-521-88068-8 | chapter=Section 16.2. Viterbi Decoding | chapter-url=http://apps.nrbook.com/empanel/index.html#pg=850}}
* {{cite journal |author=Rabiner LR |title=A tutorial on hidden Markov models and selected applications in speech recognition |journal=Proceedings of the IEEE |volume=77 |issue=2 |pages=257–286 |date=February 1989 |doi=10.1109/5.18626}} (Describes the forward algorithm and Viterbi algorithm for HMMs).
* Shinghal, R. and [[Godfried Toussaint|Godfried T. Toussaint]], "Experiments in text recognition with the modified Viterbi algorithm," ''IEEE Transactions on Pattern Analysis and Machine Intelligence'', Vol. PAMI-l, April 1979, pp.&nbsp;184–193.
* Shinghal, R. and [[Godfried Toussaint|Godfried T. Toussaint]], "The sensitivity of the modified Viterbi algorithm to the source statistics," ''IEEE Transactions on Pattern Analysis and Machine Intelligence'', vol. PAMI-2, March 1980, pp.&nbsp;181–185.
 
== Implementations ==
*[http://www.ka9q.net/code/fec/ C and assembly]
*[http://www.sjsuasr.com/doku.php?id=wiki_viterbi.c C] [DEAD LINK]
*[http://bozskyfilip.blogspot.com/2009/01/viterbi-algorithm-in-c-and-using-stl.html C++]
*[http://codingplayground.blogspot.com/2009/02/viterbi-algorithm-in-boost-and-c.html C++ and Boost] by Antonio Gulli
*[http://pcarvalho.com/forward_viterbi/ C#]
*[https://gist.github.com/2482912 F#]
*[http://www.cs.stonybrook.edu/~pfodor/viterbi/Viterbi.java Java]
*[https://metacpan.org/module/Algorithm::Viterbi Perl]
*[http://www.cs.stonybrook.edu/~pfodor/viterbi/viterbi.P Prolog]
*[http://opencores.org/project,viterbi_decoder_axi4s VHDL]
 
==External links==
*[http://en.wikibooks.org/wiki/Algorithm_Implementation/Viterbi_algorithm Implementations in Java, F#, Clojure, C# on Wikibooks]
*[http://home.netcom.com/~chip.f/viterbi/tutorial.html Tutorial] on convolutional coding with viterbi decoding, by Chip Fleming
*[http://arxiv.org/abs/cs/0504020v2 The history of the Viterbi Algorithm], by David Forney
*[http://www.cambridge.org/resources/0521882672/7934_kaeslin_dynpro_new.pdf  A Gentle Introduction to Dynamic Programming and the Viterbi Algorithm]
*[http://www.kanungo.com/software/hmmtut.pdf A tutorial for a Hidden Markov Model toolkit (implemented in C) that contains a description of the Viterbi algorithm]
 
[[Category:Error detection and correction]]
[[Category:Dynamic programming]]
[[Category:Markov models]]

Latest revision as of 17:49, 26 December 2014

Eusebio Stanfill is what's written on my birth marriage certificate although it is not the name on several other birth certificate. Vermont can be where my home was. Software building up has been my day job for a but. To prepare is the only pasttime my wife doesn't approve of. You can seek out my website here: http://prometeu.net

my website - clash of clans hack tool (Continue Reading)