<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>depth first search &#187; matlab</title>
	<atom:link href="http://www.depthfirstsearch.net/blog/tag/matlab/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.depthfirstsearch.net/blog</link>
	<description>“We can only see a short distance ahead, but we can see plenty there that needs to be done.&#34;</description>
	<lastBuildDate>Sun, 05 Feb 2012 13:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MATLAB versus R</title>
		<link>http://www.depthfirstsearch.net/blog/2009/05/27/matlab-versus-r/</link>
		<comments>http://www.depthfirstsearch.net/blog/2009/05/27/matlab-versus-r/#comments</comments>
		<pubDate>Wed, 27 May 2009 15:18:28 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[hmm]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=1013</guid>
		<description><![CDATA[I needed to apply the Viterbi algorithm for a recent homework. The problem set suggested using the HiddenMarkov CRAN package. Here&#8217;s the help page for the dthmm function: dthmm              package:HiddenMarkov              R Documentation Discrete Time HMM Object Description: Creates a discrete time hidden Markov model object with class '"dthmm"'. Usage: dthmm(x, Pi, delta, distn, pm, pn [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to apply the Viterbi algorithm for a recent homework. The problem set suggested using the HiddenMarkov CRAN package. Here&#8217;s the help page for the <em>dthmm</em> function:</p>
<pre>dthmm              package:HiddenMarkov              R Documentation

Discrete Time HMM Object

Description:

Creates a discrete time hidden Markov model object with class
'"dthmm"'.

Usage:

dthmm(x, Pi, delta, distn, pm, pn = NULL, discrete = NULL,
nonstat = TRUE)

Arguments:

x: is a vector of length n containing the observed process.
Alternatively, 'x' could be specified as 'NULL', meaning that
the data will be added later (e.g. simulated).

Pi: is the m times m transition probability matrix of the
homogeneous hidden Markov chain.

delta: is the marginal probability distribution of the m hidden
states at the first time point.

distn: is a character string with the distribution name, e.g.
'"norm"' or '"pois"'. If the distribution is specified as
'"wxyz"' then a distribution function called '"pwxyz"' should
be available, in the standard R format (e.g. 'pnorm' or
'ppois').

pm: is a list object containing the (Markov dependent) parameter
values associated with the distribution of the observed
process (see below).

pn: is a list object containing the observation dependent
parameter values associated with the distribution of the
observed process (see below).

discrete: is logical, and is 'TRUE' if 'distn' is a discrete
distribution. Set automatically for distributions already
contained in the package.

nonstat: is logical, 'TRUE' if the homogeneous Markov chain is assumed
to be non-stationary, default. See "Details" below.</pre>
<p>It&#8217;s okay. I don&#8217;t understand it either.</p>
<p>What I remember from lecture is that for discrete time HMMs you need a matrix of transition probabilities (the probability of a next state given the current state) and a matrix of emission probabilities (given a particular state, the probability of seeing a particular observation).</p>
<p>Ideally, I&#8217;d like an example of how to do just that &#8212; specify two matrices and a starting state and generate a whole bunch of HMM samples. Try as I might, I couldn&#8217;t figure out how to do that using the R function above. I&#8217;m sure it is possible, it just doesn&#8217;t seem to be obvious.</p>
<p>Now consider the MATLAB documentation.</p>
<pre>
Setting Up the Model and Generating Data

This section shows how to set up a hidden Markov model and use it
to generate data. First, create the transition and emission
matrices by entering the following commands.

TRANS = [.9 .1; .05 .95;];

EMIS = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6;...
7/12, 1/12, 1/12, 1/12, 1/12, 1/12];

Next, generate a random sequence of emissions from the model,
seq, of length 1000, using the function hmmgenerate. You can also
return the corresponding random sequence of states in the model
as the second output, states.  [seq, states] = hmmgenerate(1000,
TRANS, EMIS);

Note In generating the sequences seq and states, hmmgenerate
begins with the model in state i0 = 1 at step 0. The model then
makes a transition to state i1 at step 1, and returns i1 as the
first entry in states.  Computing the Most Likely Sequence of
States

Suppose you know the transition and emission matrices, TRANS and
EMIS. If you observe a sequence, seq, of emissions, how can you
compute the most likely sequence of states that generated the
sequence? The function hmmviterbi uses the Viterbi algorithm to
compute the most likely sequence of states that the model would
go through to generate the given sequence of emissions.
likelystates = hmmviterbi(seq, TRANS, EMIS);

likelystates is a sequence of the same length as seq.
</pre>
<p>You&#8217;ll notice that the functions take precisely the arguments you would expect, nothing more, nothing less. Moreover, the documentation takes you through setting up an HMM in exactly the same way as HMMs are normally taught.</p>
<p>Perhaps the MATLAB functionality is more limited that the R functionality, but I think there is something to be said for making the easy case easy, which R clearly doesn&#8217;t. I&#8217;m not always a fan of MATLAB, but the platforms competitive advantage seems to be the simplicity of the interface to a number of complex algorithms. This allows the average academic to quickly make use of a lot of powerful building blocks, building blocks that are not nearly so easy to use in other languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2009/05/27/matlab-versus-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matlab</title>
		<link>http://www.depthfirstsearch.net/blog/2008/05/13/matlab/</link>
		<comments>http://www.depthfirstsearch.net/blog/2008/05/13/matlab/#comments</comments>
		<pubDate>Tue, 13 May 2008 16:35:15 +0000</pubDate>
		<dc:creator>JS</dc:creator>
				<category><![CDATA[computer science]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://www.depthfirstsearch.net/blog/?p=442</guid>
		<description><![CDATA[I&#8217;ve recently started to use Matlab for various research purposes. Though aspects of the language seem very useful, I have noticed some interesting particularities. The mysterious double quote (&#8220;). This is a difficult to search for quirk. Some pages seem to indicate that the double quote has some meaning: You can also assign pieces of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently started to use Matlab for various research purposes. Though aspects of the language seem very useful, I have noticed some interesting particularities.</p>
<ol>
<li>The mysterious double quote (&#8220;). This is a difficult to search for quirk. Some pages seem to indicate that the double quote has <a href="http://www.mathworks.com/academia/student_center/tutorials/creating_variables.html">some meaning</a>:<br />
<blockquote><p>You can also assign pieces of text to variables, not just numbers. You do this using single quotes (not double quotes &#8212; single quotes and double quotes have different uses in MATLAB) around the text you want to assign to a variable.</p></blockquote>
<p>Other pages <a href="http://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB">indicate otherwise</a>:</p>
<blockquote><p>Matlab only supports single quotes, which means parsing errors will occur if you try to use double quotes (e.g. in an Octave script when run on Matlab).</p></blockquote>
</li>
<li>Then there is the issue of indexing. One can select multiple rows and columns using lists of the desired rows and columns: e.g. <code>A(1:10,2:4)</code>. However, given a list of coordinates <code>x = [i j]</code>, one cannot simply index <code>A(x)</code>. This will return the entries contained in rows i and columns j, not the entries (i,j) of A. This seems at odds with logical indexing, which does pull out individual entries: e.g. <code>A(A&gt;5)</code>. Of course there is a function for pulling out individual (i,j) entires. One has to call <code>sub2ind(size(A),i,j)</code>.</li>
<li>Finally, I sometimes need to run, say 200 or so processes in order to get experimental results. To do so would require ~200 Matlab licenses. That&#8217;s a lot of money needed to harness the kind of distributed computing power that characterizes not just research institutions, but many modern business environments (I ran large distributed computational processes even when I had a real job.) In the past I&#8217;ve had to port to Octave, which ended up saving me days of waiting for a serial Matlab process to finish.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.depthfirstsearch.net/blog/2008/05/13/matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/13 queries in 0.358 seconds using disk: basic
Object Caching 360/383 objects using disk: basic

Served from: www.depthfirstsearch.net @ 2012-02-07 14:35:01 -->
