# HG changeset patch # User whyly # Date 1160941842 0 # Node ID e8b0cde34d1b55e304e31c7f4d723a02ff275120 # Parent a52a009b49084bfe913cf40794694cae2b194c1c Improved texinfo. diff -r a52a009b4908 -r e8b0cde34d1b main/statistics/inst/hmmestimate.m --- a/main/statistics/inst/hmmestimate.m Sun Oct 15 08:55:05 2006 +0000 +++ b/main/statistics/inst/hmmestimate.m Sun Oct 15 19:50:42 2006 +0000 @@ -16,97 +16,116 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{transprobest}, @var{outprobest}] =} hmmestimate (@var{sequence}, @var{states}) -## @deftypefnx {Function File} hmmestimate (@dots{}, 'statenames', @var{statenames}) -## @deftypefnx {Function File} hmmestimate (@dots{}, 'symbols', @var{symbols}) -## @deftypefnx {Function File} hmmestimate (@dots{}, 'pseudotransitions', @var{pseudotransitions}) -## @deftypefnx {Function File} hmmestimate (@dots{}, 'pseudoemissions', @var{pseudoemissions}) -## Estimates the matrix with the transition probabilities and the matrix -## with the output probabilities for a given sequence with outputs and -## states produced by a Hidden Markov Model. The model assumes that the -## generation begins with state @code{1} in step @code{0} but does not -## include step @code{0} in the generated states and sequence +## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'statenames', @var{statenames}) +## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'symbols', @var{symbols}) +## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'pseudotransitions', @var{pseudotransitions}) +## @deftypefnx {Function File} {} hmmestimate (@dots{}, 'pseudoemissions', @var{pseudoemissions}) +## Estimates the matrix of transition probabilities and the matrix of output +## probabilities for a given sequence of outputs and states generated by a +## Hidden Markov Model. The model assumes that the generation starts in +## state @code{1} at step @code{0} but does not include step @code{0} in the +## generated states and sequence. ## ## Arguments are ## -## @itemize +## @itemize @bullet ## @item -## @var{sequence} is a vector with a sequence of given outputs. The -## outputs must be integers ranging from @code{1} to the number of outputs -## of the Hidden Markov Model +## @var{sequence} is a vector of a sequence of given outputs. The outputs +## must be integers ranging from @code{1} to the number of outputs of the +## Hidden Markov Model. +## ## @item -## @var{states} is a vector of the same length as @var{sequence} with given +## @var{states} is a vector of the same length as @var{sequence} of given ## states. The states must be integers ranging from @code{1} to the number -## of states of the Hidden Markov Model +## of states of the Hidden Markov Model. ## @end itemize ## ## Return values are ## -## @itemize +## @itemize @bullet ## @item -## @var{transprobest} is the matrix with the estimated transition +## @var{transprobest} is the matrix of the estimated transition ## probabilities for the states. @code{transprobest (i, j)} is the estimated -## probability for a transition to state @code{j} given state @code{i} +## probability for a transition to state @code{j} given state @code{i}. +## ## @item -## @var{outprobest} is the matrix with the estimated output probabilities. +## @var{outprobest} is the matrix of the estimated output probabilities. ## @code{outprobest (i, j)} is the estimated probability for generating -## output @code{j} given state @code{i} +## output @code{j} given state @code{i}. ## @end itemize ## -## If 'symbols' is specified, then @var{sequence} is expected to be a +## If @code{'symbols'} is specified, then @var{sequence} is expected to be a ## sequence of the elements of @var{symbols} instead of integers. -## @var{symbols} can be a cell array +## @var{symbols} can be a cell array. ## -## If 'statenames' is specified, then @var{states} is expected to be a -## sequence of the elements of @var{statenames} instead of integers. -## @var{statenames} can be a cell array +## If @code{'statenames'} is specified, then @var{states} is expected to be +## a sequence of the elements of @var{statenames} instead of integers. +## @var{statenames} can be a cell array. ## -## If 'pseudotransitions' is specified then the integer matrix +## If @code{'pseudotransitions'} is specified then the integer matrix ## @var{pseudotransitions} is used as an initial number of counted ## transitions. @code{pseudotransitions (i, j)} is the initial number of ## counted transitions from state @code{i} to state @code{j}. ## @var{transprobest} will have the same size as @var{pseudotransitions}. -## Use this if you have transitions that are very unlikely to occur +## Use this if you have transitions that are very unlikely to occur. ## -## If 'pseudoemissions' is specified then the integer matrix +## If @code{'pseudoemissions'} is specified then the integer matrix ## @var{pseudoemissions} is used as an initial number of counted outputs. ## @code{pseudoemissions (i, j)} is the initial number of counted outputs -## @code{j} given state @code{i}. If 'pseudoemissions' is also specified -## then the number of rows of @var{pseudoemissions} must be the same as the -## number of rows of @var{pseudotransitions}. @var{outprobest} will have the -## same size as @var{pseudoemissions}. Use this if you have outputs or -## states that are very unlikely to occur +## @code{j} given state @code{i}. If @code{'pseudoemissions'} is also +## specified then the number of rows of @var{pseudoemissions} must be the +## same as the number of rows of @var{pseudotransitions}. @var{outprobest} +## will have the same size as @var{pseudoemissions}. Use this if you have +## outputs or states that are very unlikely to occur. ## ## Examples: ## ## @example +## @group ## transprob = [0.8, 0.2; 0.4, 0.6]; ## outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; ## [sequence, states] = hmmgenerate (25, transprob, outprob); ## [transprobest, outprobest] = hmmestimate (sequence, states) +## @end group ## +## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, 'symbols', symbols, 'statenames', statenames); ## [transprobest, outprobest] = hmmestimate (sequence, states, 'symbols', symbols, 'statenames', statenames) +## @end group ## +## @group ## pseudotransitions = [8, 2; 4, 6]; ## pseudoemissions = [2, 4, 4; 7, 2, 1]; ## [sequence, states] = hmmgenerate (25, transprob, outprob); ## [transprobest, outprobest] = hmmestimate (sequence, states, 'pseudotransitions', pseudotransitions, 'pseudoemissions', pseudoemissions) +## @end group ## @end example ## ## References: ## -## @itemize +## @enumerate ## @item -## @cite{Matlab 7.0 documentation (pdf)} +## W. L. Martinez and A. R. Martinez. @cite{Computational Statistics +## Handbook with MATLAB.} Chapman & Hall/CRC, pages 547-557, 2001. +## ## @item -## @uref{http://en.wikipedia.org/wiki/Maximum_likelihood} -## @end itemize +## Wikipedia contributors. Hidden Markov model. @cite{Wikipedia, The Free +## Encyclopedia.} +## @uref{http://en.wikipedia.org/w/index.php?title=Hidden_Markov_model&oldid=81100294}, +## October 2006. ## +## @item +## Wikipedia contributors. Maximum likelihood. @cite{Wikipedia, The Free +## Encyclopedia.} +## @uref{http://en.wikipedia.org/w/index.php?title=Maximum_likelihood&oldid=80805216}, +## October 2006. +## @end enumerate ## @end deftypefn ## Author: Arno Onken +## Description: Hidden Markov Model estimation for a given sequence function [transprobest, outprobest] = hmmestimate (sequence, states, varargin) diff -r a52a009b4908 -r e8b0cde34d1b main/statistics/inst/hmmgenerate.m --- a/main/statistics/inst/hmmgenerate.m Sun Oct 15 08:55:05 2006 +0000 +++ b/main/statistics/inst/hmmgenerate.m Sun Oct 15 19:50:42 2006 +0000 @@ -19,70 +19,83 @@ ## @deftypefnx {Function File} {} hmmgenerate (@dots{}, 'symbols', @var{symbols}) ## @deftypefnx {Function File} {} hmmgenerate (@dots{}, 'statenames', @var{statenames}) ## Generates an output sequence and hidden states for a Hidden Markov Model. -## The model starts with state @code{1} at step @code{0} but will not -## include step @code{0} in the generated states and sequence +## The model starts in state @code{1} at step @code{0} but will not include +## step @code{0} in the generated states and sequence. ## ## Arguments are ## -## @itemize +## @itemize @bullet ## @item ## @var{len} is the number of steps to generate. @var{sequence} and -## @var{states} will have @var{len} entries each +## @var{states} will have @var{len} entries each. +## ## @item -## @var{transprob} is the matrix with the transition probabilities for the -## states. @code{transprob (i, j)} is the probability for a transition to -## state @code{j} given state @code{i} +## @var{transprob} is the matrix of transition probabilities for the states. +## @code{transprob (i, j)} is the probability for a transition to state +## @code{j} given state @code{i}. +## ## @item -## @var{outprob} is the matrix with the output probabilities. +## @var{outprob} is the matrix of output probabilities. ## @code{outprob (i, j)} is the probability for generating output @code{j} -## given state @code{i} +## given state @code{i}. ## @end itemize ## ## Return values are ## -## @itemize +## @itemize @bullet ## @item -## @var{sequence} is a vector of length @var{len} with the generated +## @var{sequence} is a vector of length @var{len} of the generated ## outputs. The outputs are integers ranging from @code{1} to -## @code{columns (outprob)} +## @code{columns (outprob)}. +## ## @item -## @var{states} is a vector of length @var{len} with the generated hidden +## @var{states} is a vector of length @var{len} of the generated hidden ## states. The states are integers ranging from @code{1} to -## @code{columns (transprob)} +## @code{columns (transprob)}. ## @end itemize ## -## If 'symbols' is specified, then the elements of @var{symbols} are used -## for the output sequence instead of integers ranging from @code{1} to -## @code{columns (outprob)}. @var{symbols} can be a cell array +## If @code{'symbols'} is specified, then the elements of @var{symbols} are +## used for the output sequence instead of integers ranging from @code{1} to +## @code{columns (outprob)}. @var{symbols} can be a cell array. ## -## If 'statenames' is specified, then the elements of @var{statenames} are -## used for the states instead of integers ranging from @code{1} to -## @code{columns (transprob)}. @var{statenames} can be a cell array +## If @code{'statenames'} is specified, then the elements of +## @var{statenames} are used for the states instead of integers ranging from +## @code{1} to @code{columns (transprob)}. @var{statenames} can be a cell +## array. ## ## Examples: ## ## @example +## @group ## transprob = [0.8, 0.2; 0.4, 0.6]; ## outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; ## [sequence, states] = hmmgenerate (25, transprob, outprob) +## @end group ## +## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, 'symbols', symbols, 'statenames', statenames) +## @end group ## @end example ## ## References: ## -## @itemize +## @enumerate ## @item -## @cite{Matlab 7.0 documentation (pdf)} +## W. L. Martinez and A. R. Martinez. @cite{Computational Statistics +## Handbook with MATLAB.} Chapman & Hall/CRC, pages 547-557, 2001. +## ## @item -## @uref{http://en.wikipedia.org/wiki/Hidden_Markov_Model} -## @end itemize -## +## Wikipedia contributors. Hidden Markov model. @cite{Wikipedia, The Free +## Encyclopedia.} +## @uref{http://en.wikipedia.org/w/index.php?title=Hidden_Markov_model&oldid=81100294}, +## October 2006. +## @end enumerate ## @end deftypefn ## Author: Arno Onken +## Description: Output sequence and hidden states for a Hidden Markov Model function [sequence, states] = hmmgenerate (len, transprob, outprob, varargin) diff -r a52a009b4908 -r e8b0cde34d1b main/statistics/inst/hmmviterbi.m --- a/main/statistics/inst/hmmviterbi.m Sun Oct 15 08:55:05 2006 +0000 +++ b/main/statistics/inst/hmmviterbi.m Sun Oct 15 19:50:42 2006 +0000 @@ -20,68 +20,87 @@ ## @deftypefnx {Function File} {} hmmviterbi (@dots{}, 'statenames', @var{statenames}) ## Uses the Viterbi algorithm to find the Viterbi path for a Hidden Markov ## Model given a sequence of outputs. The model assumes that the generation -## begins with state @code{1} in step @code{0} but does not include step -## @code{0} in the generated states and sequence +## starts in state @code{1} at step @code{0} but does not include step +## @code{0} in the generated states and sequence. ## ## Arguments are ## -## @itemize +## @itemize @bullet ## @item -## @var{sequence} is the vector of length @var{len} with given outputs. The -## outputs must be integers ranging from @code{1} to @code{columns (outprob)} +## @var{sequence} is the vector of length @var{len} of given outputs. The +## outputs must be integers ranging from @code{1} to +## @code{columns (outprob)}. +## ## @item -## @var{transprob} is the matrix with the transition probabilities for the -## states. @code{transprob (i, j)} is the probability for a transition to -## state @code{j} given state @code{i} +## @var{transprob} is the matrix of transition probabilities for the states. +## @code{transprob (i, j)} is the probability for a transition to state +## @code{j} given state @code{i}. +## ## @item -## @var{outprob} is the matrix with the output probabilities. +## @var{outprob} is the matrix of output probabilities. ## @code{outprob (i, j)} is the probability for generating output @code{j} -## given state @code{i} +## given state @code{i}. ## @end itemize ## ## Return values are ## -## @itemize +## @itemize @bullet ## @item -## @var{vpath} is the vector of the same length as @var{sequence} with the +## @var{vpath} is the vector of the same length as @var{sequence} of the ## estimated hidden states. The states are integers ranging from @code{1} to -## @code{columns (transprob)} +## @code{columns (transprob)}. ## @end itemize ## -## If 'symbols' is specified, then @var{sequence} is expected to be a +## If @code{'symbols'} is specified, then @var{sequence} is expected to be a ## sequence of the elements of @var{symbols} instead of integers ranging -## from @code{1} to @code{columns (outprob)}. @var{symbols} can be a cell array +## from @code{1} to @code{columns (outprob)}. @var{symbols} can be a cell array. ## -## If 'statenames' is specified, then the elements of @var{statenames} are -## used for the states in @var{vpath} instead of integers ranging from -## @code{1} to @code{columns (transprob)}. @var{statenames} can be a cell array +## If @code{'statenames'} is specified, then the elements of +## @var{statenames} are used for the states in @var{vpath} instead of +## integers ranging from @code{1} to @code{columns (transprob)}. +## @var{statenames} can be a cell array. ## ## Examples: ## ## @example +## @group ## transprob = [0.8, 0.2; 0.4, 0.6]; ## outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1]; ## [sequence, states] = hmmgenerate (25, transprob, outprob) ## vpath = hmmviterbi (sequence, transprob, outprob) +## @end group ## +## @group ## symbols = @{'A', 'B', 'C'@}; ## statenames = @{'One', 'Two'@}; ## [sequence, states] = hmmgenerate (25, transprob, outprob, 'symbols', symbols, 'statenames', statenames) ## vpath = hmmviterbi (sequence, transprob, outprob, 'symbols', symbols, 'statenames', statenames) +## @end group ## @end example ## ## References: ## -## @itemize +## @enumerate ## @item -## @cite{Matlab 7.0 documentation (pdf)} +## W. L. Martinez and A. R. Martinez. @cite{Computational Statistics +## Handbook with MATLAB.} Chapman & Hall/CRC, pages 547-557, 2001. +## ## @item -## @uref{http://en.wikipedia.org/wiki/Viterbi_algorithm} -## @end itemize +## Wikipedia contributors. Hidden Markov model. @cite{Wikipedia, The Free +## Encyclopedia.} +## @uref{http://en.wikipedia.org/w/index.php?title=Hidden_Markov_model&oldid=81100294}, +## October 2006. ## +## @item +## Wikipedia contributors. Viterbi algorithm. @cite{Wikipedia, The Free +## Encyclopedia.} +## @uref{http://en.wikipedia.org/w/index.php?title=Viterbi_algorithm&oldid=73517908}, +## September 2006. +## @end enumerate ## @end deftypefn ## Author: Arno Onken +## Description: Viterbi path for a Hidden Markov Model function vpath = hmmviterbi (sequence, transprob, outprob, varargin)