<?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>Drunks&#38;Lampposts</title>
	<atom:link href="http://drunks-and-lampposts.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://drunks-and-lampposts.com</link>
	<description></description>
	<lastBuildDate>Fri, 10 May 2013 13:17:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='drunks-and-lampposts.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Drunks&#38;Lampposts</title>
		<link>http://drunks-and-lampposts.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://drunks-and-lampposts.com/osd.xml" title="Drunks&#38;Lampposts" />
	<atom:link rel='hub' href='http://drunks-and-lampposts.com/?pushpress=hub'/>
		<item>
		<title>Expected switching for the Dirichlet distribution</title>
		<link>http://drunks-and-lampposts.com/2013/02/26/expected-switching-for-the-dirichlet-distribution/</link>
		<comments>http://drunks-and-lampposts.com/2013/02/26/expected-switching-for-the-dirichlet-distribution/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 09:01:42 +0000</pubDate>
		<dc:creator>simonraper</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Choice Modelling]]></category>
		<category><![CDATA[Dirichlet Distribution]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=812</guid>
		<description><![CDATA[A valuable tool in choice modelling is the Dirichlet-multinomial distribution. It&#8217;s a compound of the multinomial and Dirichlet distributions and it works like this: A choice between N options is modelled as a multinomial distribution with parameters &#952;1, &#952;2, &#952;3 &#8230; &#952;N, where the thetas also represent the probabilities of each option being chosen. For &#8230; <a href="http://drunks-and-lampposts.com/2013/02/26/expected-switching-for-the-dirichlet-distribution/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=812&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A valuable tool in choice modelling is the Dirichlet-multinomial distribution. It&#8217;s a compound of the <a href="http://en.wikipedia.org/wiki/Multinomial_distribution">multinomial</a> and <a href="http://en.wikipedia.org/wiki/Dirichlet_distribution">Dirichlet</a> distributions and it works like this:</p>
<ul>
<li>A choice between N options is modelled as a multinomial distribution with parameters &theta;<sub>1</sub>, &theta;<sub>2</sub>, &theta;<sub>3</sub> &#8230; &theta;<sub>N</sub>, where the thetas also represent the probabilities of each option being chosen. For example we might model votes cast in an election as draws from a multinomial distribution with parameters &theta;<sub>1</sub>=0.7, &theta;<sub>2</sub>=0.2, &theta;<sub>3</sub>=0.1.
         </li>
<li>However the multinomial distribution by itself is likely to be a poor model of the choices made within a population as it assumes all individuals select options with the same probabilities. It would be more realistic to say that the thetas themselves vary over the population. This gives us what is known as an over-dispersed distribution: the parameters for one distribution are modelled by another distribution. In this case we use a Dirichlet distribution, which is the multivariate version of a Beta distribution, to model the distribution of the thetas.  </li>
</ul>
<p>As we&#8217;ll be using it a lot here&#8217;s the probability density function for the Dirichlet distribution.</p>
<p><img src='http://s0.wp.com/latex.php?latex=f%28%5Ctheta_1%2C%5Cdots%2C+%5Ctheta_N%3B+%5Calpha_1%2C%5Cdots%2C+%5Calpha_N%29+%3D+%5Cfrac%7B1%7D%7B%5Cmathrm%7BB%7D%28%5Calpha%29%7D+%5Cprod_%7Bi%3D1%7D%5EN+%5Ctheta_i%5E%7B%5Calpha_i+-+1%7D+&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f(&#92;theta_1,&#92;dots, &#92;theta_N; &#92;alpha_1,&#92;dots, &#92;alpha_N) = &#92;frac{1}{&#92;mathrm{B}(&#92;alpha)} &#92;prod_{i=1}^N &#92;theta_i^{&#92;alpha_i - 1} ' title='f(&#92;theta_1,&#92;dots, &#92;theta_N; &#92;alpha_1,&#92;dots, &#92;alpha_N) = &#92;frac{1}{&#92;mathrm{B}(&#92;alpha)} &#92;prod_{i=1}^N &#92;theta_i^{&#92;alpha_i - 1} ' class='latex' /></p>
<p>Where the normalising constant is:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cmathrm%7BB%7D%28%5Calpha%29+%3D+%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%7D%7B%5CGamma%5Cbigl%28%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%5Cbigr%29%7D%2C%5Cqquad%5Calpha%3D%28%5Calpha_1%2C%5Cdots%2C%5Calpha_N%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;mathrm{B}(&#92;alpha) = &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)}{&#92;Gamma&#92;bigl(&#92;sum_{i=1}^N &#92;alpha_i&#92;bigr)},&#92;qquad&#92;alpha=(&#92;alpha_1,&#92;dots,&#92;alpha_N)' title='&#92;mathrm{B}(&#92;alpha) = &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)}{&#92;Gamma&#92;bigl(&#92;sum_{i=1}^N &#92;alpha_i&#92;bigr)},&#92;qquad&#92;alpha=(&#92;alpha_1,&#92;dots,&#92;alpha_N)' class='latex' /></p>
<p>One of the powerful things about the Dirichlet distribution as a modelling tool is that it allows us to capture not only the proportions of the population that opt for each choice but also the amount of switching between the choices from one draw to the next. To take our election example again, an election result of 70%, 20%, 10% for three parties could be modelled by Dirichlet distribution with alphas of 0.1, 0.029 and 0.014 or with alphas of 20, 5.71 and 2.86. In fact there are infinitely many possible settings of the alpha parameters that will produce this result. The difference between them is stability. If two successive elections produce the same result then this could be because the same people are voting for the same parties or, less likely but equally possible, people are switching their votes but in such a way that the net result is the same. Different settings of the alpha parameters produce different levels of switching. </p>
<p>A natural question is then: given a particular parametrisation of the Dirchlet distribution, what is the expected percentage of individuals that will switch category from one draw of the multinomial distribution to another?</p>
<p>I&#8217;m sure this has been worked out before somewhere but after a quick and fruitless trawl through the online literature I decided to do it myself, helped a lot by a great <a href="http://dnquark.com/blog/author/admin/">post</a> from <strong>Leo Alekseyev</strong> who demonstrates a clever way of integrating over Dirichlet distributions. All I&#8217;ve done is adapt his technique.</p>
<p>(By the way to convert the latex in this post into a form easily used in wordpress I used an excellent python package from <a href="http://lucatrevisan.wordpress.com/latex-to-wordpress/">Luca Trevisan</a>)</p>
<p>So let&#8217;s say we have <em>N</em> choices. For individual <em>i</em> the probability of picking choice <em>j</em> is &theta;<sub>ij</sub>. What then is the probability that a randomly selected individual will make the same choice in two successive draws from a multinomial distribution? The individual could either select the first option twice or the second option twice or the third option twice etc. In other words the probability we are interested in is </p>
<p><img src='http://s0.wp.com/latex.php?latex=L%3D%5Ctheta_%7Bi1%7D%5E2+%2B+%5Ctheta_%7Bi2%7D%5E2+%2B%5Ctheta_%7Bi3%7D%5E2+...%5Ctheta_%7BiN%7D%5E2+&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='L=&#92;theta_{i1}^2 + &#92;theta_{i2}^2 +&#92;theta_{i3}^2 ...&#92;theta_{iN}^2 ' title='L=&#92;theta_{i1}^2 + &#92;theta_{i2}^2 +&#92;theta_{i3}^2 ...&#92;theta_{iN}^2 ' class='latex' /></p>
<p>We will call L the loyalty and work out expected switching as 1-E[L].</p>
<p>Leo Alekseyev has created an excellent <a href="http://www.youtube.com/watch?feature=player_embedded&amp;v=cv7ESInBhbs">video</a> on you tube talking through his technique. I would recommend watching it if you would like to follow the arguments below. If you&#8217;re just interested in the end result then scroll to the end of the post.</p>
<p>The quantity we are interested in is <img src='http://s0.wp.com/latex.php?latex=%7BL%3D%5Ctheta_1%5E2%2B%5Ctheta_2%5E2%2B+%5Ccdots+%5Ctheta_N%5E2%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{L=&#92;theta_1^2+&#92;theta_2^2+ &#92;cdots &#92;theta_N^2}' title='{L=&#92;theta_1^2+&#92;theta_2^2+ &#92;cdots &#92;theta_N^2}' class='latex' /> where the <img src='http://s0.wp.com/latex.php?latex=%7B%5Ctheta_i%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{&#92;theta_i}' title='{&#92;theta_i}' class='latex' /> come from a Dirichlet distribution with parameters <img src='http://s0.wp.com/latex.php?latex=%7B+%5Calpha_1%2C+%5C+%5Calpha_2%2C+%5C+%5Calpha_3%2C+%5Cldots+%5Calpha_N+%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{ &#92;alpha_1, &#92; &#92;alpha_2, &#92; &#92;alpha_3, &#92;ldots &#92;alpha_N }' title='{ &#92;alpha_1, &#92; &#92;alpha_2, &#92; &#92;alpha_3, &#92;ldots &#92;alpha_N }' class='latex' /> To get the expected value of L we can use a generalised version of the <a href="http://en.wikipedia.org/wiki/Law_of_the_unconscious_statistician">Law of the Unconscious Statistician</a> to adapt the proof given by Leo Alekseyev. As a reminder, the Law of the Unconscious Statistician is:</p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++E%5Bg%28X%29%5D+%3D+%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+g%28x%29+f%28x%29+%5C+dx+%5C+%5C+%5C+%5C+%5C+%281%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  E[g(X)] = &#92;int_{-&#92;infty}^&#92;infty g(x) f(x) &#92; dx &#92; &#92; &#92; &#92; &#92; (1)' title='&#92;displaystyle  E[g(X)] = &#92;int_{-&#92;infty}^&#92;infty g(x) f(x) &#92; dx &#92; &#92; &#92; &#92; &#92; (1)' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=%7Bf%28x%29%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{f(x)}' title='{f(x)}' class='latex' /> is the probability distribution of the random variable X. </p>
<p>
This will give us the following integral </p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++E%5BL%5D%3D+%5Cfrac%7B1%7D%7BB%28%5Calpha%29%7D%5Cint+%5Ccdots+%5Cint_%5Cmathbf%7BD%7D%5C+%5Csum_%7Bj%3D1%7D%5EN+%5Ctheta_%7Bj%7D%5E2+%5C+%5Cprod_%7Bj%3D1%7D%5EN+%5Ctheta_j%5E%7B%5Calpha_j-1%7D+%5C+d%5Ctheta_1+%5C%21%5Ccdots+d%5Ctheta_N+%5C+%5C+%5C+%5C+%5C+%282%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  E[L]= &#92;frac{1}{B(&#92;alpha)}&#92;int &#92;cdots &#92;int_&#92;mathbf{D}&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{j=1}^N &#92;theta_j^{&#92;alpha_j-1} &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N &#92; &#92; &#92; &#92; &#92; (2)' title='&#92;displaystyle  E[L]= &#92;frac{1}{B(&#92;alpha)}&#92;int &#92;cdots &#92;int_&#92;mathbf{D}&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{j=1}^N &#92;theta_j^{&#92;alpha_j-1} &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N &#92; &#92; &#92; &#92; &#92; (2)' class='latex' /></p>
<p></p>
<p>
So how do we evaluate this integral? It&#8217;s domain D is not straightforward as it is constrained by <img src='http://s0.wp.com/latex.php?latex=%7B+%5Cleft%5Cvert+%5Cbf%7B%5Ctheta%7D+%5Cright%5Cvert+%3D+1+%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{ &#92;left&#92;vert &#92;bf{&#92;theta} &#92;right&#92;vert = 1 }' title='{ &#92;left&#92;vert &#92;bf{&#92;theta} &#92;right&#92;vert = 1 }' class='latex' /> (i.e. the probabilities must sum to zero).</p>
<p>
Leo Alekseyev shows us a trick using the Dirac delta function: </p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cdelta%28x%29%3D%5Cfrac%7B1%7D%7B2%5Cpi%7D+%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+e%5E%7Bikx%7D+dk+%5C+%5C+%5C+%5C+%5C+%283%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;delta(x)=&#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{ikx} dk &#92; &#92; &#92; &#92; &#92; (3)' title='&#92;displaystyle  &#92;delta(x)=&#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{ikx} dk &#92; &#92; &#92; &#92; &#92; (3)' class='latex' /></p>
<p>
 This (generalised) function, the limit of increasingly concentrated distributions, has an area of one beneath the curve (if you can call it that) at x=0 and an area of zero everywhere else &#8211; a slightly odd concept sometimes thought of as infinitely tall spike above the origin. The helpful thing for us is if we set <img src='http://s0.wp.com/latex.php?latex=%7Bx%3D1-%5Ctheta_1-%5Ctheta_1-+%5Ccdots+%5Ctheta_N%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{x=1-&#92;theta_1-&#92;theta_1- &#92;cdots &#92;theta_N}' title='{x=1-&#92;theta_1-&#92;theta_1- &#92;cdots &#92;theta_N}' class='latex' /> and multiply the contents of the integral by the delta function then this is equivalent to evaluating the integral over D.</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty%5C+%5Csum_%7Bj%3D1%7D%5EN+%5Ctheta_%7Bj%7D%5E2+%5C+%5Cprod_%7Bi%3Dj%7D%5EN+%5Ctheta_j%5E%7B%5Calpha_j-1%7D+%5Cdelta+%281-%5Ctheta_1-%5Ctheta_2+%5Ccdots+%5Ctheta_N%29+%5C+d%5Ctheta_1+%5C%21%5Ccdots+d%5Ctheta_N+%5C+%5C+%5C+%5C+%5C+%284%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{i=j}^N &#92;theta_j^{&#92;alpha_j-1} &#92;delta (1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N) &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N &#92; &#92; &#92; &#92; &#92; (4)' title='&#92;displaystyle  &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{i=j}^N &#92;theta_j^{&#92;alpha_j-1} &#92;delta (1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N) &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N &#92; &#92; &#92; &#92; &#92; (4)' class='latex' /></p>
<p>
Since&#8230;</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cdelta+%281-%5Ctheta_1-%5Ctheta_2+%5Ccdots+%5Ctheta_N%29+%3D+%5Cfrac%7B1%7D%7B2%5Cpi%7D%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+e%5E%7B-ik%281-%5Ctheta_1-%5Ctheta_2+%5Ccdots+%5Ctheta_N%29%7D+dk+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;delta (1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N) = &#92;frac{1}{2&#92;pi}&#92;int_{-&#92;infty}^&#92;infty e^{-ik(1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N)} dk ' title='&#92;displaystyle &#92;delta (1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N) = &#92;frac{1}{2&#92;pi}&#92;int_{-&#92;infty}^&#92;infty e^{-ik(1-&#92;theta_1-&#92;theta_2 &#92;cdots &#92;theta_N)} dk ' class='latex' /></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%3D+%5Cfrac%7B1%7D%7B2%5Cpi%7D%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+e%5E%7Bik%7D+e%5E%7Bik%5Ctheta_1%7D+e%5E%7Bik%5Ctheta_2%7D+%5Ccdots+e%5E%7Bik%5Ctheta_N%7Ddk++++%5C+%5C+%5C+%5C+%5C+%285%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   = &#92;frac{1}{2&#92;pi}&#92;int_{-&#92;infty}^&#92;infty e^{ik} e^{ik&#92;theta_1} e^{ik&#92;theta_2} &#92;cdots e^{ik&#92;theta_N}dk    &#92; &#92; &#92; &#92; &#92; (5)' title='&#92;displaystyle   = &#92;frac{1}{2&#92;pi}&#92;int_{-&#92;infty}^&#92;infty e^{ik} e^{ik&#92;theta_1} e^{ik&#92;theta_2} &#92;cdots e^{ik&#92;theta_N}dk    &#92; &#92; &#92; &#92; &#92; (5)' class='latex' /></p>
<p>&#8230; the integral can be rewritten as:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cfrac%7B1%7D%7B2%5Cpi%7D+%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+e%5E%7B-ik%7D+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty%5C+%5Csum_%7Bj%3D1%7D%5EN+%5Ctheta_%7Bj%7D%5E2+%5C+%5Cprod_%7Bi%3Dj%7D%5EN+%5Ctheta_j%5E%7B%5Calpha_j-1%7D+e%5E%7Bik%5Ctheta_1%7D+e%5E%7Bik%5Ctheta_2%7D+%5Ccdots+e%5E%7Bik%5Ctheta_N%7D+%5C+d%5Ctheta_1+%5C%21%5Ccdots+d%5Ctheta_N%5C+dk%5C+%5C+%5C+%5C+%5C+%286%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{-ik} &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{i=j}^N &#92;theta_j^{&#92;alpha_j-1} e^{ik&#92;theta_1} e^{ik&#92;theta_2} &#92;cdots e^{ik&#92;theta_N} &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N&#92; dk&#92; &#92; &#92; &#92; &#92; (6)' title='&#92;displaystyle  &#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{-ik} &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty&#92; &#92;sum_{j=1}^N &#92;theta_{j}^2 &#92; &#92;prod_{i=j}^N &#92;theta_j^{&#92;alpha_j-1} e^{ik&#92;theta_1} e^{ik&#92;theta_2} &#92;cdots e^{ik&#92;theta_N} &#92; d&#92;theta_1 &#92;!&#92;cdots d&#92;theta_N&#92; dk&#92; &#92; &#92; &#92; &#92; (6)' class='latex' /></p>
<p></p>
<p>
If we group together like terms we reach:</p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%5Cfrac%7B1%7D%7B2%5Cpi%7D+%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty+e%5E%7B-ik%7D+%5CBig%5B+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   &#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{-ik} &#92;Big[ ' title='&#92;displaystyle   &#92;frac{1}{2&#92;pi} &#92;int_{-&#92;infty}^&#92;infty e^{-ik} &#92;Big[ ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1%2B1%7D+e%5E%7B-ik%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-ik%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-ik%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-ik%5Ctheta_N%7D+d%5Ctheta_N+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1+1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N ' title='&#92;displaystyle   &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1+1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-ik%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2%2B1%7D+e%5E%7B-ik%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-ik%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-ik%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2+1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2+1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-ik%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-ik%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3%2B1%7D+e%5E%7B-ik%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-ik%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3+1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3+1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-ik&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Ccdots+%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-ik%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-ik%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-ik%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N%2B1%7D+e%5E%7B-ik%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;cdots + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N+1} e^{-ik&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle  &#92;cdots + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-ik&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-ik&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-ik&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N+1} e^{-ik&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%5CBig%5D+dk+%5C+%5C+%5C+%5C+%5C+%287%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   &#92;Big] dk &#92; &#92; &#92; &#92; &#92; (7) ' title='&#92;displaystyle   &#92;Big] dk &#92; &#92; &#92; &#92; &#92; (7) ' class='latex' /></p>
<p>
Note the pattern in the exponents!</p>
<p>Continuing along the lines described by Leo Alekseyev we use the substitutions <img src='http://s0.wp.com/latex.php?latex=%7Bik%3D%5Ckappa%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{ik=&#92;kappa}' title='{ik=&#92;kappa}' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%7Bk%3Di%5Ckappa%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{k=i&#92;kappa}' title='{k=i&#92;kappa}' class='latex' /> to set us up for the Laplace transform and evalute the integral at <img src='http://s0.wp.com/latex.php?latex=%7Bt%3D1%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{t=1}' title='{t=1}' class='latex' /> to set us up for the inverse Laplace transform.</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B1%7D%7B2%5Cpi+i%7D+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ ' title='&#92;displaystyle &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1%2B1%7D+e%5E%7B-%5Ckappa%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-%5Ckappa%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-%5Ckappa%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-%5Ckappa%5Ctheta_N%7D+d%5Ctheta_N+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1+1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N ' title='&#92;displaystyle   &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1+1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-%5Ckappa%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2%2B1%7D+e%5E%7B-%5Ckappa%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-%5Ckappa%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-%5Ckappa%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2+1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2+1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+++%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-%5Ckappa%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-%5Ckappa%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3%2B1%7D+e%5E%7B-%5Ckappa%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N-1%7D+e%5E%7B-%5Ckappa%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3+1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle   + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3+1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N-1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Ccdots+%2B+%5Cint_%7B%5Ctheta_1+%3D0%7D%5E%5Cinfty+%5Ctheta_1%5E%7B%5Calpha_1-1%7D+e%5E%7B-%5Ckappa%5Ctheta_1%7D+d%5Ctheta_1+%5Cint_%7B%5Ctheta_2+%3D0%7D%5E%5Cinfty+%5Ctheta_2%5E%7B%5Calpha_2-1%7D+e%5E%7B-%5Ckappa%5Ctheta_2%7D+d%5Ctheta_2+%5Cint_%7B%5Ctheta_3+%3D0%7D%5E%5Cinfty+%5Ctheta_3%5E%7B%5Calpha_3-1%7D+e%5E%7B-%5Ckappa%5Ctheta_3%7D+d%5Ctheta_3+%5Ccdots+%5Cint_%7B%5Ctheta_N+%3D0%7D%5E%5Cinfty+%5Ctheta_N%5E%7B%5Calpha_N%2B1%7D+e%5E%7B-%5Ckappa%5Ctheta_N%7D+d%5Ctheta_N++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;cdots + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N+1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' title='&#92;displaystyle  &#92;cdots + &#92;int_{&#92;theta_1 =0}^&#92;infty &#92;theta_1^{&#92;alpha_1-1} e^{-&#92;kappa&#92;theta_1} d&#92;theta_1 &#92;int_{&#92;theta_2 =0}^&#92;infty &#92;theta_2^{&#92;alpha_2-1} e^{-&#92;kappa&#92;theta_2} d&#92;theta_2 &#92;int_{&#92;theta_3 =0}^&#92;infty &#92;theta_3^{&#92;alpha_3-1} e^{-&#92;kappa&#92;theta_3} d&#92;theta_3 &#92;cdots &#92;int_{&#92;theta_N =0}^&#92;infty &#92;theta_N^{&#92;alpha_N+1} e^{-&#92;kappa&#92;theta_N} d&#92;theta_N  ' class='latex' /></p>
<p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5CBig%5D+%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D+%5C+%5C+%5C+%5C+%5C+%288%29++&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (8)  ' title='&#92;displaystyle &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (8)  ' class='latex' /></p>
<p>
As a reminder the Laplace transform is:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7Bf%28t%29%5Cright%5C%7D%3D%5Cint_0%5E%5Cinfty+f%28t%29e%5E%7B-st%7Dds+%5C+%5C+%5C+%5C+%5C+%289%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{f(t)&#92;right&#92;}=&#92;int_0^&#92;infty f(t)e^{-st}ds &#92; &#92; &#92; &#92; &#92; (9)' title='&#92;displaystyle  &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{f(t)&#92;right&#92;}=&#92;int_0^&#92;infty f(t)e^{-st}ds &#92; &#92; &#92; &#92; &#92; (9)' class='latex' /></p>
<p></p>
<p>
So we can substitute it in giving us:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B1%7D%7B2%5Cpi+i%7D+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_1%5E%7B%5Calpha_1%2B1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_2%5E%7B%5Calpha_2-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_3%5E%7B%5Calpha_3-1%7D%5Cright%5C%7D+%5Ccdots+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_N%5E%7B%5Calpha_N-1%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1+1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' title='&#92;displaystyle &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1+1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' class='latex' /></p>
<p> 
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++++%2B%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_1%5E%7B%5Calpha_1-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_2%5E%7B%5Calpha_2%2B1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_3%5E%7B%5Calpha_3-1%7D%5Cright%5C%7D+%5Ccdots+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_N%5E%7B%5Calpha_N-1%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle    +&#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2+1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' title='&#92;displaystyle    +&#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2+1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' class='latex' /></p>
<p> 
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++++%2B%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_1%5E%7B%5Calpha_1-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_2%5E%7B%5Calpha_2-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_3%5E%7B%5Calpha_3%2B1%7D%5Cright%5C%7D+%5Ccdots+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_N%5E%7B%5Calpha_N-1%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle    +&#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3+1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' title='&#92;displaystyle    +&#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3+1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N-1}&#92;right&#92;} ' class='latex' /></p>
<p> 
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++++%2B+%5Ccdots++%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_1%5E%7B%5Calpha_1-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_2%5E%7B%5Calpha_2-1%7D%5Cright%5C%7D+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_3%5E%7B%5Calpha_3-1%7D%5Cright%5C%7D+%5Ccdots+%5Cdisplaystyle%5Cmathcal%7BL%7D+%5Cleft%5C%7B%5Ctheta_N%5E%7B%5Calpha_N%2B1%7D%5Cright%5C%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle    + &#92;cdots  &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N+1}&#92;right&#92;} ' title='&#92;displaystyle    + &#92;cdots  &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_1^{&#92;alpha_1-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_2^{&#92;alpha_2-1}&#92;right&#92;} &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_3^{&#92;alpha_3-1}&#92;right&#92;} &#92;cdots &#92;displaystyle&#92;mathcal{L} &#92;left&#92;{&#92;theta_N^{&#92;alpha_N+1}&#92;right&#92;} ' class='latex' /></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5CBig%5D+%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D++++%5C+%5C+%5C+%5C+%5C+%2810%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1}    &#92; &#92; &#92; &#92; &#92; (10) ' title='&#92;displaystyle &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1}    &#92; &#92; &#92; &#92; &#92; (10) ' class='latex' /></p>
<p>The Laplace transformation evaluates as:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cint_0%5E%5Cinfty+%5Ctheta%5E%5Calpha+e%5E%7B-s%5Ctheta%7D+d%5Ctheta+%3D%5Cfrac%7B%5CGamma%28%5Calpha%2B1%29%7D%7Bs%5E%7B%5Calpha%2B1%7D%7D+%5C+%5C+%5C+%5C+%5C+%2811%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;int_0^&#92;infty &#92;theta^&#92;alpha e^{-s&#92;theta} d&#92;theta =&#92;frac{&#92;Gamma(&#92;alpha+1)}{s^{&#92;alpha+1}} &#92; &#92; &#92; &#92; &#92; (11)' title='&#92;displaystyle  &#92;int_0^&#92;infty &#92;theta^&#92;alpha e^{-s&#92;theta} d&#92;theta =&#92;frac{&#92;Gamma(&#92;alpha+1)}{s^{&#92;alpha+1}} &#92; &#92; &#92; &#92; &#92; (11)' class='latex' /></p>
<p></p>
<p>
Which we can substitute back into our integral:</p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++++%5Cfrac%7B1%7D%7B2%5Cpi+i%7D+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+%5Cfrac%7B%5CGamma%28%5Calpha_1%2B2%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B2%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_2%29%7D%7B%5Ckappa%5E%7B%5Calpha_2%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_3%29%7D%7B%5Ckappa%5E%7B%5Calpha_3%7D%7D+%5Ccdots+%5Cfrac%7B%5CGamma%28%5Calpha_N%29%7D%7B%5Ckappa%5E%7B%5Calpha_N%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle    &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{&#92;Gamma(&#92;alpha_1+2)}{&#92;kappa^{&#92;alpha_1+2}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' title='&#92;displaystyle    &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{&#92;Gamma(&#92;alpha_1+2)}{&#92;kappa^{&#92;alpha_1+2}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' class='latex' /></p>
<p> 
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%2B%5Cfrac%7B%5CGamma%28%5Calpha_1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_2%2B2%29%7D%7B%5Ckappa%5E%7B%5Calpha_2%2B2%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_3%29%7D%7B%5Ckappa%5E%7B%5Calpha_3%7D%7D+%5Ccdots++%5Cfrac%7B%5CGamma%28%5Calpha_N%29%7D%7B%5Ckappa%5E%7B%5Calpha_N%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2+2)}{&#92;kappa^{&#92;alpha_2+2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' title='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2+2)}{&#92;kappa^{&#92;alpha_2+2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%2B%5Cfrac%7B%5CGamma%28%5Calpha_1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_2%29%7D%7B%5Ckappa%5E%7B%5Calpha_2%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_3%2B2%29%7D%7B%5Ckappa%5E%7B%5Calpha_3%2B2%7D%7D+%5Ccdots++%5Cfrac%7B%5CGamma%28%5Calpha_N%29%7D%7B%5Ckappa%5E%7B%5Calpha_N%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3+2)}{&#92;kappa^{&#92;alpha_3+2}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' title='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3+2)}{&#92;kappa^{&#92;alpha_3+2}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N)}{&#92;kappa^{&#92;alpha_N}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%2B+%5Ccdots+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  + &#92;cdots ' title='&#92;displaystyle  + &#92;cdots ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%2B%5Cfrac%7B%5CGamma%28%5Calpha_1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_2%29%7D%7B%5Ckappa%5E%7B%5Calpha_2%7D%7D+%5Cfrac%7B%5CGamma%28%5Calpha_3%29%7D%7B%5Ckappa%5E%7B%5Calpha_3%7D%7D+%5Ccdots++%5Cfrac%7B%5CGamma%28%5Calpha_N%2B2%29%7D%7B%5Ckappa%5E%7B%5Calpha_N%2B2%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N+2)}{&#92;kappa^{&#92;alpha_N+2}} ' title='&#92;displaystyle  +&#92;frac{&#92;Gamma(&#92;alpha_1)}{&#92;kappa^{&#92;alpha_1}} &#92;frac{&#92;Gamma(&#92;alpha_2)}{&#92;kappa^{&#92;alpha_2}} &#92;frac{&#92;Gamma(&#92;alpha_3)}{&#92;kappa^{&#92;alpha_3}} &#92;cdots  &#92;frac{&#92;Gamma(&#92;alpha_N+2)}{&#92;kappa^{&#92;alpha_N+2}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5CBig%5D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;Big] ' title='&#92;displaystyle &#92;Big] ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D+%5C+%5C+%5C+%5C+%5C+%2812%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (12) ' title='&#92;displaystyle  &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (12) ' class='latex' /></p>
<p></p>
<p>
Since <img src='http://s0.wp.com/latex.php?latex=%7B%5CGamma%28x%2B2%29%3Dx%28x%2B1%29%5CGamma%28x%29%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{&#92;Gamma(x+2)=x(x+1)&#92;Gamma(x)}' title='{&#92;Gamma(x+2)=x(x+1)&#92;Gamma(x)}' class='latex' /> we get: </p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cfrac%7B1%7D%7B2%5Cpi+i%7D+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Calpha_1%28%5Calpha_1%2B1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2%2B+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_1(&#92;alpha_1+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' title='&#92;displaystyle  &#92;frac{1}{2&#92;pi i} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_1(&#92;alpha_1+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' class='latex' /></p>
<p> </p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%2B%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Calpha_2%28%5Calpha_2%2B1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2%2B+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle +&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_2(&#92;alpha_2+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' title='&#92;displaystyle +&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_2(&#92;alpha_2+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%2B%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Calpha_3%28%5Calpha_3%2B1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2%2B+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle +&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_3(&#92;alpha_3+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' title='&#92;displaystyle +&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_3(&#92;alpha_3+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%2B+%5Ccdots+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle + &#92;cdots ' title='&#92;displaystyle + &#92;cdots ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Calpha_N%28%5Calpha_N%2B1%29%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2%2B+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_N(&#92;alpha_N+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' title='&#92;displaystyle &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;alpha_N(&#92;alpha_N+1)}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2+ &#92;cdots &#92;alpha_N + 2}} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5CBig%5D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;Big] ' title='&#92;displaystyle &#92;Big] ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D+++%5C+%5C+%5C+%5C+%5C+%2813%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;left.d&#92;kappa&#92;right|_{t=1}   &#92; &#92; &#92; &#92; &#92; (13) ' title='&#92;displaystyle &#92;left.d&#92;kappa&#92;right|_{t=1}   &#92; &#92; &#92; &#92; &#92; (13) ' class='latex' /></p>
<p>Some rearranging gives us:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%7D%7B2%5Cpi+i%7D+%5Csum_%7Bi%3D1%7D%5EN%28%5Calpha_i%28%5Calpha_i%2B1%29%29+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+%5Cfrac%7B1%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+%5CBig%5D+%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D+%5C+%5C+%5C+%5C+%5C+%2814%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)}{2&#92;pi i} &#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1)) &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{1}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2 &#92;cdots &#92;alpha_N + 2}} &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (14)' title='&#92;displaystyle  &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)}{2&#92;pi i} &#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1)) &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{1}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2 &#92;cdots &#92;alpha_N + 2}} &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1} &#92; &#92; &#92; &#92; &#92; (14)' class='latex' /></p>
<p>
Now we use the inverse Laplace transform to evaluate <img src='http://s0.wp.com/latex.php?latex=%7B%5Cfrac%7B1%7D%7B2%5Cpi%7D+%5Cint_%7B-+i+%5Cinfty%7D%5E%7Bi+%5Cinfty%7D+e%5E%7B%5Ckappa+t%7D+%5CBig%5B+%5Cfrac%7B1%7D%7B%5Ckappa%5E%7B%5Calpha_1%2B%5Calpha_2+%5Ccdots+%5Calpha_N+%2B+2%7D%7D+%5CBig%5D+%5Cleft.d%5Ckappa%5Cright%7C_%7Bt%3D1%7D%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{&#92;frac{1}{2&#92;pi} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{1}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2 &#92;cdots &#92;alpha_N + 2}} &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1}}' title='{&#92;frac{1}{2&#92;pi} &#92;int_{- i &#92;infty}^{i &#92;infty} e^{&#92;kappa t} &#92;Big[ &#92;frac{1}{&#92;kappa^{&#92;alpha_1+&#92;alpha_2 &#92;cdots &#92;alpha_N + 2}} &#92;Big] &#92;left.d&#92;kappa&#92;right|_{t=1}}' class='latex' /> as <img src='http://s0.wp.com/latex.php?latex=%7B%5Cfrac%7B1%7D%7B%5CGamma%282%2B%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%29%7D%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{&#92;frac{1}{&#92;Gamma(2+&#92;sum_{i=1}^N &#92;alpha_i)}}' title='{&#92;frac{1}{&#92;Gamma(2+&#92;sum_{i=1}^N &#92;alpha_i)}}' class='latex' /> giving us:</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Csum_%7Bi%3D1%7D%5EN%28%5Calpha_i%28%5Calpha_i%2B1%29%29%7D%7B%5CGamma%282%2B%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%29%7D+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1))}{&#92;Gamma(2+&#92;sum_{i=1}^N &#92;alpha_i)} ' title='&#92;displaystyle &#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1))}{&#92;Gamma(2+&#92;sum_{i=1}^N &#92;alpha_i)} ' class='latex' /></p>
<p></p>
<p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%3D%5Cfrac%7B%5Cprod_%7Bi%3D1%7D%5EN+%5CGamma%28%5Calpha_i%29%5Csum_%7Bi%3D1%7D%5EN%28%5Calpha_i%28%5Calpha_i%2B1%29%29%7D%7B%5CGamma%28%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%29%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i+%28%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%2B1%29%7D+%5C+%5C+%5C+%5C+%5C+%2815%29+&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle =&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1))}{&#92;Gamma(&#92;sum_{i=1}^N &#92;alpha_i)&#92;sum_{i=1}^N &#92;alpha_i (&#92;sum_{i=1}^N &#92;alpha_i+1)} &#92; &#92; &#92; &#92; &#92; (15) ' title='&#92;displaystyle =&#92;frac{&#92;prod_{i=1}^N &#92;Gamma(&#92;alpha_i)&#92;sum_{i=1}^N(&#92;alpha_i(&#92;alpha_i+1))}{&#92;Gamma(&#92;sum_{i=1}^N &#92;alpha_i)&#92;sum_{i=1}^N &#92;alpha_i (&#92;sum_{i=1}^N &#92;alpha_i+1)} &#92; &#92; &#92; &#92; &#92; (15) ' class='latex' /></p>
<p>
Bringing the normalisation constant back in and cancelling out we get</p>
<p><p align="center"><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle++%5Cfrac%7B%5Csum_%7Bi%3D1%7D%5EN%5Calpha_i%28%5Calpha_i%2B1%29%7D%7B%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i+%281%2B%5Csum_%7Bi%3D1%7D%5EN+%5Calpha_i%29%7D+%5C+%5C+%5C+%5C+%5C+%2816%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='&#92;displaystyle  &#92;frac{&#92;sum_{i=1}^N&#92;alpha_i(&#92;alpha_i+1)}{&#92;sum_{i=1}^N &#92;alpha_i (1+&#92;sum_{i=1}^N &#92;alpha_i)} &#92; &#92; &#92; &#92; &#92; (16)' title='&#92;displaystyle  &#92;frac{&#92;sum_{i=1}^N&#92;alpha_i(&#92;alpha_i+1)}{&#92;sum_{i=1}^N &#92;alpha_i (1+&#92;sum_{i=1}^N &#92;alpha_i)} &#92; &#92; &#92; &#92; &#92; (16)' class='latex' /></p>
<p></p>
<p>
which is our expected loyalty <img src='http://s0.wp.com/latex.php?latex=%7BE%5BL%5D%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='{E[L]}' title='{E[L]}' class='latex' />.</p>
<p>All we need to do now is check it&#8217;s right by comparing with a simulated result in R</p>
<pre class="brush: r; title: ; notranslate">

comp&lt;-NULL

for (i in 1:100){

alphas&lt;-runif(3, 0.01, 10)

#Simulate
sample.d1&lt;-rdirichlet(10000, alphas)
purchases&lt;-t(mapply(function(x, y, z) rmultinom(1, size = 2, prob=c(x,y,z)), sample.d1[,1], sample.d1[,2], sample.d1[,3]))
loyal&lt;-sum(purchases[,1]==2)+sum(purchases[,2]==2)+sum(purchases[,3]==2)
switching.sim&lt;-(10000-loyal)/10000

#Derived

switching.dir&lt;-1-(sum(alphas*(alphas+1))/(sum(alphas)*(1+sum(alphas))))

comp&lt;-rbind(comp, c(switching.sim, switching.dir))

}

colnames(comp)&lt;-c(&quot;Simulated&quot;, &quot;Derived&quot;)
plot(comp)
x&lt;-seq(0,1,0.1)
lines(x,x)
</pre>
<p>A plot of the simulated as against the derived results shows that, as we would hope, they are approximately equal (the line is x=y)</p>
<p><a href="http://drunksandlampposts.files.wordpress.com/2013/02/simdir-e1361817855234.png"><img src="http://drunksandlampposts.files.wordpress.com/2013/02/simdir-e1361817855234.png?w=750" alt="SimDir"   class="alignleft size-full wp-image-873" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/812/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/812/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=812&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2013/02/26/expected-switching-for-the-dirichlet-distribution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd329a395c507fe4c19e172a71ede3b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonraper</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2013/02/simdir-e1361817855234.png" medium="image">
			<media:title type="html">SimDir</media:title>
		</media:content>
	</item>
		<item>
		<title>Thorstein Veblen and Hard Coding</title>
		<link>http://drunks-and-lampposts.com/2013/02/08/thorstein-veblen-and-hard-coding/</link>
		<comments>http://drunks-and-lampposts.com/2013/02/08/thorstein-veblen-and-hard-coding/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 22:04:36 +0000</pubDate>
		<dc:creator>simonraper</dc:creator>
				<category><![CDATA[Topical]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Thorstein Veblen]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=725</guid>
		<description><![CDATA[It is still quite common to hear the career progression of an analyst described as one upwards from the hard graft of coding and &#8220;getting your hands dirty&#8221; towards the enviable heights of people management and strategic thinking. Whenever I hear this it reminds me of the book Conspicuous Consumption by the American economist Thorstein &#8230; <a href="http://drunks-and-lampposts.com/2013/02/08/thorstein-veblen-and-hard-coding/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=725&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It is still quite common to hear the career progression of an analyst described as one upwards from the hard graft of coding and &#8220;getting your hands dirty&#8221; towards the enviable heights of people management and strategic thinking. Whenever I hear this it reminds me of the book <em>Conspicuous Consumption</em> by the American economist <a href="http://en.wikipedia.org/wiki/Thorstein_Veblen">Thorstein Veblen</a>. It examines, in a very hypothetical way, the roots of economic behaviour in some of our basic social needs: to impress others, to dominate and to demonstrate status. It&#8217;s not a happy book.</p>
<p><a href="http://drunksandlampposts.files.wordpress.com/2013/02/veblen3a.jpg"><img class="alignleft size-full wp-image-803" alt="Veblen3a" src="http://drunksandlampposts.files.wordpress.com/2013/02/veblen3a.jpg?w=750"   /></a></p>
<p>His principal concept is the distinction between <em>exploit</em> and <em>drudgery</em>.</p>
<blockquote><p>The institution of a leisure class is the outgrowth of an early discrimination between employments, according to which some employments are worthy and others unworthy. Under this ancient distinction the worthy employments are those which may be classed as exploit; unworthy are those necessary employments into which no appreciable element of exploit enters.</p></blockquote>
<p>He sees this division arising early in history as honour and status are assigned to those are successful in making others do what they want and <em>&#8220;at the same time, employment in industry becomes correspondingly odious, and, in the common-sense apprehension, the handling of the tools and implements of industry falls beneath the dignity of able-bodied men. Labour becomes irksome.&#8221;</em></p>
<p>We&#8217;re no longer hairy barbarians using the vanquished for foot-stools but, as Veblen points out, the distinction persists no matter how illogical and unprofitable. Coding is still somehow viewed as necessarily inferior to the boardroom meeting even if it is the genius piece of code that makes or breaks a business.</p>
<p>Attitudes are changing, but still so slowly that there is a desperate shortage of people with both the experience and the hands-on skills to get things done.</p>
<p>So if you are a good analyst, and you love what you do, then this is my advice to you: when they come to lure you from your lovely pristine scripts, resist. Stay where you are. The 21st century is going to need you!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/725/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/725/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=725&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2013/02/08/thorstein-veblen-and-hard-coding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd329a395c507fe4c19e172a71ede3b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonraper</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2013/02/veblen3a.jpg" medium="image">
			<media:title type="html">Veblen3a</media:title>
		</media:content>
	</item>
		<item>
		<title>Two Quick Recipes: Ubuntu and Hadoop</title>
		<link>http://drunks-and-lampposts.com/2013/02/05/two-quick-recipes/</link>
		<comments>http://drunks-and-lampposts.com/2013/02/05/two-quick-recipes/#comments</comments>
		<pubDate>Tue, 05 Feb 2013 09:11:49 +0000</pubDate>
		<dc:creator>simonraper</dc:creator>
				<category><![CDATA[EC2]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Hadoop]]></category>
		<category><![CDATA[NX Server]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=786</guid>
		<description><![CDATA[There are so many flavours of everything and things are changing so quickly that I find every task researched online ends up being a set of instructions stitched together from several blogs and forums. Here&#8217;s a couple of recent ones. Ubuntu on AWS (50 mins) Was going to buy a new laptop but it made &#8230; <a href="http://drunks-and-lampposts.com/2013/02/05/two-quick-recipes/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=786&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>There are so many flavours of everything and things are changing so quickly that I find every task researched online ends up being a set of instructions stitched together from several blogs and forums. Here&#8217;s a couple of recent ones.</p>
<h3>Ubuntu on AWS (50 mins)</h3>
<p>Was going to buy a new laptop but it made more sense to set up a linux instance on AWS and remote in (a quarter of the price and more interesting). Here&#8217;s my recipe</p>
<ol>
<ol>
<li>As in Mark&#8217;s earlier post set yourself up with an AWS account and a key pair by following this <a href="http://s3.amazonaws.com/AmazonEC2Tutorial/AmazonEC2Tutorial.html">tutorial</a></li>
<li>Launch an Ubuntu instance using the EC2 management console and select memory and processing power to suit.</li>
<li>Start up the instance then connect to it by using Mindterm (very useful alternative to SSHing in with putty). To do this just select the instance in the terminal. Select Actions and then Connect. (You&#8217;ll need to provide the path to your saved key)</li>
<li>Now you probably want to remote into your machine. Do this by setting up NoMachineNX following steps 2 to 4 in the following <a href="http://aws-musings.com/4-easy-steps-to-enable-remote-desktop-on-your-ubuntu-ec2-instance/">post</a></li>
<p> However when you execute the last line of step 2 you&#8217;ll find that nxsetup is not found. To fix this switch to this <a href="https://help.ubuntu.com/community/FreeNX">post</a> and follow steps 6-7 (life&#8217;s so complicated)</p>
<li>Change password authentication to yes in  /etc/ssh/sshd_config</li>
<li>Add gnome fall back</li>
</ol>
</ol>
<p><code>sudo apt-get install gnome-session-fallback</code></p>
<ol>
<li>Restart the instance and log in</li>
</ol>
<p>Just remember to keep an eye on the charges!</p>
<h3>Single Cluster Hadoop on Ubuntu (20 mins)</h3>
<p>Of course you can run Hadoop directly on Amazon&#8217;s EMR platform but if you want to get more of a feel for how it works in a familiar environment you can set it up on a single instance.</p>
<ol>
<li>Follow the instructions in this <a href="http://www.higherpass.com/linux/Tutorials/Installing-And-Using-Hadoop/">post</a> substituting in the latest hadoop stable release</li>
<li>Install the latest JDK <code>sudo apt-get install openjdk-7-jdk</code></li>
<li>Set the JAVA_HOME path variable <code>export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64</code> Substituting in the path to the JDK binaries</li>
<li>From the <a href="http://hadoop.apache.org/docs/stable/single_node_setup.html">Hadoop quick start guide</a> follow the instructions in the &#8220;Prepare to start the Hadoop Cluster&#8221; and &#8220;Stand Alone Operations&#8221; sections. If this all works you should be ready to go.</li>
</ol>
<p><span style="font-size:medium;"><span style="line-height:24px;"> </span></span></p>
<p><img height="1" width="1" alt="" style="display:none;" src="https://www.facebook.com/offsite_event.php?id=6005457088093" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/786/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=786&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2013/02/05/two-quick-recipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd329a395c507fe4c19e172a71ede3b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonraper</media:title>
		</media:content>

		<media:content url="https://www.facebook.com/offsite_event.php?id=6005457088093" medium="image" />
	</item>
		<item>
		<title>Lazy D3 on some astronomical data</title>
		<link>http://drunks-and-lampposts.com/2013/01/03/lazy-d3-on-some-astronomical-data/</link>
		<comments>http://drunks-and-lampposts.com/2013/01/03/lazy-d3-on-some-astronomical-data/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 21:37:58 +0000</pubDate>
		<dc:creator>simonraper</dc:creator>
				<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Scraping and APIs]]></category>
		<category><![CDATA[astronomy]]></category>
		<category><![CDATA[d3]]></category>
		<category><![CDATA[dendrogram]]></category>
		<category><![CDATA[ontology]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=727</guid>
		<description><![CDATA[I can&#8217;t claim to be anything near an expert on D3 (a JavaScript library for data visualisation) but being both greedy and lazy I wondered if I could get some nice results with minimum effort. In any case the hardest thing about D3 for a novice to the world of web design seems to be &#8230; <a href="http://drunks-and-lampposts.com/2013/01/03/lazy-d3-on-some-astronomical-data/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=727&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I can&#8217;t claim to be anything near an expert on <a href="http://d3js.org/"> D3 </a> (a JavaScript library for data visualisation) but being both greedy and lazy I wondered if I could get some nice results with minimum effort. In any case the hardest thing about D3 for a novice to the world of web design seems to be getting started at all so perhaps this post will be useful for getting people up and running.</p>
<div id="attachment_735" class="wp-caption alignleft" style="width: 760px"><a href="http://107.21.228.241/Rheingold.html"><img class="size-large wp-image-735" alt="A Reingold–Tilford Tree of the IVOA Astronomical Object Ontology using D3" src="http://drunksandlampposts.files.wordpress.com/2013/01/astrorg-e1357224529759.png?w=750&#038;h=658" width="750" height="658" /></a><p class="wp-caption-text">A Reingold–Tilford Tree of the IVOA Astronomical Object Ontology using D3</p></div>
<p>The images above and below are visualisations using D3 of a classification hierarchy for astronomical objects provided by the <a href="http://www.ivoa.net/Documents/Notes/AstrObjectOntology/"> IVOA </a> (International Virtual Observatory Alliance). I take no credit for the layout. The designs are taken straight from the D3 examples gallery but I will show you how I got the environment set up and my data into the graphs. The process should be replicable for any hierarchical dataset stored in a similar fashion.</p>
<div id="attachment_730" class="wp-caption alignright" style="width: 358px"><a href="http://107.21.228.241/dend.html"><img class="size-large wp-image-730" alt="A dendrogram of the same data" src="http://drunksandlampposts.files.wordpress.com/2013/01/astrodend-e1357224862740.png?w=348&#038;h=750" width="348" height="750" /></a><p class="wp-caption-text">A dendrogram of the same data</p></div>
<p>Even better than the static images are various interactive versions such as the <a href="http://107.21.228.241/rotate.html"> rotating Reingold–Tilford Tree, </a> the <a href="http://107.21.228.241/collapse.html"> collapsible dendrogram </a> and <a href="http://107.21.228.241/indented.html"> collapsible indented tree </a>. These were all created fairly easily by substituting the astronomical object data for the data in the original examples. (I say fairly easily as you need to get the hierarchy into the right format but more on that later.)</p>
<p>First the environment.</p>
<p>If you are an R user with little experience of building web pages then you&#8217;ll probably find yourself squinting at the D3 documentation wondering how you get from the code to the output. With just a browser to read the JavaScript and an editor (notepad if you like but preferably a specialist HTML editor) you can get through the most of the tutorials referred to in Mark&#8217;s <a href="http://drunks-and-lampposts.com/2012/05/31/d3-another-acronym-to-learn/"> previous post </a>. Doing this locally on your own pc works ok because the data visualised in the tutorials is mostly hard coded into the JavaScript. However once you want to start referring to data contained in external files some sensible security restrictions on what files your browser can access will block your attempts. The options are to turn these off (not advised) or switch to working on a webserver.</p>
<p>You can either opt for one of the many free hosting services or if you are feeling more adventurous you can follow Mark&#8217;s <a href="http://drunks-and-lampposts.com/2012/01/08/ec2-tutorials-getting-started-on-amazon-web-services/"> posts </a> on setting up a Linux instance on Amazon Web Services and then follow <a href="http://libbyh.com/2011/06/23/setting-up-apache-and-php-on-amazon-ec2/"> Libby Hemphill&#8217;s instructions </a> for starting up Apache and opening the port. Finally, going with the latter, I use <a href="http://filezilla-project.org/"> FileZilla </a> to transfer over any data I need to my Linux instance. See <a href="http://mdahlman.wordpress.com/2012/03/21/filezilla-and-ec2-using-private-keys/"> this post </a> for getting it to work with your authentication key.</p>
<p>This should leave you in the following situation:</p>
<ul>
<li> You have a working web server and an IP address that will take you to an HTML index page from which you can provide links to your D3 documents. </li>
<li> You have a way of transferring work that you do locally over to your web server.  </li>
<li> You have a whole gallery of <a href="https://github.com/mbostock/d3/wiki/Gallery"> examples </a> to play around with </li>
</ul>
<p>Rather than creating my own D3 scripts I&#8217;m just going too substitute my own data into the examples. The issue here is that the hierarchical examples take as an input a nested JSON object. This means something like:</p>
<pre class="brush: xml; title: ; notranslate">
{
 &quot;name&quot;: &quot;Astronomical Object&quot;,
 &quot;children&quot;: [
  {
   &quot;name&quot;: &quot;Planet&quot;,
   &quot;children&quot;: [
    {
     &quot;name&quot;: &quot;Type&quot;,
     &quot;children&quot;: [
      {&quot;name&quot;: &quot;Terrestrial&quot;},
      {&quot;name&quot;: &quot;Gas Giant&quot;}
     ]
    }

</pre>
<p>The issue is that our data looks like this:</p>
<pre class="brush: plain; title: ; notranslate">
1. Planet
1.1. [Type]
1.1.1. Terrestrial
1.1.2. Gas Giant
1.2.  [Feature]
1.2.1. Surface
1.2.1.1. Mountain
1.2.1.2. Canyon
1.2.1.3. Volcanic
1.2.1.4. Impact
1.2.1.5. Erosion
1.2.1.6. Liquid
1.2.1.7. Ice
1.2.2. Atmosphere
1.2.2.1. Cloud
1.2.2.2. Storm
1.2.2.3. Belt
1.2.2.4. Aurora
</pre>
<p>To put this into the right format I&#8217;ve used Python to read in the file as csv (with dot as a delimiter) and construct the nested JSON object. Here&#8217;s the full python code:</p>
<pre class="brush: python; title: ; notranslate">

import csv, re

#Open the file and read as dot delimited

def readLev(row):
    level=0
    pattern = re.compile(&quot;[a-zA-Z]&quot;)
    for col in row:
        if pattern.search(col) !=None:
            level=row.index(col)
    return level
    

with open('B:\PythonFiles\PythonInOut\AstroObject\Astro.csv', 'rb') as csvfile:
    astroReader = csv.reader(csvfile, delimiter='.')
    astroJson='{&quot;name&quot;: &quot;Astronomical Object&quot;'
    prevLev=0
    for row in astroReader:
        #Identify the depth
        currentLev=readLev(row)
        if currentLev&gt;prevLev:
            astroJson=astroJson+', &quot;children&quot;: [{&quot;name&quot;: &quot;' + row[currentLev]+'&quot;'
        elif currentLev&lt;prevLev:
            jump=prevLev-currentLev
            astroJson=astroJson+', &quot;size&quot;: 1}'+']}'*jump+', {&quot;name&quot;: &quot;' + row[currentLev]+'&quot;'
        elif currentLev==prevLev:
            astroJson=astroJson+', &quot;size&quot;: 1},{&quot;name&quot;: &quot;' + row[currentLev]+'&quot;'
        prevLev=readLev(row)
    astroJson=astroJson+ '}]}]}'
    print astroJson
</pre>
<p>Since only the level of indentation matters to this process it could be repeated with on any data that has the form</p>
<pre class="brush: plain; title: ; notranslate">

* Planet
** [Type]
*** Terrestrial
*** Gas Giant

</pre>
<p>So that&#8217;s it. You&#8217;ll see that it in the source code for the hierarchical examples there is a reference to flare.json. Substitute in a reference to your own file containing the outputted JSON object and be sure to include that file in the directory on your web server.</p>
<p>Of course it&#8217;s a poor substitute for learning the language itself as that enables you to construct your own innovative visualisations but it gets you started.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/727/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/727/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=727&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2013/01/03/lazy-d3-on-some-astronomical-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd329a395c507fe4c19e172a71ede3b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonraper</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2013/01/astrorg-e1357224529759.png?w=750" medium="image">
			<media:title type="html">A Reingold–Tilford Tree of the IVOA Astronomical Object Ontology using D3</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2013/01/astrodend-e1357224862740.png?w=348" medium="image">
			<media:title type="html">A dendrogram of the same data</media:title>
		</media:content>
	</item>
		<item>
		<title>Clegg vs Pleb: An XKCD-esque chart</title>
		<link>http://drunks-and-lampposts.com/2012/10/02/clegg-vs-pleb-an-xkcd-esque-chart/</link>
		<comments>http://drunks-and-lampposts.com/2012/10/02/clegg-vs-pleb-an-xkcd-esque-chart/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 21:11:22 +0000</pubDate>
		<dc:creator>markbulling</dc:creator>
				<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Topical]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ggplot2]]></category>
		<category><![CDATA[xkcd]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=707</guid>
		<description><![CDATA[I saw an interesting &#8220;challenge&#8221; on StackOverflow last night to create an XKCD style chart in R. A couple of hours later &#38; going in a very similar direction to a couple of the answers on SO, I got to something that looked pretty good, using the sin and cos curves for simple and reproducible &#8230; <a href="http://drunks-and-lampposts.com/2012/10/02/clegg-vs-pleb-an-xkcd-esque-chart/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=707&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I saw an interesting &#8220;challenge&#8221; on StackOverflow last night to create <a href="http://stackoverflow.com/questions/12675147/xkcd-style-graphs-in-r">an XKCD style chart in R</a>. A couple of hours later &amp; going in a very similar direction to a couple of the answers on SO, I got to something that looked pretty good, using the sin and cos curves for simple and reproducible replication.</p>
<p>Tonight, I thought I&#8217;d try and apply the theme and styling to some real word and slightly XKCD content: UK politics. Two of the biggest stories of the month in the UK have been <a href="http://www.guardian.co.uk/politics/2012/sep/19/nick-clegg-apologies-tuition-fees-pledge">Nick Clegg&#8217;s apology over reneging</a> on the Liberal Democrat&#8217;s tuition fees pledge and<a href="http://www.telegraph.co.uk/news/politics/9562077/Andrew-Mitchell-did-call-police-officers-plebs-police-report-claims.html"> Andrew Mitchell&#8217;s &#8220;incident&#8221; trying to cycle out of Downing Street, the so-called GateGate</a>.</p>
<p>Using the newly redesigned Google Insights for Search, I looked at searches for clegg and pleb<a href="http://www.google.com/trends/explore#q=clegg%2C%20pleb&amp;geo=GB&amp;date=today%201-m&amp;cmpt=q"> over the last 30 days.</a> A quick manipulation into a csv and applying the XKCD theme and some geom_smoothing gives this:</p>
<p><a href="http://drunksandlampposts.files.wordpress.com/2012/10/xkcd_cleggpleb1.jpg"><img class="aligncenter size-full wp-image-709" title="xkcd_cleggpleb" src="http://drunksandlampposts.files.wordpress.com/2012/10/xkcd_cleggpleb1.jpg?w=750&#038;h=468" alt="" width="750" height="468" /></a></p>
<p>Looks like Andrew Mitchell might be Nick Clegg&#8217;s new best friend in terms of deflecting some of the attention away from the sorry song&#8230;</p>
<p>And here&#8217;s the code (note that you need to have installed the Humor Sans font using install_fonts() ):</p>
<pre class="brush: r; title: ; notranslate">
library(ggplot2)
library(extrafont)

### Already have read in fonts (see previous answer on how to do this)
loadfonts()

### Clegg and Pleb data
pleb.clegg &lt;- read.csv(&quot;pleb and clegg.csv&quot;)
pleb.clegg$Date &lt;- as.Date(pleb.clegg$Date, format=&quot;%d/%m/%Y&quot;)
pleb.clegg$xaxis &lt;- -4

### XKCD theme
theme_xkcd &lt;- theme(
	panel.background = element_rect(fill=&quot;white&quot;),
	axis.ticks = element_line(colour=NA),
	panel.grid = element_line(colour=&quot;white&quot;),
	axis.text.y = element_text(colour=NA),
	axis.text.x = element_text(colour=&quot;black&quot;),
	text = element_text(size=16, family=&quot;Humor Sans&quot;)
	)

### Plot the chart
p &lt;- ggplot(data=pleb.clegg, aes(x=Date, y=Pleb))+
geom_smooth(aes(y=Clegg), colour=&quot;gold&quot;, size=1, position=&quot;jitter&quot;, fill=NA)+
geom_smooth(colour=&quot;white&quot;, size=3, position=&quot;jitter&quot;, fill=NA)+
geom_smooth(colour=&quot;dark blue&quot;, size=1, position=&quot;jitter&quot;, fill=NA)+
geom_text(data=pleb.clegg[10, ], family=&quot;Humor Sans&quot;, aes(x=Date), colour=&quot;gold&quot;, y=20, label=&quot;Searches for clegg&quot;)+
geom_text(data=pleb.clegg[22, ], family=&quot;Humor Sans&quot;, aes(x=Date), colour=&quot;dark blue&quot;, y=4, label=&quot;Searches for pleb&quot;)+
geom_line(aes(y=xaxis), position = position_jitter(h = 0.1), colour=&quot;black&quot;)+
coord_cartesian(ylim=c(-5, 40))+
labs(x=&quot;&quot;, y=&quot;&quot;, title=&quot;Pleb vs Clegg: Google Keyword Volumes&quot;)+
theme_xkcd

ggsave(&quot;xkcd_cleggpleb.jpg&quot;, plot=p, width=8, height=5)
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/707/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/707/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=707&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/10/02/clegg-vs-pleb-an-xkcd-esque-chart/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/18f9940aeef69a4d8e5419503bdbd482?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">markbulling</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/10/xkcd_cleggpleb1.jpg" medium="image">
			<media:title type="html">xkcd_cleggpleb</media:title>
		</media:content>
	</item>
		<item>
		<title>Why are pirates called pirates?</title>
		<link>http://drunks-and-lampposts.com/2012/09/19/why-are-pirates-called-pirates/</link>
		<comments>http://drunks-and-lampposts.com/2012/09/19/why-are-pirates-called-pirates/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 15:59:27 +0000</pubDate>
		<dc:creator>drunksandlampposts</dc:creator>
				<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Topical]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=681</guid>
		<description><![CDATA[In homage to International Talk Like a Pirate Day&#8230; I recently stumbled across a series of blog posts from the folks at IDV that visualised the archive of recorded pirate attacks which has been collected by the US National Geospatial-Intelligence Agency. It&#8217;s a dataset of 6000+ pirate attacks which have been recorded over the last 30 &#8230; <a href="http://drunks-and-lampposts.com/2012/09/19/why-are-pirates-called-pirates/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=681&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In homage to International Talk Like a Pirate Day&#8230;</p>
<p>I recently stumbled across a <a href="http://uxblog.idvsolutions.com/">series of blog posts</a> from the folks at IDV that visualised the archive of recorded pirate attacks which has been collected by the US National Geospatial-Intelligence Agency. It&#8217;s a dataset of 6000+ pirate attacks which have been recorded over the last 30 or so years.</p>
<p>This first map shows where the attacks have been recorded, with four clear areas standing out when the data is aggregated into hexagon bins:</p>
<div id="attachment_690" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/09/world-pirate-map.jpg"><img class="size-full wp-image-690" title="World Pirate Map" src="http://drunksandlampposts.files.wordpress.com/2012/09/world-pirate-map.jpg?w=750&#038;h=416" alt="" width="750" height="416" /></a><p class="wp-caption-text">Map showing areas where pirate attacks have been recorded</p></div>
<p>Zooming in on the area around Yemen, there&#8217;s a clear ramp up in the number of attacks since 2008, which saw a 570% increase compared to the previous year.  As noted by the IDV analysis, most attacks take place on Wednesday and during the spring and autumn.</p>
<div id="attachment_691" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year.jpg"><img class="size-full wp-image-691" title="Attacks recorded by year" src="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year.jpg?w=750&#038;h=416" alt="" width="750" height="416" /></a><p class="wp-caption-text">Number of attacks recorded in the Aden region by year</p></div>
<p>The reaction to the massive increase in attacks in 2008 seems to have been ships not travelling as close to the shore in 2009, leading to more attacks happening further out to sea. This can clearly be seen by looking only at the attacks in 2008 and 2009:</p>
<div id="attachment_689" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/09/pirates-histogram-0809.jpg"><img class="size-full wp-image-689" title="pirates histogram 0809" src="http://drunksandlampposts.files.wordpress.com/2012/09/pirates-histogram-0809.jpg?w=750&#038;h=535" alt="" width="750" height="535" /></a><p class="wp-caption-text">Number of Pirates attacks in the Aden area in 2008 and 2009 (Distance is in degrees)</p></div>
<p>Within the dataset, as well as information around the location of the attack, there are also descriptions of the attacks, which lends itself well to some text analysis to understand where there have been changes in the nature of the attacks above and beyond their distance.</p>
<p>Some analysis of the descriptions of the attacks reveals that the nature of the attacks also changed in 2010, with more featuring terms such as security and speedboats (full details of how these topic groups have been created is below). The analysis was used to identify five different types of attacks.</p>
<p>From the chart below, Topics 4 and 5came to prominence in 2008, with Topic 5 maintaining it&#8217;s share in 2010 before Topic 2 then increasing in number in 2011 and 2012. This is just scratching the surface with what can be done with topic analysis and given that all the documents are related to pirate attacks, there&#8217;s not the variation compared to what you would see in say, news articles about many subjects. There&#8217;s a good walk through of using the TopicModels package <a href="http://www.jstatsoft.org/v40/i13/paper">here</a>.</p>
<div id="attachment_692" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year-and-topic.jpg"><img class="size-full wp-image-692" title="Attacks by year and topic" src="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year-and-topic.jpg?w=750&#038;h=416" alt="" width="750" height="416" /></a><p class="wp-caption-text">Attacks in the Yemen region classified into one of five topics based on description</p></div>
<p>And what are these topics? The table below shows the top 10 terms for each of the 5 topics &#8211; they&#8217;re not as clear cut as you&#8217;d hope (mainly because there are a fair few verbs and numbers in there at the moment), but give an idea of some differences &#8211; skiffs versus speedboats, topic 2 featuring &#8220;security&#8221;, the numbers involved and months of the year all hit at different aspects of the attacks which have been picked out.</p>
<pre class="brush: r; title: ; notranslate">

     Topic 1  Topic 2  Topic 3    Topic 4    Topic 5
1  attempted     were hijacked       boat      boats
2        six     fire      are      white       four
3       took security attacked       port        men
4  increased   skiffs    miles      about    persons
5      board     team  vessels      small      three
6     skiffs     when     this        sep        may
7     alarm,      jan  advised        apr speedboats
8        for    seven merchant    general       five
9   chemical      had  boarded reportedly    reports
10      guns    which exercise  speedboat       each

</pre>
<p>And the reason why pirates are called pirates? Because they Argghhhhhhhhhh.</p>
<p>NB. I haven&#8217;t had a chance to check on the copyright, etc. for hosting the pirate dataset, so please download it from <a href="http://www.google.co.uk/urlsa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;ved=0CCMQFjAA&amp;url=http%3A%2F%2Fmsi.nga.mil%2FNGAPortal%2FMSI.portal%3F_nfpb%3Dtrue%26_pageLabel%3Dmsi_portal_page_65&amp;ei=e-tZUOOPCsfB0gWYsoHgCw&amp;usg=AFQjCNH-Dl41PlNhG9Jtl6Tk4EkF0uExTQ&amp;sig2=kI1a4Lrsc-dhZpenYkkEOw">here</a>.</p>
<p><strong>Reading the data into R.</strong></p>
<pre class="brush: r; title: ; notranslate">
library(maps)
library(sp)
library(maptools)
library(ggplot2)
library(spatstat)
gpclibPermit()
library(topicmodels)

pirates.data &lt;- readShapePoints(&quot;C:\\ASAM 05 SEP 12&quot;)
pirates.data.2 &lt;- as.data.frame(pirates.data)
</pre>
<p><strong>How far to the shore?</strong></p>
<p>Next is to turn the data into a Planar Point Pattern in order to allow for calculation of nearest coastal point for each attack. The same technique is then used to create a similar file for the coastline. Use the nncross function to find the distance from each attack to the nearest point on the coast (and identify which point that is).</p>
<pre class="brush: r; title: ; notranslate">

bb &lt;- c(40, 56, 7, 17)
pirates.ppp &lt;- as.ppp(pirates.data.2[,13:14], bb)

worldmap &lt;- map_data(&quot;world&quot;)
land.ppp &lt;- as.ppp(worldmap[, 1:2], bb)
land.df &lt;- as.data.frame(cbind(land.ppp$x, land.ppp$y))

reg &lt;- as.data.frame(map(&quot;world&quot;, xlim = c(40, 56), ylim = c(7, 17), plot = FALSE)[c(&quot;x&quot;, &quot;y&quot;)])

nearest.land &lt;- nncross(pirates.ppp, land.ppp)
pirates.nearest.land &lt;- as.data.frame(cbind(as.numeric(pirates.ppp$x), as.numeric(pirates.ppp$y), as.numeric(nearest.land$dist)))

pirates.data.aden &lt;- merge(pirates.nearest.land, pirates.data.2, by.x=c(&quot;V1&quot;, &quot;V2&quot;), by.y = c(&quot;coords.x1&quot;, &quot;coords.x2&quot;))
</pre>
<p><strong>Calculate various extra columns such as year of date and number of attacks by year </strong></p>
<pre class="brush: r; title: ; notranslate">
pirates.data.aden$year &lt;- 1900 + as.POSIXlt(pirates.data.aden$DateOfOcc)$year
pirates.data.aden$month &lt;- 1900 + as.POSIXlt(pirates.data.aden$DateOfOcc)$year
pirates.data.aden$year &lt;- 1900 + as.POSIXlt(pirates.data.aden$DateOfOcc)$year

year.stats &lt;- ddply(pirates.data.aden, .(year), summarise, attacks= length(year))
year.stats$Delt &lt;- Delt(year.stats$attacks)
</pre>
<p><strong> Plot the world map showing attacks binned into hexagons </strong></p>
<pre class="brush: r; title: ; notranslate">
ggplot()+
	stat_summary_hex(fun=&quot;length&quot;, data=pirates.data.2, aes(x=coords.x1, y=coords.x2, z=coords.x2)) +
	scale_fill_gradient(low=&quot;white&quot;, high=&quot;red&quot;, &quot;Pirate Attacks recorded&quot;) +
	geom_path(aes(x=x, y=y), data = world) +
	mb.theme +
	labs(x=&quot;&quot;, y=&quot;&quot;) +
	theme(panel.background = element_rect(fill=&quot;white&quot;),
		axis.ticks = element_line(colour=&quot;white&quot;),
		axis.text = element_text(colour=&quot;white&quot;),
		axis.line = element_line(colour=&quot;white&quot;),
		panel.grid = element_line(colour=NA)) +
		scale_x_continuous(breaks=NA)+
		scale_y_continuous(breaks=NA)
</pre>
<p><strong> Number of attacks by year near Aden </strong></p>
<pre class="brush: r; title: ; notranslate">
ggplot(data=pirates.data.aden, aes(x=year))+
		geom_histogram(binwidth=1, colour=&quot;white&quot;, fill=&quot;dark blue&quot;)+
		mb.theme +
		labs(x=&quot;Year&quot;, y=&quot;Number of attacks recorded&quot;)
</pre>
<p><strong> Attacks by distance from Shore as a histogram </strong></p>
<pre class="brush: r; title: ; notranslate">
ggplot(data=subset(pirates.data.aden, year%in%c(2008, 2009)), aes(x=V3))+geom_histogram(fill=&quot;dark blue&quot;, colour=&quot;white&quot;)+
		mb.theme+
		facet_wrap(~year, ncol=1) +
		labs(x=&quot;Distance from shore&quot;, y=&quot;Number of attacks&quot;)
</pre>
<p><strong> Topic Models analysis of attack descriptions near Aden </strong></p>
<pre class="brush: r; title: ; notranslate">
corpus &lt;- Corpus(VectorSource(pirates.data.aden$Desc1))

dtm &lt;- DocumentTermMatrix(corpus)

term_tfidf &lt;- tapply(dtm$v/row_sums(dtm)[dtm$i], dtm$j, mean) * log2(nDocs(dtm)/col_sums(dtm &gt; 0))
dtm &lt;- dtm[, term_tfidf &gt;= 0.1]
dtm &lt;- dtm[row_sums(dtm) &gt; 0,]

k=5
SEED=2012

TM &lt;- list(VEM = LDA(dtm, k = k, control = list(seed = SEED)),
		VEM_fixed = LDA(dtm, k = k, control = list(estimate.alpha = FALSE, seed = SEED)),
		Gibbs = LDA(dtm, k = k, method = &quot;Gibbs&quot;, control = list(seed = SEED, burnin = 1000, thin = 100, iter = 1000)),
		CTM = CTM(dtm, k = k, control = list(seed = SEED, var = list(tol = 10^-4), em = list(tol = 10^-3))))

pirates.data.aden$Topic &lt;- topics(TM[[&quot;Gibbs&quot;]], 1)

ggplot(data=pirates.data.aden, aes(x=year, fill=as.factor(Topic), group=as.factor(Topic)))+
		geom_histogram(binwidth=1, colour=&quot;white&quot;)+
		scale_fill_brewer(palette=&quot;Set3&quot;, &quot;Topic Group&quot;) +
		mb.theme +
		labs(x=&quot;&quot;, y=&quot;&quot;)
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/681/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=681&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/09/19/why-are-pirates-called-pirates/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/176dba89b506295b42160ff9773a2fc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">drunksandlampposts</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/09/world-pirate-map.jpg" medium="image">
			<media:title type="html">World Pirate Map</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year.jpg" medium="image">
			<media:title type="html">Attacks recorded by year</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/09/pirates-histogram-0809.jpg" medium="image">
			<media:title type="html">pirates histogram 0809</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/09/attacks-by-year-and-topic.jpg" medium="image">
			<media:title type="html">Attacks by year and topic</media:title>
		</media:content>
	</item>
		<item>
		<title>R: Dealing with package updates</title>
		<link>http://drunks-and-lampposts.com/2012/06/20/r-dealing-with-package-updates-12/</link>
		<comments>http://drunks-and-lampposts.com/2012/06/20/r-dealing-with-package-updates-12/#comments</comments>
		<pubDate>Wed, 20 Jun 2012 11:03:12 +0000</pubDate>
		<dc:creator>drunksandlampposts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/2012/06/20/r-dealing-with-package-updates-12/</guid>
		<description><![CDATA[Here&#8217;s a very short post to highlight one of the &#8220;highlights&#8221; of my week that I thought was worth sharing with the wider community. One of the things I find great about R is the rapidly evolving ecosystem where new packages are being constantly created and others are being updated. Up until now, I&#8217;ve found &#8230; <a href="http://drunks-and-lampposts.com/2012/06/20/r-dealing-with-package-updates-12/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=613&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a very short post to highlight one of the &#8220;highlights&#8221; of my week that I thought was worth sharing with the wider community.</p>
<p>One of the things I find great about R is the rapidly evolving ecosystem where new packages are being constantly created and others are being updated.</p>
<p>Up until now, I&#8217;ve found this to be a very good thing, but experienced the other side this week, where an upgrade to a package broke a pretty big script that I&#8217;d been working on.   </p>
<p>The &#8220;quick&#8221; solution in my case was to use the CRAN archive to download the source for earlier versions of the package (and it&#8217;s dependencies) that was causing issue and then build and install them to overwrite the upgrade &#8211; knowledge of how to build a package from source in Windows came in very handy and you can read more about how to do it in a <a href="http://drunks-and-lampposts.com/2012/01/11/making-an-r-package-not-as-hard-as-you-think/">previous D&amp;L post</a>. </p>
<p>The longer term solution is a lot trickier, particularly where R is being used in a collaborative environment and reproducibility is important, either between machines or over time.</p>
<p>I suspect one solution is to have a common library that is centrally maintained and then changing the default location that R looks for installed packages (which is also a handy solution when dealing with not having to download all packages against once you&#8217;ve upgraded base R). </p>
<p>On top of this, I suspect there would then need to be some type of test suite which, once updates to packages were available, checked in a development environment that existing scripts and processes still worked. None of this is new to software and IT folk, but it&#8217;s a novel issue at the moment for the analyst community I suspect.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/613/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=613&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/06/20/r-dealing-with-package-updates-12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/176dba89b506295b42160ff9773a2fc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">drunksandlampposts</media:title>
		</media:content>
	</item>
		<item>
		<title>R: Creating a shortcut to run a gWidgets GUI</title>
		<link>http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/</link>
		<comments>http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 12:07:13 +0000</pubDate>
		<dc:creator>drunksandlampposts</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[rgui]]></category>

		<guid isPermaLink="false">http://drunks-and-lampposts.com/?p=582</guid>
		<description><![CDATA[I&#8217;ve been playing around with using gWidgets on Windows over the last few weeks as a way of creating front ends for various functions and set of functions that I&#8217;ve created, so that non R users can have the benefit of these without having to write a single line of code. The likes of 4Dpiecharts &#8230; <a href="http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=582&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been playing around with using gWidgets on Windows over the last few weeks as a way of creating front ends for various functions and set of functions that I&#8217;ve created, so that non R users can have the benefit of these without having to write a single line of code.</p>
<p>The likes of <a href="http://4dpiecharts.com/">4Dpiecharts</a> offer some good introductions to various aspects of the tool, but one thing which I struggled to find was a way of creating an icon based way of launching the GUI &#8211; i.e. click on an icon on the desktop and have the GUI launch in an application like way.</p>
<p>At first, I assumed that this could be done via a batch file, but found that this didn&#8217;t seem to work when the script should display a GUI as the output.</p>
<p>I then came across this very handy stackoverflow <a href="http://stackoverflow.com/questions/10312417/running-an-r-script-using-a-windows-shortcut">post</a>. Although, slightly enigmatic, the method outlined by Greg Snow worked and gave me what I wanted.</p>
<p>1. Create a new folder at a convenient place on your drive.</p>
<p>2. Create a shortcut to RGui.exe or Rterm.exe &#8211; these will likely be located in a folder like C:\program files\R\R-version\bin\i386. If the shortcut is to RGui then the full R GUI will be brought up, whilst R term will bring up the console version (I went with this option so that the focus would stay with the GUI).</p>
<p>3. Create an R function called .First which includes the various functions, data, etc. to launch your code.</p>
<pre class="brush: r; title: ; notranslate"> .First &lt;- function() {  insert code here } </pre>
<p>4. Ensure that your R session is clean and only contains the functions (particularly .First) and data that you want to launch when you double click the shortcut. Save this workspace (which will be called &#8220;.rData&#8221;) to the folder that you created in Step 1.</p>
<p>5. Right click on the Shortcut that you created in Step 2 and change the Start In property (under the &#8220;Shortcut&#8221; tab) to the name of the folder that you created in Step 1.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/582/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=582&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/06/18/r-creating-a-shortcut-to-run-a-gwidgets-gui/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/176dba89b506295b42160ff9773a2fc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">drunksandlampposts</media:title>
		</media:content>
	</item>
		<item>
		<title>Graphing the history of philosophy</title>
		<link>http://drunks-and-lampposts.com/2012/06/13/graphing-the-history-of-philosophy/</link>
		<comments>http://drunks-and-lampposts.com/2012/06/13/graphing-the-history-of-philosophy/#comments</comments>
		<pubDate>Wed, 13 Jun 2012 20:44:40 +0000</pubDate>
		<dc:creator>simonraper</dc:creator>
				<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[Web Scraping and APIs]]></category>
		<category><![CDATA[dbpedia]]></category>
		<category><![CDATA[gephi]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[SPARQL]]></category>
		<category><![CDATA[Visualisation]]></category>

		<guid isPermaLink="false">https://drunksandlampposts.wordpress.com/?p=579</guid>
		<description><![CDATA[This one came about because I was searching for a data set on horror films (don&#8217;t ask) and ended up with one describing the links between philosophers. To cut a long story very short I&#8217;ve extracted the information in the influenced by section for every philosopher on Wikipedia and used it to construct a network &#8230; <a href="http://drunks-and-lampposts.com/2012/06/13/graphing-the-history-of-philosophy/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=579&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div id="attachment_617" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/06/classical.png"><img class="size-full wp-image-617" title="Classical" src="http://drunksandlampposts.files.wordpress.com/2012/06/classical.png?w=750&#038;h=514" alt="" width="750" height="514" /></a><p class="wp-caption-text">A close up of ancient and medieval philosophy ending at Descartes and Leibniz</p></div>
<p>This one came about because I was searching for a data set on horror films (don&#8217;t ask) and ended up with one describing the links between philosophers.</p>
<p>To cut a long story very short I&#8217;ve extracted the information in the <em>influenced by</em> section for every philosopher on Wikipedia and used it to construct a network which I&#8217;ve then visualised using <a href="http://gephi.org/" target="_blank">gephi</a></p>
<p>It&#8217;s an easy process to repeat. It could be done for any area within Wikipedia where the information forms a network. I chose philosophy because firstly the influences section is very well maintained and secondly I know a little bit about it. At the bottom of this post I&#8217;ve described how I got there.</p>
<p>First I&#8217;ll show why I think it&#8217;s worked as a visualisation. Here&#8217;s the whole graph.</p>
<p><a href="http://drunksandlampposts.files.wordpress.com/2012/06/philprettyv4.png"><img class="aligncenter size-full wp-image-662" title="philPrettyV4" src="http://drunksandlampposts.files.wordpress.com/2012/06/philprettyv4.png?w=750&#038;h=750" alt="" width="750" height="750" /></a></p>
<p>Each philosopher is a node in the network and the lines between them (or edges in the terminology of graph theory) represents lines of influence. The node and text are sized according to the number of connections (both in and out). The algorithm that visualises the graph also tends to put the better connected nodes in the centre of the diagram so we see the most influential philosophers, in large text, clustered in the centre. It all seems about right with the major figures in the western philosophical tradition taking the centre stage. (I need to also add the direction of influence with a arrow head &#8211; something I&#8217;ve not got round to yet.) A shortcoming however is that this evaluation only takes into account direct lines of influence. Indirect influence via another person in the network does not enter into it. This probably explains why Descartes is smaller than you&#8217;d think. It would also be better if the nodes were sized only by the number of outward connections although I think overall the differences would be slight. I&#8217;ll get round to that.</p>
<p>It gets more interesting when we use Gephi to identify communities (or modules) within the network. Roughly speaking it identifies groups of nodes which are more connected with each other than with nodes in other groups. Philosophy has many traditions and schools so a good test would be whether the algorithm picks them out.</p>
<p>It has been fairly successful. Below we can see the so called continental tradition picked out in green, stemming from Hegel and Nietzsche, leading into Heidegger and Sartre and ending in the isms of the twentieth century. It&#8217;s interesting that there is separate subgroup, in purple, influenced mainly by Schopenhauer (out of shot) and Freud.</p>
<div id="attachment_620" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/06/continental1.png"><img class="size-full wp-image-620" title="Continental" src="http://drunksandlampposts.files.wordpress.com/2012/06/continental1.png?w=750&#038;h=491" alt="" width="750" height="491" /></a><p class="wp-caption-text">The Continental Tradition</p></div>
<p>And this close up is of the analytical tradition emerging out of Frege, Russell and Wittgenstein. At the top and to the left you can see the British empirical school and the American pragmatists.</p>
<div id="attachment_618" class="wp-caption aligncenter" style="width: 760px"><a href="http://drunksandlampposts.files.wordpress.com/2012/06/analytical.png"><img class="size-full wp-image-618" title="analytical" src="http://drunksandlampposts.files.wordpress.com/2012/06/analytical.png?w=750&#038;h=459" alt="" width="750" height="459" /></a><p class="wp-caption-text">British Empiricism, American Pragmatism and the Analytical Tradition</p></div>
<p>It would be interesting to play with the number of groups picked out by the algorithm. It would hopefully identify sub groups within these overarching traditions.</p>
<p>The graph is probably most insightful when you zoom in close. Gephi produces a vector graphic output so if you&#8217;re interested you can download it <a href="https://www.dropbox.com/sh/y1p37cto19v8fji/ezvEvEiIUb" target="_blank">here</a> and explore it yourself.</p>
<p>Now for how you do it.</p>
<p>The first stop is <a href="http://dbpedia.org" target="_blank">dbpedia</a>. This is a fantastic resource which stores structured information extracted from wikepdia in a database that accessible through the web. Among other things it stores all of the information you see in an infobox on a Wikipedia page. For example I was after the influenced and influenced by fields that you find on the infobox on the page for <a href="http://en.wikipedia.org/wiki/Plato" target="_blank">Plato</a>.</p>
<p>The next step is to extract this information. For this we need two things: a SPARQL endpoint (try <a href="http://dbpedia.org/snorql/">snorql</a>), which is an online interface to submit our queries and little knowledge of <a href="http://en.wikipedia.org/wiki/SPARQL">SPARQL</a> a specialist language for querying the semantic web. This is a big (and exciting) area that has to do with querying information that is structured in triples (subject-relationship-object). I assume it has its roots in predicate logic so the analytical philosophers would have been pleased. However the downside is that the language itself a lot more difficult to learn than say SQL and to complicate things still further you need to know the ontological structure of the resource you are querying. I probably wouldn&#8217;t have got anywhere at all were it not for a great <a href="http://www.snee.com/bobdc.blog/2007/11/querying-dbpedia.html">blog post</a> by Bob DuCharme which is a simple guide for getting the information out of wikipedia.</p>
<p>In the end the query I needed was very simple. You can test it by submitting it in <a href="http://dbpedia.org/snorql/">snorql</a>.</p>
<p>SELECT *<br />
WHERE {<br />
?p a<br />
&lt;<a href="http://dbpedia.org/ontology/Philosopher&#038;gt" rel="nofollow">http://dbpedia.org/ontology/Philosopher&#038;gt</a>; .<br />
?p &lt;<a href="http://dbpedia.org/ontology/influenced&#038;gt" rel="nofollow">http://dbpedia.org/ontology/influenced&#038;gt</a>; ?influenced.<br />
}</p>
<p>It then needed a bit of cleaning as the punctuation was coded for URLS. For this I used the following online <a href="http://meyerweb.com/eric/tools/dencoder/">URL decoder</a>.</p>
<p>After a bit more simple manipulation in excel I had a finished csv file that consisted of three columns<br />
<code><br />
Philosopher A<br />
Philosopher B<br />
Weight<br />
</code></p>
<p>Each row in the data set represented a line of influence from philosopher A to philosopher B. The weight column contained a dummy entry of 1 because in our graph we do not want any one link to matter more than any other.</p>
<p><a href="http://gephi.org/">Gephi </a>is the tool I used to create the visualisation of the graph. It&#8217;s both fantastic and open source. You can download it and set it up in minutes. For a quick tutorial see this <a href="https://gephi.org/users/quick-start/">link</a>. There are many settings you can use to change the way your graph looks. I used a combination of the force atlas and the <a href="http://en.wikipedia.org/wiki/Force-based_algorithms_(graph_drawing)">fruchterman-reingold</a> layout algorithms. I then scaled text and node size by node degree (number of connections) and suppressed all nodes with less than four connections (it was overwhelming otherwise). The partition tool is used to create the communities. Full instructions are in the tutorial. I also found this <a href="http://www.mkbergman.com/968/a-new-best-friend-gephi-for-large-scale-networks/">blog entry</a> very useful as a guide.</p>
<p>I hope that helps anyone who is trying to do something similar. If anyone does has a data set on horror films tagged with keywords please let me know!</p>
<p>If you liked this post and would like to see more like it then please subscribe by email (see the link in the side bar ) or sign up to our RSS feed.</p>
<p>Simon</p>
<p><strong>Update</strong> Griff at <a href="http://griffsgraphs.wordpress.com/2012/07/03/graphing-every-idea-in-history" target="_blank">Griff&#8217;s graphs</a> has used the instructions above to create a fantastic visualization of the influence network of everyone on Wikipedia. It&#8217;s well worth a look.</p>
<p><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="license"><img style="border-width:0;" src="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" alt="Creative Commons Licence" /></a><br />
Graphing the history of philosophy by <a href="http://drunks-and-lampposts.com/" rel="cc:attributionURL">Simon Raper</a> is licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="license">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.<br />
Based on a work at <a href="http://drunksandlampposts.files.wordpress.com/2012/06/philprettyv4.png" rel="dct:source">drunksandlampposts.files.wordpress.com</a>.<br />
Permissions beyond the scope of this license may be available at <a href="http://drunks-and-lampposts.com/" rel="cc:morePermissions">http://drunks-and-lampposts.com/</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/579/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=579&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/06/13/graphing-the-history-of-philosophy/feed/</wfw:commentRss>
		<slash:comments>233</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/cd329a395c507fe4c19e172a71ede3b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonraper</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/06/classical.png" medium="image">
			<media:title type="html">Classical</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/06/philprettyv4.png" medium="image">
			<media:title type="html">philPrettyV4</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/06/continental1.png" medium="image">
			<media:title type="html">Continental</media:title>
		</media:content>

		<media:content url="http://drunksandlampposts.files.wordpress.com/2012/06/analytical.png" medium="image">
			<media:title type="html">analytical</media:title>
		</media:content>

		<media:content url="http://i.creativecommons.org/l/by-nc-sa/3.0/80x15.png" medium="image">
			<media:title type="html">Creative Commons Licence</media:title>
		</media:content>
	</item>
		<item>
		<title>D3 &#8211; another acronym to learn</title>
		<link>http://drunks-and-lampposts.com/2012/05/31/d3-another-acronym-to-learn/</link>
		<comments>http://drunks-and-lampposts.com/2012/05/31/d3-another-acronym-to-learn/#comments</comments>
		<pubDate>Thu, 31 May 2012 10:00:38 +0000</pubDate>
		<dc:creator>drunksandlampposts</dc:creator>
				<category><![CDATA[data visualisation]]></category>
		<category><![CDATA[d3]]></category>

		<guid isPermaLink="false">https://drunksandlampposts.wordpress.com/?p=572</guid>
		<description><![CDATA[D3 (which stands for data driven documents ) has been getting a lot of traction over the last few months, with more and more interactive and animated visualisations using this JavaScript library. The author of the library, Mike Bostock, is very active in both developing the library and also in providing a constant stream of &#8230; <a href="http://drunks-and-lampposts.com/2012/05/31/d3-another-acronym-to-learn/">Continue reading <span class="meta-nav">&#187;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=572&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://d3js.org/" target="_blank"><img class="alignleft" title="D3 example" src="http://d3js.org/ex/force.png" alt="" width="226" height="180" />D3</a> (which stands for <strong>d</strong>ata <strong>d</strong>riven <strong>d</strong>ocuments ) has been getting a lot of traction over the last few months, with more and more interactive and animated visualisations using this JavaScript library. The author of the library, Mike Bostock, is very active in both developing the library and also in providing a constant stream of <a href="http://bost.ocks.org/mike/miserables/" target="_blank">examples</a> <a href="http://bl.ocks.org/1256572" target="_blank">using</a> <a href="http://bl.ocks.org/849853" target="_blank">the</a> <a href="http://square.github.com/crossfilter/" target="_blank">language</a>.</p>
<p>For anyone coming from a ggplot2 background, there are a lot of similarities with certain parts of D3 and the attributes that can be given to objects. There is a fair amount more code to write, but there are a lot of great tutorials out there which give very good introductions to creating good looking visualisations. There&#8217;s a bit of a learning curve to using it, but there are lots of tutorials out there which make it easy to get started, for example,<a href="http://christopheviau.com/d3_tutorial/" target="_blank"> here</a>, <a href="http://www.janwillemtulp.com/2011/03/20/tutorial-introduction-to-d3/" target="_blank">here</a> and <a href="http://alignedleft.com/tutorials/d3/" target="_blank">here</a>.</p>
<p>The general idea behind the language is to encode objects, for example, a circle, with various attributes like colour, size and  location. These could either be hard coded, based on a function (e.g. the sine function) or based on a dataset. The additional nice feature of the software is the built in ability to transition between states (e.g. moving a circle from location A to location B) which would normally be difficult to do, and probably appear quite jerky.</p>
<p>For anyone coming from a Tableau background, D3 provides a lot more flexibility in what can be achieved, but is a very code based solution and not a BI solution.</p>
<p>From my experience so far, a specialist HTML editor like Astana Studio is a good place to start for a few reasons, including colour coding for the HTML and also having a built in local web server so that you can quickly preview the results of your code writing.</p>
<p>As an aside, you&#8217;ll need a web server of some sort for any D3 code to work (It took me a frustrating hour to figure this out). The alternative to using the built in Astana server is something like using the python simple http server, but I find this a lot more cumbersome.</p>
<p>Oh, and sorry for not having any examples built into the post &#8211; WordPress.com doesn&#8217;t like having custom JavaScript in posts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drunksandlampposts.wordpress.com/572/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drunksandlampposts.wordpress.com/572/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drunks-and-lampposts.com&#038;blog=30889107&#038;post=572&#038;subd=drunksandlampposts&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://drunks-and-lampposts.com/2012/05/31/d3-another-acronym-to-learn/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/176dba89b506295b42160ff9773a2fc1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">drunksandlampposts</media:title>
		</media:content>

		<media:content url="http://d3js.org/ex/force.png" medium="image">
			<media:title type="html">D3 example</media:title>
		</media:content>
	</item>
	</channel>
</rss>
