A list,
Hidden Markov Model (HMM) is a dynamic Bayesian network generation model with the simplest structure. It is also a famous directed graph model. It is a typical statistical machine learning model to deal with annotation problems in natural languages. This paper will focus on this classical machine learning model. 1 the introduction
Suppose there are three different dice (6 sides, 4 sides, 8 sides), first choose one of the three dice each time, the probability of each dice being selected is 1/3, as shown in the figure below. Repeat the above process to get a string of values [1,6,3,5,2,7]. These observable variables form the observable state chain. At the same time, there is an implicit state chain composed of implicit variables in the hidden Markov model, which in this case is the sequence of dice. For example, the sequence of the numeric dice might be [D6, D8, D8, D6, D4, D8].
The schematic diagram of the hidden Markov type is as follows:
In the figure, the arrows represent the dependencies between variables. The arrows in the figure are described as follows:
At any given time, the observation variable (dice) depends only on the state variable (what kind of dice), and the state qt at time T depends only on the state Qt-1 at time t-1. This is the Markov chain, the next moment of the system is determined only by the current state (no memory), the homogeneous Markov hypothesis.
2. Definition of hidden Markov model
Based on the above example, the definition of hidden Markov is given here. Hidden markov models is about probability model of time sequence, described by a hidden markov chain unobservable state randomly generated random sequence, and then by each state the process of generating a random sequence to observe, hidden markov chain state of randomly generated sequence, known as the state sequence (D6 in the example above, the D8, etc.); Each state generates an observation, and the resulting random sequence of observations is called an observation sequence (i.e., 1,6, etc., in the example above). Each position in the sequence can again be seen as a moment.
The hidden Markov model is determined by the initial probability distribution, state transition probability distribution and observation probability distribution. The specific form is as follows. Here, Q is the set of all possible states and V is the set of all possible observations, namely:
3. Forward algorithm
For the initial of step 1, is the joint probability of the state i1 = Q1 and the observation O1 at the initial time. Step (2) is the recursive formula of the forward probability, and the observation sequence at time t+1 is calculated as O1, O2… ,ot,ot+1 and the forward probability of state QI at time t+1. As shown in the figure above, since at(j) is obtained at time t, o1, O2… ,ot and qj forward probability of being in state at time t, then at(j)aji is o1, O2… ,ot and is the joint probability of being in qj state at time t and reaching QI state at time t+1. The sum of all the N possible states of the product at time t is o1, O2… ,ot, and the joint probability of state QI at time t+1. The third step, calculate the P (O | lambda) results.
Of course, this is only one of many algorithms introduced, as well as backward algorithms (you can see the relevant books for understanding). Viterbi algorithm is widely used in dynamic programming to solve hidden Markov model prediction problems.
Ii. Source code
Function H=melbankm(M,N,fs, FL, fH) %Mel filter banks % Input parameters: M Number of filter banks % N FFT length % fs sampling frequency % FL-fH Is the useful frequency band of the linear power spectrum00.5*fs) % % output parameter: H returns the filter bank, one filter per actionif nargin<4
fl=0*fs;
fh=0.5*fs; End % Calculate the center frequency of each filter f=zeros(1,M+1);
for m=1:M+2
f(m)=floor((N/fs)*mel2freq(freq2mel(fl)...
+(m- 1)*(freq2mel(fh)-freq2mel(fl))/(M+1))); End % find filter bank H c=floor(N/2) +1;
y=zeros(1,c);
H=zeros(M,c);
for m=2:M+1
for k=1:c % Since the maximum fh is fs/2, so you need c bits at most to store Hif f(m- 1)<=k&&k<=f(m)
y(k)=(k-f(m- 1))/(f(m)-f(m- 1));
elseif f(m)<=k&&k<=f(m+1)
y(k)=(f(m+1)-k)/(f(m+1)-f(m));
else
y(k)=0;
end
endfunction [x,esq,j] = kmeans1(d,k,x0)
%KMEANS Vector quantisation using K-means algorithm [X,ESQ,J]=(D,K,X0)
%Inputs:
% D contains data vectors (one per row)
% K is number of centres required
% X0 are the initial centres (optional)
%
%Outputs:
% X is output row vectors (K rows)
% ESQ is mean square error
% J indicates which centre each data vector belongs to
% Based on a routine by Chuck Anderson, [email protected], 1996
% Copyright (C) Mike Brookes 1998
%
% Last modified Mon Jul 27 15:48:23 1998
%
% VOICEBOX home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You can obtain a copy of the GNU General Public License from
% ftp:/ / prep.ai.mit.edu/pub/gnu/COPYING-2.0 or by writing to
% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [n,p] = size(d); % rows (n) and columns (p) of the input matrix Dif nargin<3
x = d(ceil(rand(1,k)*n),:); Extract k arbitrary row vectors from the input matrixelse
x=x0;
end
y = x+1;
while any(x(:) ~= y(:))
z = disteusq(d,x,'x'); % to calculate d (62*24) and x (3*24), z(62*3)
[m,j] = min(z,[],2); % find each line in z3The minimum value and the corresponding serial number y = x;for i=1:k
s = j==i;
if any(s)
x(i,:) = mean(d(s,:),1); % averages all vectors in the class I over rowselse
q=find(m~=0);
if isempty(q) break; end
r=q(ceil(rand*length(q)));
x(i,:) = d(r,:);
m(r)=0;
y=x+1;
end
end
end
Copy the code
3. Operation results
Fourth, note
Version: 2014 a