<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>all models are wrong</title>
	<atom:link href="http://mikedewar.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikedewar.wordpress.com</link>
	<description>-- but some are useful</description>
	<lastBuildDate>Mon, 24 May 2010 18:18:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mikedewar.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/fe592d8580fd7227bab367a98cac70ad?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>all models are wrong</title>
		<link>http://mikedewar.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mikedewar.wordpress.com/osd.xml" title="all models are wrong" />
	<atom:link rel='hub' href='http://mikedewar.wordpress.com/?pushpress=hub'/>
		<item>
		<title>-&gt; Going both ways in R &lt;-</title>
		<link>http://mikedewar.wordpress.com/2010/05/19/going-both-ways-in-r/</link>
		<comments>http://mikedewar.wordpress.com/2010/05/19/going-both-ways-in-r/#comments</comments>
		<pubDate>Wed, 19 May 2010 18:16:39 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=287</guid>
		<description><![CDATA[Andy, in response to my griping on #Rstats, asks &#8220;What&#8217;s wrong with an arrow going both ways!?!?!&#8221; In R one can perfom assignment three ways: I&#8217;m pretty sure all these things are equivalent. The only subtlety I&#8217;ve noticed so far is that to set default options in function definitions you have to use `=`. This redundancy drives [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=287&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/almostandy">Andy</a>, in response to my griping on #Rstats, asks &#8220;What&#8217;s wrong with an arrow going both ways!?!?!&#8221; In R one can perfom assignment three ways:</p>
<p><pre class="brush: plain;">
a = 2
a &lt;- 2
2 -&gt; a
</pre></p>
<p>I&#8217;m pretty sure all these things are equivalent. The only subtlety I&#8217;ve noticed so far is that to set default options in function definitions you have to use `=`.</p>
<p>This redundancy drives me absolutely nuts as an R beginner. From a human point of view code has two main jobs: to be written and to be read. Now for the first job, having three different ways to assign a value to a variable might be nice? I&#8217;m not sure how, but I guess it would be nice sometimes to write a function, then remember that you hadn&#8217;t assigned it a variable and do it at the end instead.</p>
<p>For the second job  though, reading R is awful. Now I&#8217;ve heard horror stories about perl, so maybe it&#8217;s just that I&#8217;m used to <a href="http://www.python.org/dev/peps/pep-0008/">readable code</a> and that, in the big scheme of things, R is nice and readable. But yesterday, ploughing through someone&#8217;s metaprogramming, tearing at my hair as to the obtuseness of everything, I was foiled for about an hour having not realised that the fsking arrow could go both ways.</p>
<p>I think it highlights a big flaw in R. Sometimes it&#8217;s like no &#8220;destructive&#8221; design decisions have been taken since the original work of Ihaka and Gentleman. I spend so much time messing about trying to convert a data.frame of factors into a list of &#8220;vectors&#8221; of strings or something. It seems that no-one has ever said &#8220;OK, we need a way to assign a value to a variable: let&#8217;s pick one&#8221;. Instead three have emerged. There are two different types of classes (which only seems to have any real effect on the help files). There are loads of data types that are in regular use, with somewhat bastardised names (i.e. a &#8216;vector&#8217;, &#8216;matrix&#8217;, &#8216;list&#8217;, &#8216;array&#8217; are all different things &#8211; a vector doesn&#8217;t seem to be a subclass of matrix, for example).</p>
<p>Now, I&#8217;m sure that the pluralities in R could maybe be held up to be a good thing. They probably encode subtleties that I don&#8217;t understand, and that my bitching is just me exposing my naivety about the language. And I know that R is descended from LISP and S and that its user base either grew up with R or with one of these other languages. Therefore things that are natural to this background will seem alien to someone like me with a MATLAB and Python background. And there&#8217;s backwards compatibility to consider and so on.</p>
<p>So don&#8217;t get me wrong &#8211; I think R is an amazing piece of work, and the communities around R are incredibly devoted and responsive. It&#8217;s kind of like the &#8220;first&#8221; three episodes of Star Wars: there&#8217;s an amazing film in there somewhere, it just needs some editorial decisions to be made. Maybe a new &#8220;Hadley&#8221; language will be born whereby R is completely re-API&#8217;d into a single language that only uses data.frames&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=287&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2010/05/19/going-both-ways-in-r/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>finding homologous probes using biomaRt</title>
		<link>http://mikedewar.wordpress.com/2010/05/14/generating-homologues-using-biomart/</link>
		<comments>http://mikedewar.wordpress.com/2010/05/14/generating-homologues-using-biomart/#comments</comments>
		<pubDate>Fri, 14 May 2010 19:43:11 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=284</guid>
		<description><![CDATA[I asked a question on the superb biostar stackexchange site. It&#8217;s here: http://biostar.stackexchange.com/questions/1054/homology-bioconductor It&#8217;s about finding geneome-wide homologies using bioconductor. It turns out that bioconductor has a package called biomaRt which allows you to query the Ensembl databases with ease. (Ensembl stores gene information for a bunch of different organisms). I thought I&#8217;d write down [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=284&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I asked a question on the superb biostar stackexchange site. It&#8217;s here: http://biostar.stackexchange.com/questions/1054/homology-bioconductor</p>
<p>It&#8217;s about finding geneome-wide homologies using bioconductor. It turns out that bioconductor has a package called biomaRt which allows you to query the Ensembl databases with ease. (Ensembl stores gene information for a bunch of different organisms).</p>
<p>I thought  I&#8217;d write down my solution here, as a sort of extended answer to my question on biostar, in case anyone trips up on the question there and would like a more complete answer. You&#8217;ll need to read the question before any of this code makes sense!</p>
<p><pre class="brush: plain;">
library(biomaRt)
gen_hs2mm &lt;- function(affyids){
    ensembl_hs &lt;- useMart(
        &quot;ensembl&quot;,
        dataset = &quot;hsapiens_gene_ensembl&quot;
    )
    hs2mm_filters &lt;- c(
        &quot;affy_hg_u133a&quot;,
        &quot;with_mmusculus_homolog&quot;
    )
    hs2mm_gene_atts &lt;- c(
         &quot;affy_hg_u133a&quot;,
        &quot;ensembl_gene_id&quot;
    )
    hs2mm_homo_atts &lt;- c(
        &quot;ensembl_gene_id&quot;,
        &quot;mouse_ensembl_gene&quot;
    )
    # the names in these lists are arbitrary
    hs2mm_value = list(
        affyid=affyids,
        with_homolog=TRUE
    )
    # get the human genes and mouse orthologues
    hs2mm_gene &lt;- getBM(
        attributes = hs2mm_gene_atts,
        filters = hs2mm_filters,
        value = hs2mm_value,
        mart = ensembl_hs
    )
    hs2mm_homo &lt;- getBM(
        attributes = hs2mm_homo_atts,
        filters = hs2mm_filters,
        value = hs2mm_value,
        mart = ensembl_hs
    )
    # merge the two lists!
    hs2mm &lt;- merge(hs2mm_gene,hs2mm_homo)
}

gen_mm2hs &lt;- function(affyids){
    ensembl_mm &lt;- useMart(&quot;ensembl&quot;,
        dataset = &quot;mmusculus_gene_ensembl&quot;)
        mm2hs_filters &lt;- c(
        &quot;affy_mogene_1_0_st_v1&quot;,
        &quot;with_hsapiens_homolog&quot;
    )
    mm2hs_gene_atts &lt;- c(
        &quot;affy_mogene_1_0_st_v1&quot;,
        &quot;ensembl_gene_id&quot;
    )
    mm2hs_homo_atts &lt;- c(
        &quot;ensembl_gene_id&quot;,
        &quot;human_ensembl_gene&quot;
    )
    # the names in these lists are arbitrary
    mm2hs_value = list(
        affyids=affyids,
        with_homolog=TRUE
    )
    # get the mouse genes and human orthologues
    mm2hs_gene &lt;- getBM(
        attributes = mm2hs_gene_atts ,
        filters = mm2hs_filters,
        value = mm2hs_value,
        mart = ensembl_mm
    )
    mm2hs_homo &lt;- getBM(
        attributes = mm2hs_homo_atts,
        filters = mm2hs_filters,
        value = mm2hs_value,
        mart = ensembl_mm
    )
    mm2hs &lt;- merge(mm2hs_gene,mm2hs_homo)
}
source('load_data.r')
# here immgen and cd4T are different experession set objects 
# from Bioconductor.
# immgen is mouse data (from the Immunological Genome Project) 
# and cd4T is human data
# cd4T can be found on GEO using the accessionID GDS785 
# See ref[1]
immgen &lt;- load_immgen()
cd4T &lt;- load_GDS785()
hs2mm &lt;- gen_hs2mm(rownames(exprs(cd4T)))
mm2hs &lt;- gen_mm2hs(rownames(exprs(immgen)))
colnames(hs2mm)[1] &lt;- 'human_ensembl_gene'
colnames(mm2hs)[1] &lt;- 'mouse_ensembl_gene'
# the final thing is to merge the two tables to make a single 
# table containing all the probes that are homologous, along 
# with their respsective EnsemblIDs
homol &lt;- merge(hs2mm,mm2hs)
</pre></p>
<p><span style="font-family:verdana, helvetica, clean, sans-serif;line-height:normal;white-space:normal;border-collapse:collapse;"><span class="authors">[1] Lee MS, Hanspers K, Barker CS, Korn AP et al. </span><span class="title" style="color:#707070;">Gene expression profiles during human CD4+ T cell differentiation. </span><span class="source" style="font-style:italic;">Int Immunol</span>2004 Aug;16(8):1109-24. PMID: <a style="color:#006400;text-decoration:none;" title="Link to PubMed record" href="http://www.ncbi.nlm.nih.gov/sites/entrez?Db=Pubmed&amp;term=15210650[UID]">15210650</a></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=284&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2010/05/14/generating-homologues-using-biomart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>Profiling in R</title>
		<link>http://mikedewar.wordpress.com/2010/05/13/profiling-in-r/</link>
		<comments>http://mikedewar.wordpress.com/2010/05/13/profiling-in-r/#comments</comments>
		<pubDate>Thu, 13 May 2010 15:14:17 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=272</guid>
		<description><![CDATA[Giving a quick talk about vectorising code in R next month. Need to learn about profiling in R. This is what I have discovered in the last hour or so (when I should have been working): Rprof() This is the basic profiler in R. One turns it on: Rprof("profile.out") One runs some code &#8230; and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=272&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">Giving a quick talk about vectorising code in R next month. Need to learn about profiling in R. This is what I have discovered in the last hour or so (when I should have been working):</div>
<h1>Rprof()</h1>
<div id="_mcePaste">This is the basic profiler in R. One turns it on:</div>
<pre style="padding-left:30px;">Rprof("profile.out")</pre>
<div id="_mcePaste">One runs some code &#8230; and one turns it off using, as always, R&#8217;s intuitive API</div>
<pre style="padding-left:30px;">Rprof(NULL)</pre>
<div id="_mcePaste">To see the results, you can use `summaryRprof(&#8220;profile.out&#8221;)` which parses the file you made using Rprof and presents it in a nice clear format, which looks something like:</div>
<pre style="padding-left:30px;">&gt; summaryRprof("method1.out")</pre>
<pre style="padding-left:30px;">$by.self</pre>
<pre style="padding-left:30px;">self.time self.pct total.time total.pct</pre>
<pre style="padding-left:30px;">"strsplit"          4.08     94.0       4.10      94.5</pre>
<pre style="padding-left:30px;">"+"                 0.12      2.8       0.12       2.8</pre>
<pre style="padding-left:30px;">"is.character"      0.12      2.8       0.12       2.8</pre>
<pre style="padding-left:30px;">"as.logical"        0.02      0.5       0.02       0.5</pre>
<pre style="padding-left:30px;">$by.total</pre>
<pre style="padding-left:30px;">total.time total.pct self.time self.pct</pre>
<pre style="padding-left:30px;">"strsplit"           4.10      94.5      4.08     94.0</pre>
<pre style="padding-left:30px;">"+"                  0.12       2.8      0.12      2.8</pre>
<pre style="padding-left:30px;">"is.character"       0.12       2.8      0.12      2.8</pre>
<pre style="padding-left:30px;">"as.logical"         0.02       0.5      0.02      0.5</pre>
<div id="_mcePaste">There&#8217;s more detail <a href="http://cran.r-project.org/doc/manuals/R-exts.html#Tidying-and-profiling-R-code.">here</a> about `Rprof()` and `summaryRprof()`.</div>
<h1>proftools</h1>
<div id="_mcePaste">This package presents an alternative to summaryRprof, using graphviz to generate teh pretteh. Not sure how massively useful it would be in practice, unless your code got pretty complex! I&#8217;d be interested to know how complicated people&#8217;s functions actually got when using R.</div>
<div id="_mcePaste">To make the graph, make sure you have graph and Rgraphviz properly installed, then bash out</div>
<pre style="padding-left:30px;">plotProfileCallGraph("profile.out")</pre>
<div id="_mcePaste">see http://cran.r-project.org/web/packages/proftools/index.html for more.</div>
<h1>profr</h1>
<div id="_mcePaste">I kind of want everything Hadley Wickham does to be awesome, so when I see he&#8217;s made a profiling tool, I give it a lot more attention than it necessarily deserves. For example, you won&#8217;t find me hunting for documentation through anyone else&#8217;s github account. Nevertheless, this is what I find myself doing for `profr` (which in my head I will be pronouncing &#8220;proffer&#8221;). Note: it does turn out that I could have simply typed ?profr in my R terminal (does this always work)?</div>
<div id="_mcePaste">To use, simply run</div>
<pre style="padding-left:30px;">out &lt;- profr(code_to_profile)</pre>
<div id="_mcePaste">then to inspect it use the normal `head`, `tail` and `summary`, noting that `out` is (pretty much) a `data.frame`:</div>
<pre style="padding-left:30px;">&gt; head(out)</pre>
<pre style="padding-left:30px;">f level time start  end  leaf source</pre>
<pre style="padding-left:30px;">8      example     1 0.44  0.00 0.44 FALSE  utils</pre>
<pre style="padding-left:30px;">9  &lt;Anonymous&gt;     2 0.04  0.00 0.04 FALSE   &lt;NA&gt;</pre>
<pre style="padding-left:30px;">10     library     2 0.02  0.04 0.06 FALSE   base</pre>
<pre style="padding-left:30px;">11      source     2 0.38  0.06 0.44 FALSE   base</pre>
<pre style="padding-left:30px;">12  prepare_Rd     3 0.04  0.00 0.04 FALSE   &lt;NA&gt;</pre>
<pre style="padding-left:30px;">13        %in%     3 0.02  0.04 0.06 FALSE   base</pre>
<pre style="padding-left:30px;">&gt; summary(out)</pre>
<pre style="padding-left:30px;">f          level             time          start</pre>
<pre style="padding-left:30px;">match        : 7   Min.   : 1.000   Min.   :0.02   Min.   :0.0000</pre>
<pre style="padding-left:30px;">%in%         : 6   1st Qu.: 5.000   1st Qu.:0.02   1st Qu.:0.1200</pre>
<pre style="padding-left:30px;">is.factor    : 6   Median : 7.000   Median :0.02   Median :0.1600</pre>
<pre style="padding-left:30px;">eval.with.vis: 6   Mean   : 8.113   Mean   :0.04   Mean   :0.1685</pre>
<pre style="padding-left:30px;">inherits     : 5   3rd Qu.:10.500   3rd Qu.:0.02   3rd Qu.:0.2200</pre>
<pre style="padding-left:30px;">&lt;Anonymous&gt;  : 3   Max.   :19.000   Max.   :0.44   Max.   :0.4200</pre>
<pre style="padding-left:30px;">(Other)      :82</pre>
<pre style="padding-left:30px;">end            leaf            source</pre>
<pre style="padding-left:30px;">Min.   :0.0200   Mode :logical   Length:115</pre>
<pre style="padding-left:30px;">1st Qu.:0.1400   FALSE:99        Class :character</pre>
<pre style="padding-left:30px;">Median :0.2000   TRUE :16        Mode  :character</pre>
<pre style="padding-left:30px;">Mean   :0.2085   NA's :0</pre>
<pre style="padding-left:30px;">3rd Qu.:0.2500</pre>
<pre style="padding-left:30px;">Max.   :0.4400</pre>
<p>Here I should say that `code_to_profile` was the standard `example(glm)`. One can also use `plot()` or `ggplot()` to plot the &#8216;call tree&#8217;. I&#8217;m not quite sure what a &#8216;call tree&#8217; is, and to be honest the (adimittedly pretty) graph that `ggplot(out)` produces doesn&#8217;t enlighten me a great deal. That&#8217;s OK though &#8211; all I really wanted was the time spent.</p>
<p>A quick point about Hadley&#8217;s code, that I think highlights something wrong with R in general (and right with Python) is that in `profr`, from a user perspective I don&#8217;t really have to learn anything new to make it work. I apply a function (handily called `profr`) to some code and I get back a `data.frame` on which I can use very standard tools in order to investigate. I don&#8217;t have to write to a file (or generate a temp file to write to or anything), I don&#8217;t have to learn to stop and start hidden things, or that to stop profiling I pass `NULL` to a function that started profiling. I don&#8217;t have to use a whole new tool to parse what is basically a table. And to plot I can just use `plot` rather than having to dissapear down the (admittedly fun) hole that is graphviz. It feels like every new thing I come across in R means learning a whole API and set of concepts and object structure. (Admittedly ggplot is the total opposite of this, but hey I guess that was the point)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/272/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/272/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=272&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2010/05/13/profiling-in-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>More Segment HMMs</title>
		<link>http://mikedewar.wordpress.com/2009/04/23/more-segment-hmms/</link>
		<comments>http://mikedewar.wordpress.com/2009/04/23/more-segment-hmms/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:04:47 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=195</guid>
		<description><![CDATA[It&#8217;s weird how you can muck about with structures for so long and still forget what the hell you&#8217;re doing all the time. This post is supposed to try and clarify segment HMMs a bit for me, so that I can approach the learning problem with a clear mind. It&#8217;s all very specific; and it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=195&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s weird how you can muck about with structures for so long and still forget what the hell you&#8217;re doing all the time. This post is supposed to try and clarify segment HMMs a bit for me, so that I can approach the learning problem with a clear mind. It&#8217;s all very specific; and it&#8217;s all below the fold.</p>
<p><span id="more-195"></span>I&#8217;m going to define the model again. Notation is important:</p>
<ul>
<li><img src='http://s0.wp.com/latex.php?latex=p%28Q_%7Bt%2Bl%7D%3Dq_j+%7CQ_t%3D+q_i%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_{t+l}=q_j |Q_t= q_i)' title='p(Q_{t+l}=q_j |Q_t= q_i)' class='latex' />: state transition probability</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28L_t%3Dl%7CQ_t%3Dq%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(L_t=l|Q_t=q)' title='p(L_t=l|Q_t=q)' class='latex' />: duration density</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28y_t%2C%5Cldots%2C+y_%7Bt%2Bl-1%7D%7CQ_t%3Dq%2CL_t%3Dl%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(y_t,&#92;ldots, y_{t+l-1}|Q_t=q,L_t=l)' title='p(y_t,&#92;ldots, y_{t+l-1}|Q_t=q,L_t=l)' class='latex' />: segment density</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28Q_0%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_0)' title='p(Q_0)' class='latex' />: initial state distribution</li>
</ul>
<p>Some things to note.</p>
<ol>
<li>The state transition probability doesn&#8217;t really care how long the segment associated with q_i is. This means that the transition is invariant under changes to <img src='http://s0.wp.com/latex.php?latex=l&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='l' title='l' class='latex' /> which kind of means the whole thing is still Markovian, though this enough for people to start using terms like &#8216;semi-Markovian&#8217; which is kind of confusing.</li>
<li>The duration of the state at time <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='t' title='t' class='latex' /> is dependent on the state at time <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='t' title='t' class='latex' />. This implies that:</li>
<li>The segment starts at time <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='t' title='t' class='latex' /> and lasts for <img src='http://s0.wp.com/latex.php?latex=l&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='l' title='l' class='latex' /> time steps. This means that the last time index in the &#8216;current&#8217; segment is <img src='http://s0.wp.com/latex.php?latex=t%2Bl-1&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='t+l-1' title='t+l-1' class='latex' />.</li>
</ol>
<p>What we&#8217;d like to do is write this out as a properly specified graphical model, but it turns out that this is pretty hard to do for the general case. As a first crack I tried introducing a counting variable <img src='http://s0.wp.com/latex.php?latex=C_t&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='C_t' title='C_t' class='latex' />. Unfortunately it doesn&#8217;t qutie make it, but was a useful learning experience. So, with a counting variable we can write the alternative model out as follows:</p>
<ol>
<li><img src='http://s0.wp.com/latex.php?latex=p%28C_t%3Dc_j%7CC_%7Bt-1%7D%3Dc_i%2CQ_t%3Dq_j%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j)' title='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j)' class='latex' />: counting variable transition distribution</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28Q_%7Bt%7D%3Dq_j%7CQ_%7Bt-1%7D%3Dq_i%2CC_%7Bt-1%7D%3Dc_i%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i)' title='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i)' class='latex' />: state transition probability conditioned on the counting variable at the previous time point</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28y_t%2C%5Cldots%2C+y_%7Bt%2Bl-1%7D%7CQ_t%3Dq%2CC_t%3Dl%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(y_t,&#92;ldots, y_{t+l-1}|Q_t=q,C_t=l)' title='p(y_t,&#92;ldots, y_{t+l-1}|Q_t=q,C_t=l)' class='latex' />: segment density</li>
<li><img src='http://s0.wp.com/latex.php?latex=p%28Q_0%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_0)' title='p(Q_0)' class='latex' />: initial state distribution</li>
</ol>
<p>The counting variable either decrements or resets, such that <img src='http://s0.wp.com/latex.php?latex=p%28C_t%3Dc_j%7CC_%7Bt-1%7D%3Dc_i%2CQ_t%3Dq_j%29+%3D+%5Cdelta%28c_i-1%29%2C+%7E+c_i+%3E+1&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j) = &#92;delta(c_i-1), ~ c_i &gt; 1' title='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j) = &#92;delta(c_i-1), ~ c_i &gt; 1' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=p%28C_t%3Dc_j%7CC_%7Bt-1%7D%3Dc_i%2CQ_t%3Dq_j%29+%3D+p%28C_t%3Dc_j%7CQ_t%3Dq_j%29%2C+%7E+c_i+%3D+1&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j) = p(C_t=c_j|Q_t=q_j), ~ c_i = 1' title='p(C_t=c_j|C_{t-1}=c_i,Q_t=q_j) = p(C_t=c_j|Q_t=q_j), ~ c_i = 1' class='latex' />. Here <img src='http://s0.wp.com/latex.php?latex=p%28C_t%3Dc_j%7CQ_t%3Dq_j%29&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(C_t=c_j|Q_t=q_j)' title='p(C_t=c_j|Q_t=q_j)' class='latex' /> is simply the duration density, such that when the counter resets it starts off at a new duration.</p>
<p>Similarly, the state variable either stays the same or transitions depending on the counting variable. So <img src='http://s0.wp.com/latex.php?latex=p%28Q_%7Bt%7D%3Dq_j%7CQ_%7Bt-1%7D%3Dq_i%2CC_%7Bt-1%7D%3Dc_i%29+%3D+%5Cdelta%28Q_%7Bt%7D%3Dq_i%29%2C+%7E+c_i+%3E+1&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i) = &#92;delta(Q_{t}=q_i), ~ c_i &gt; 1' title='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i) = &#92;delta(Q_{t}=q_i), ~ c_i &gt; 1' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=p%28Q_%7Bt%7D%3Dq_j%7CQ_%7Bt-1%7D%3Dq_i%2CC_%7Bt-1%7D%3Dc_i%29+%3D+p%28Q_%7Bt%7D%3Dq_j%7CQ_%7Bt-1%7D%3Dq_i%29%2C+%7E+c_i+%3D+1&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i) = p(Q_{t}=q_j|Q_{t-1}=q_i), ~ c_i = 1' title='p(Q_{t}=q_j|Q_{t-1}=q_i,C_{t-1}=c_i) = p(Q_{t}=q_j|Q_{t-1}=q_i), ~ c_i = 1' class='latex' />.</p>
<p>So we&#8217;ve swapped some awkardness in having two ideas of time&#8217;s passage &#8211; one for the underlying state and one for the observations &#8211; with some awkwardness of defining these conditional densities.</p>
<p>As it stands, though, we&#8217;re still stuck with a variable topology &#8211; the introduction of the counting variable hasn&#8217;t really changed the fact that the segment density changes dimension dependent on <img src='http://s0.wp.com/latex.php?latex=l&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='l' title='l' class='latex' />. If each observation was independent given the state then the counting variable would be all we need to get a nice regular graph.</p>
<p>The observations aren&#8217;t independent though! This is the big difference between Segment HMMs and what are known as explicit-duration HMMs. Hence to be able to draw a graph <em>we must make some assumptions on the form of the output density</em>. Murphy actually states this in one of his technical reports, but it seems to have taken a couple of months for it to actually sink in. Next step, then, is a graphical model for a <img src='http://s0.wp.com/latex.php?latex=p&amp;bg=ffffff&amp;fg=555555&amp;s=0' alt='p' title='p' class='latex' />th order explicit duration switching AR model! I think I&#8217;ll save that for the next post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=195&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/04/23/more-segment-hmms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>Python and Numpy integers</title>
		<link>http://mikedewar.wordpress.com/2009/03/30/python-and-numpy-integers/</link>
		<comments>http://mikedewar.wordpress.com/2009/03/30/python-and-numpy-integers/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 13:26:04 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[python gotcha]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=188</guid>
		<description><![CDATA[I keep getting bitten on the bum with Python and &#8216;proper&#8217; programming things. Today it&#8217;s this: I would feel guilty about this if I had to specify the type of numbers I was using, but this is a dynamic programming language! How the hell am I supposed to know that raising an int by a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=188&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I keep getting bitten on the bum with Python and &#8216;proper&#8217; programming things. Today it&#8217;s this:</p>
<pre><pre class="brush: python;">

In [253]: 8**14
Out[253]: 4398046511104L

In [254]: 8**(numpy.int32(14))
Out[254]: 0

</pre></pre>
<p>I would feel guilty about this if I had to specify the type of numbers I was using, but this is a dynamic programming language! How the hell am I supposed to know that raising an int by a numpy.int32 will force the result to also be an numpy.int32 (and therefore (silently) 0 because int32 can&#8217;t hold my number) whereas raising an int by an int will result in a long? Why didn&#8217;t the int32 become a long also? Or an int64 or something that could hold my number?</p>
<p>Gah!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=188&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/03/30/python-and-numpy-integers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>Nasty Python Things</title>
		<link>http://mikedewar.wordpress.com/2009/03/27/nasty-python-things/</link>
		<comments>http://mikedewar.wordpress.com/2009/03/27/nasty-python-things/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 10:59:23 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=180</guid>
		<description><![CDATA[So I seem to keep writing commands that look like this: Is this bad? The above is the max of a list. The list is made up using a list comprehension, where each element is the log of a product of a 1D array plus a bit. Each element of each array is a call [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=180&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I seem to keep writing commands that look like this:</p>
<p><pre class="brush: python;">
delta[t][q] = max(
    [delta[tau][j] +
        pylab.log(
            pylab.array([
                output_dist(Q=q,L=(t-tau),Y=Y[tau+1:t]),
                duration_dist(Q=q,L=(t-tau)),
                transition_dist[q,j]]).prod())            
    for j in self.state_range])
</pre></p>
<p>Is this bad? The above is the max of a list. The list is made up using a list comprehension, where each element is the log of a product of a 1D array plus a bit. Each element of each array is a call to a function associated with my model. The trouble is, if I break it down into some for loops, then I start having to invent temporary names for my variables, which seems clunky.</p>
<p>Any opinions?</p>
<p>M</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=180&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/03/27/nasty-python-things/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>MICROCOSMOGRAPHIA ACADEMICA</title>
		<link>http://mikedewar.wordpress.com/2009/03/03/microcosmographia-academica/</link>
		<comments>http://mikedewar.wordpress.com/2009/03/03/microcosmographia-academica/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 14:01:20 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[extra-curricular]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=170</guid>
		<description><![CDATA[I came across the Microcosmographia Academia in one of Niranjan&#8216;s slides (which are an interesting view into the world of academic politics and bureaucracy) and then found it in full at the webpage of Dr Utting of Kent University. It&#8217;s a lovely satire on academic politics from 1908 in the form of a short pamphlet. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=170&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I came across the <a href="http://en.wikipedia.org/wiki/Microcosmographia_Academica">Microcosmographia Academia</a> in one of <a href="http://www.ecs.soton.ac.uk/people/mn">Niranjan</a>&#8216;s slides (which are an interesting view into the world of academic politics and bureaucracy) and then found it in full at the <a href="http://www.cs.kent.ac.uk/people/staff/iau/cornford/cornford.html">webpage of Dr Utting of Kent University</a>. It&#8217;s a lovely satire on academic politics from 1908 in the form of a short pamphlet. Just short enough, in fact, that I&#8217;ve wasted a good hour typesetting it [<a href="http://homepages.inf.ed.ac.uk/mdewar1/Microcosmographia_Academica.pdf">pdf</a>,<a href="http://homepages.inf.ed.ac.uk/mdewar1/Microcosmographia_Academica.tex">tex</a>]. It starts with this small &#8216;advertisement&#8217;:</p>
<blockquote><p>If you are young, do not read this book; it is not fit for you;<br />
If you are old, throw it away; you have nothing to learn from it;<br />
If you are unambitious, light the fire with it; you do not need its guidance.</p>
<p>But, if you are neither less than twenty-five years old, nor more than thirty;<br />
And if you are ambitious withal, and your spirit hankers after academic politics;<br />
Read, and may your soul (if you have a soul) find mercy!</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=170&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/03/03/microcosmographia-academica/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>Pebl</title>
		<link>http://mikedewar.wordpress.com/2009/02/28/pebl/</link>
		<comments>http://mikedewar.wordpress.com/2009/02/28/pebl/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 11:36:19 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=165</guid>
		<description><![CDATA[Look! A python module for learning bayesian network structures has surfaced on the JMLR software track &#8211; bits of the author&#8217;s blog are quite interesting too&#8230; This is article number 5 for the software track in JMLR, and it&#8217;s been going over a year now! I suppose 5 examples is quite enough to figure out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=165&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Look! A python module for learning bayesian network structures has <a href="http://jmlr.csail.mit.edu/papers/v10/shah09a.html">surfaced on the JMLR software track</a> &#8211; bits of the <a href="http://ano.malo.us/">author&#8217;s blog</a> are quite interesting too&#8230; This is article number 5 for the software track in JMLR, and it&#8217;s been going over a year now! I suppose 5 examples is quite enough to figure out what&#8217;s required for submission here, though, so maybe uptake will improve&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/165/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/165/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=165&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/02/28/pebl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>The Pirate Bay Trial</title>
		<link>http://mikedewar.wordpress.com/2009/02/28/the-pirate-bay-trial/</link>
		<comments>http://mikedewar.wordpress.com/2009/02/28/the-pirate-bay-trial/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 11:28:57 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[extra-curricular]]></category>
		<category><![CDATA[social]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=144</guid>
		<description><![CDATA[So Stina wrote a piece for the independent about the Pirate Bay Trials which reminded me: I&#8217;m really upset about the implications of this attack one of the main hubs of the new social order! Just in case  you don&#8217;t know, The Pirate Bay is a place for downloading torrent files, which are little files [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=144&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So Stina wrote a <a href="http://www.independent.co.uk/life-style/gadgets-and-tech/news/pirate-bay-filesharing-trial-starts-1623432.html">piece</a> for the independent about the Pirate Bay Trials which reminded me: I&#8217;m really upset about the implications of this attack one of the main hubs of the new social order! Just in case  you don&#8217;t know, <a href="http://thepiratebay.org/">The Pirate Bay</a> is a place for downloading torrent files, which are little files that help you download bigger files from people all over the world. Generally, it&#8217;s used for downloading things you&#8217;ve not bought, and so helps us in the grand copyright infringement which, apart from making us feel kind of smug and priatey, proves the inefficiency in the market for such digital things and ultimately, hopefully, will change the state of play. See <a href="http://www.stealthisfilm.com">Steal This Film</a> for more info.</p>
<p>Here, I just wanted to link to some coverage of the trial, which is illuminating. There&#8217;s <a href="http://trial.thepiratebay.org/">Spectrical</a> which is the sort of `official&#8217; coverage, then there&#8217;s also <a href="http://torrentfreak.com/">TorrentFreak&#8217;s coverage</a> which has an especially moving piece about one of the wife of one of the witnesses for the defence being sent a load of flowers. Then there&#8217;s also the mainstream coverage in the Guardian, in Cory Doctorow&#8217;s column <a href="http://www.guardian.co.uk/technology/series/digitalwrongs">Digital rights, digital wrongs</a>. It all goes to show the lengths people go in order to restrict change. I wonder if I&#8217;ll be as motivated as the record companies when something I don&#8217;t want to change comes along? Hopefully, at least, I&#8217;ll be better informed than these dinosaurs&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=144&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/02/28/the-pirate-bay-trial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>
	</item>
		<item>
		<title>Latex, Beamer, Python, Beauty</title>
		<link>http://mikedewar.wordpress.com/2009/02/25/latex-beamer-python-beauty/</link>
		<comments>http://mikedewar.wordpress.com/2009/02/25/latex-beamer-python-beauty/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 20:45:49 +0000</pubDate>
		<dc:creator>mikedewar</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[beamer]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://mikedewar.wordpress.com/?p=141</guid>
		<description><![CDATA[This post quickly shows how to create pretty latex beamer slides, that don&#8217;t look anything much like maths seminar slides, and  that can include well formatted (Python) code, as well as the normal stuff that Beamer is so good at (maths, videos, etc). I&#8217;m assuming you&#8217;ve got a `standard&#8217; install of latex (by standard I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=141&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post quickly shows how to create pretty latex beamer slides, that don&#8217;t look anything much like maths seminar slides, and  that can include well formatted (Python) code, as well as the normal stuff that Beamer is so good at (maths, videos, etc). I&#8217;m assuming you&#8217;ve got a `standard&#8217; install of latex (by standard I mean: like mine) that includes beamer and the listings package. I&#8217;m also assuming that you already know how to use beamer, so I&#8217;ve not included all the documentclass junk and so on. Here&#8217;s a taster of what it looks like, how to do it is after the break:</p>
<p><img class="aligncenter size-full wp-image-148" title="beamer_screen" src="http://mikedewar.files.wordpress.com/2009/02/beamer_screen.png?w=480&#038;h=360" alt="beamer_screen" width="480" height="360" /></p>
<p><span id="more-141"></span></p>
<p>There are three things we need to do to make beamer slides like this that don&#8217;t look like those endless maths-y beamer slides that everyone seems to like for some reason.</p>
<ol>
<li>Get rid of all the junk on the top and the bottom! No-one can see it anyway!</li>
<li>Make the colours of the presentation very pretty.</li>
<li>Make the listings use a better font than courier, and also use pretty colours!</li>
</ol>
<p><strong>1: get rid of all the junk</strong></p>
<p>This is an awesome command. It&#8217;s (maybe) the longest single command ever in the world, sort of like that village in Wales with the huge name:</p>
<p><pre class="brush: plain;">
/usetheme{default}
/beamertemplatenavigationsymbolsempty
</pre></p>
<p>So now, your beamer presentation is nice and clean and happy.</p>
<p><strong>2: Make Pretty Colours</strong></p>
<p>This is just like knowing the magic words. We define a colour, then we assign it to a magic word. So lets define three colours, a background, a foreground and a title colour:</p>
<p><pre class="brush: plain;">
/definecolor{fore}{RGB}{249,242,215}
/definecolor{back}{RGB}{51,51,51}
/definecolor{title}{RGB}{255,0,90}
</pre></p>
<p>These colours are awesome but obviously you can choose your own if you&#8217;re a philistine and disagree. I&#8217;ve chosen the names (like fore), but they can be whatever you like. You can use other colour specifications instead of RGB, though using RGB for a presentation makes sense to me because it&#8217;s probably never going to be read seriously on paper. Now we need to tell beamer to actually use them:</p>
<p><pre class="brush: plain;">
/setbeamercolor{titlelike}{fg=title}
/setbeamercolor{normal text}{fg=fore,bg=back}
</pre></p>
<p>there are millions of these magic words like &#8216;titlelike&#8217; but no-one will tell you what they are.</p>
<p><strong>3: Make the listings pretty!</strong></p>
<p>To include code listing (like Python) we use the listings package because it&#8217;s brilliant. We need:</p>
<p><pre class="brush: plain;">
/usepackage{listings,bera}
/definecolor{keywords}{RGB}{255,0,90}
/definecolor{comments}{RGB}{60,179,113}
/lstset{language=Python,
keywordstyle=color{keywords},
commentstyle=color{comments}emph}
</pre></p>
<p>The packages are for the listsings (clearly) and bera is the font. It&#8217;s secretly <a href="http://www.gnome.org/fonts/">Bitstream Vera</a> but they had to change the name or something because the world is messed up! Anyway bera is a lovely font in my honest opinion and you should use this and not courier which is ugly and very last century.</p>
<p>The colours are for comments and keywords which you&#8217;ll see in a sec, be patient.</p>
<p>The funny lstset command tells the listings package some things. The first is that we&#8217;re using Python. There are other languages, I think, but why we wouldn&#8217;t be using Python is beyond me. Then we ask listings to make our keywords the colour we defined above (pink!) and our comments to be the comment colour and also <em>emphasised</em>!</p>
<p>Finally, we must make a sample page to demonstrate the lstlisting environment, and because there&#8217;s one more important thing that is NOT OBVIOUS! Here&#8217;s a sample page:</p>
<p><pre class="brush: plain;">
/begin{frame}[fragile]
/frametitle{A Page}
/begin{lstlisting}
def list_of_vectors(n,T):
 return [matlib.zeros((n,1)) for t in T]
/end{lstlisting}
 Here is an equation:
 /begin{equation}
 x_t = Ax_{t-1} + w_t
 /end{equation}
/end{frame}
</pre></p>
<p>The thing to note is the [fragile] command. Here&#8217;s what it does. It means that the weird error that happens if you don&#8217;t include it DOESN&#8217;T HAPPEN! Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mikedewar.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mikedewar.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mikedewar.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mikedewar.wordpress.com&amp;blog=6288094&amp;post=141&amp;subd=mikedewar&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mikedewar.wordpress.com/2009/02/25/latex-beamer-python-beauty/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1ac66812ee2762376c93fa5d6aca9ec2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mikedewar</media:title>
		</media:content>

		<media:content url="http://mikedewar.files.wordpress.com/2009/02/beamer_screen.png" medium="image">
			<media:title type="html">beamer_screen</media:title>
		</media:content>
	</item>
	</channel>
</rss>
