<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Walking Randomly</title>
	
	<link>http://www.walkingrandomly.com</link>
	<description>Because it's more fun than getting there in a straight line.</description>
	<lastBuildDate>Thu, 02 Sep 2010 17:12:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/WalkingRandomly" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="walkingrandomly" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Zero padding filenames using bash in Linux</title>
		<link>http://www.walkingrandomly.com/?p=2850</link>
		<comments>http://www.walkingrandomly.com/?p=2850#comments</comments>
		<pubDate>Thu, 02 Sep 2010 17:12:07 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2850</guid>
		<description><![CDATA[I recently had a set of files that were named as follows
frame1.png
frame2.png
frame3.png
frame4.png
frame5.png
frame6.png
frame7.png
frame8.png
frame9.png
frame10.png

and so on, right up to frame750.png.  The plan was to turn these .png files into an uncompressed movie using mencoder via the following command (original source)
mencoder mf://*.png -mf w=720:h=720:fps=25:type=png -ovc raw -oac copy -o output.avi

but I ended up with a movie that [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a set of files that were named as follows</p>
<pre>frame1.png
frame2.png
frame3.png
frame4.png
frame5.png
frame6.png
frame7.png
frame8.png
frame9.png
frame10.png
</pre>
<p>and so on, right up to frame750.png.  The plan was to turn these .png files into an uncompressed movie using mencoder via the following command (<a href="http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html">original source</a>)</p>
<pre>mencoder mf://*.png -mf w=720:h=720:fps=25:type=png -ovc raw -oac copy -o output.avi
</pre>
<p>but I ended up with a movie that jumped all over the place since the frames were in an odd order.  In the following order in fact</p>
<pre>
frame0.csv
frame100.csv
frame101.csv
frame102.csv
frame103.csv
frame104.csv
frame105.csv
frame106.csv
frame107.csv
frame108.csv
frame109.csv
frame10.csv
frame110.csv
</pre>
<p>This is because globbing expansion (the <strong>*.png</strong> bit) is alphabetical in bash rather than numerical.  </p>
<p>One way to get the frames in the order that I want is to zero-pad them.  In other words I replace <strong>file1.png</strong> with <strong>file001.png</strong> and <strong>file20.png</strong> with <strong>file020.png</strong> and so on.  Here&#8217;s how to do that in bash</p>
<pre>
#!/bin/bash
num=`expr match "$1" '[^0-9]*\([0-9]\+\).*'`
paddednum=`printf "%03d" $num`
echo ${1/$num/$paddednum}
</pre>
<p>Save the above to a file called zeropad.sh and then do the following command to make it executable</p>
<pre>
chmod +x ./zeropad.sh
</pre>
<p>You can then use the zeropad.sh script as follows</p>
<pre>
./zeropad.sh frame1.png
</pre>
<p>which will return the result </p>
<pre>
frame001.png
</pre>
<p> All that remains is to use this script to rename all of the .png files in the current directory such that they are zeropadded.</p>
<pre>
for i in *.png;do mv $i `./zeropad.sh $i`; done
</pre>
<p>You may want to change the number of digits used in each filename from 3 to 5 (say).  To do this just change %03d in zeropad.sh to %05d</p>
<p>Let me know if you find this useful or have an alternative solution you&#8217;d like to share (in another language maybe?)</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/hlKcFFYBcVY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2850</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Academic journals that contain easier material</title>
		<link>http://www.walkingrandomly.com/?p=2801</link>
		<comments>http://www.walkingrandomly.com/?p=2801#comments</comments>
		<pubDate>Wed, 11 Aug 2010 11:07:38 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[general math]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2801</guid>
		<description><![CDATA[Back when I was doing my own research (my field was photonic crystals), I read a lot of research articles in journals such as Physical Review B, Applied Optics and The Journal of the Optical Society of America B.  These journals represent the state of the art in their respective fields and if you are [...]]]></description>
			<content:encoded><![CDATA[<p>Back when I was doing my own research (my field was <a href="http://en.wikipedia.org/wiki/Photonic_crystal">photonic crystals</a>), I read a lot of research articles in journals such as <a href="http://prb.aps.org/browse">Physical Review B</a>, <a href="http://www.opticsinfobase.org/ao/Issue.cfm">Applied Optics</a> and <a href="http://www.opticsinfobase.org/josab/Issue.cfm">The Journal of the Optical Society of America B</a>.  These journals represent the state of the art in their respective fields and if you are not a full time researcher then you will probably find many of their articles difficult to <strong>really</strong> get into.  When I say &#8216;really get into&#8217; I mean &#8216;understand well enough that you could reproduce or develop their results if you wanted to&#8217;.</p>
<p>These days I am not a full-time researcher (although I do assist many of them on a regular basis) but I still like to read journal articles.  The type of journal I read, however, has changed rather a lot since I&#8217;m doing it for fun and personal interest rather than for my salary.  I sometimes take what I read in these articles and turn them into <a href="http://www.walkingrandomly.com/?p=1471">blog posts</a> and/or <a href="http://www.walkingrandomly.com/?p=133">Wolfram Demonstrations</a>.</p>
<p>Here&#8217;s a list of some of my favourites</p>
<ul>
<li><a href="http://iopscience.iop.org/0143-0807">European Journal of Physics</a>: According to their website &#8220;The primary mission of <em>European Journal of Physics</em> is to assist  in maintaining and improving the standard of taught physics in  universities and other institutes of higher education.&#8221;  There&#8217;s lots of cool stuff to be found with past articles including <a href="http://iopscience.iop.org/0143-0807/30/6/S03">The Kaye effect</a>, <a href="http://iopscience.iop.org/0143-0807/31/5/009">Mean Free Path in Soccer and Gases</a> and <a href="http://iopscience.iop.org/0143-0807/31/5/013">Cooling and warming laws: an exact analytical solution</a></li>
<li><a href="http://www.maa.org/pubs/cmj.html">The College Mathematics Journal</a>: According to their website &#8220;<em>The College Mathematics Journal</em> is designed to enhance classroom learning and stimulate thinking regarding undergraduate mathematics.&#8221;</li>
<li><a href="http://www.jstor.org/action/showPublication?journalCode=mathgaze">The Mathematical Gazette</a>: I could spend all day browsing through the archives of this one &#8211; it&#8217;s a math nerds dream.  For example, when you read an article written in 1894 with the title &#8216;<strong>Some old Text-Books</strong>&#8216; you know that they are going to be <strong>really</strong> old! It&#8217;s also fun to compare the &#8216;problems and solutions&#8217; from 1900 to those from 2000.  From the website &#8220;<cite>The Mathematical Gazette</cite> is the original journal of the Mathematical Association and it is now over a century old&#8221;</li>
<li><a href="http://www.jstor.org/action/showPublication?journalCode=mathmaga">Mathematics Magazine</a>: I&#8217;ve had one or two ideas for Wolfram Demonstrations from this magazine.  From the website &#8220;<cite>Mathematics Magazine</cite> presents articles and notes on undergraduate mathematical topics&#8221;</li>
</ul>
<p>What journals do you recommend for fun and/or teaching purposes in areas such as physics, mathematics and statistics?</p>
<p><strong>Update</strong> The following are recommendations from readers in the comments section.  Thanks to everyone who responded.  Feel free to let me know if your favourite isn&#8217;t on this list.</p>
<ul>
<li><a href="http://www.springer.com/mathematics/journal/283">The Mathematical Intelligencer</a></li>
<li><a href="http://www.ams.org/notice">Notices of the AMS</a></li>
<li><a href="http://www.baywood.com/journals/previewjournals.asp?id=0022-412X">Journal of Recreational Mathematics</a></li>
<li><a rel="nofollow" href="http://scitation.aip.org/ajp/">American Journal of Physics</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/sNhHC27-gMU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2801</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>An alternative to the ranksum function using the NAG toolbox for MATLAB</title>
		<link>http://www.walkingrandomly.com/?p=2782</link>
		<comments>http://www.walkingrandomly.com/?p=2782#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:25:11 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[NAG Library]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[parallel programming]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2782</guid>
		<description><![CDATA[The MATLAB function ranksum is part of MATLAB&#8217;s  Statistics Toolbox. Like many organizations who use network licensing for MATLAB and its toolboxes, my employer, The University of Manchester, sometimes runs out of licenses for this toolbox  which leads to following error message when you attempt to evaluate ranksum.
??? License checkout failed.
License Manager Error [...]]]></description>
			<content:encoded><![CDATA[<p>The MATLAB function <strong><a href="http://www.mathworks.com/access/helpdesk/help/toolbox/stats/ranksum.html">ranksum</a> </strong>is part of MATLAB&#8217;s <a href="http://www.mathworks.com/products/statistics/"> Statistics Toolbox</a>. Like many organizations who use network licensing for MATLAB and its toolboxes, my employer, The University of Manchester, sometimes runs out of licenses for this toolbox  which leads to following error message when you attempt to evaluate <strong>ranksum</strong>.</p>
<pre>??? License checkout failed.
License Manager Error -4
Maximum number of users for Statistics_Toolbox reached.
Try again later.
To see a list of current users use the lmstat utility or contact your License Administrator.</pre>
<p>An alternative to the Statistics Toolbox is the <a href="http://www.nag.co.uk/numeric/MB/start.asp">NAG Toolbox for MATLAB</a> for which we have an unlimited number of licenses.  Here&#8217;s how to replace <strong>ranksum</strong> with the NAG routine <strong>g08ah</strong>.</p>
<p><strong>Original MATLAB / Statistics Toolbox code</strong></p>
<pre>x = [0.8147;0.9058;0.1270;0.9134;0.6324;0.0975;0.2785;0.5469;0.9575;0.9649];
y=  [0.4076;1.220;1.207;0.735;1.0502;0.3918;0.671;1.165;1.0422;1.2094;0.9057;0.285;1.099;1.18;0.928];
p = ranksum(x,y)</pre>
<p>The result is p = 0.0375</p>
<p><strong>Code using the NAG Toolbox for MATLAB</strong></p>
<pre>x = [0.8147;0.9058;0.1270;0.9134;0.6324;0.0975;0.2785;0.5469;0.9575;0.9649];
y =  [0.4076;1.220;1.207;0.735;1.0502;0.3918;0.671;1.165;1.0422;1.2094;0.9057;0.285;1.099;1.18;0.928];
tail = 'T';
[u, unor, p, ties, ranks, ifail] = g08ah(x, y, tail);</pre>
<p>The value for p is the same as that calculated by <strong>ranksum</strong>: p = 0.0375</p>
<p>NAG&#8217;s <a href="www.nag.co.uk/numeric/MB/manual_22_1/pdf/G08/g08ah.pdf"><strong>g08ah</strong></a> routine returns a lot more than just the  value p but, for this particular example, we can just ignore it all.   In fact, if you have MATLAB 2009b or above then you could call <strong>g08ah</strong> like this</p>
<pre>tail = 'T';
[~, ~, p, ~, ~, ~] = g08ah(x, y, tail);</pre>
<p>Which explicitly indicates that you are not going to use any of the outputs other than p.</p>
<p>People at Manchester are using the NAG toolbox for MATLAB more and more; not only because we have a full site license for it but because it can sometimes be <strong>very fast</strong>.  Here&#8217;s some more articles on the NAG toolbox you may find useful.</p>
<ul>
<li><a href="http://www.walkingrandomly.com/?p=1552">A faster version of MATLAB’s interp1</a></li>
<li><a href="http://www.walkingrandomly.com/?p=2351">An alternative to binopdf using the NAG toolbox for MATLAB</a></li>
<li><a href="http://www.walkingrandomly.com/?p=1590">Mark 22 of the NAG toolbox for MATLAB released</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/5wEHDbSiQ5A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2782</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Parallel Random Numbers in MATLAB #1</title>
		<link>http://www.walkingrandomly.com/?p=2755</link>
		<comments>http://www.walkingrandomly.com/?p=2755#comments</comments>
		<pubDate>Tue, 13 Jul 2010 03:28:57 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[parallel programming]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2755</guid>
		<description><![CDATA[A bit of background to this post
I work in the IT department of the University of Manchester and we are currently developing a Condor Pool which is basically a method of linking together hundreds of desktop machines to produce a high-throughput computing resource.  A MATLAB user recently submitted some jobs to our pool and complained [...]]]></description>
			<content:encoded><![CDATA[<h2>A bit of background to this post</h2>
<p>I work in the IT department of the University of Manchester and we are currently developing a <a href="http://www.cs.wisc.edu/condor/">Condor Pool</a> which is basically a method of linking together hundreds of desktop machines to produce a <a href="http://en.wikipedia.org/wiki/High-throughput_computing">high-throughput computing</a> resource.  A MATLAB user recently submitted some jobs to our pool and complained that all of them gave identical results which is stupid because his code used MATLAB&#8217;s rand command to mix things up a bit.</p>
<p>I was asked if I knew why this should happen to which I replied &#8216;yes.&#8217;  I was then asked to advise the user how to fix the problem and I did so.  The next request was for me to write some recommendations and tutorials on how users should use random numbers in MATLAB (and Mathematica and possibly Python while I was at it) along with our Condor Pool and I went uncharacteristically quiet for a while.</p>
<p>It turned out that I had a lot to learn about random numbers.  This is the first of a series of (probably 2) posts that will start off by telling you what I knew and move on to what I have learned.  It&#8217;s as much a vehicle for getting the concepts straight in my head as it is a tutorial.</p>
<h2>Ask MATLAB for 10 Random Numbers</h2>
<p>Before we go on, I&#8217;d like you to try something for me. You have to start on a system that doesn&#8217;t have MATLAB running at all so if MATLAB is running then close it before proceeding. Now, open up MATLAB and before you do anything else issue the following command</p>
<pre>rand(10,1)</pre>
<p>As many of you will know, the rand command produces random numbers from the <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29">uniform distribution</a> between 0 and 1 and the command above is asking for 10 such numbers. You may reasonably expect that the 10 random numbers that you get will be different from the 10 random numbers that I get; after all, they are random right? Well, I got the following numbers when running the above command on MATLAB 2009b running on Linux.</p>
<pre>ans =
0.8147
0.9058
0.1270
0.9134
0.6324
0.0975
0.2785
0.5469
0.9575
0.9649</pre>
<p>Look familiar?</p>
<p>Now I&#8217;ve done this experiment with a number of people over the last few weeks and the responses can be roughly split into two different camps as follows:</p>
<p>1.  Oh yeah, I know all about that &#8211; nothing to worry about.  It&#8217;s pretty obvious why it happens isn&#8217;t it?<br />
2.  It&#8217;s a bug.  How can the numbers be random if MATLAB always returns the same set?</p>
<h2>What does random mean anyway?</h2>
<p>If you are new to the computer generation of random numbers then there is something that you need to understand and that is that, strictly speaking, these numbers (like all software generated &#8216;random&#8217; numbers) are not &#8216;truly&#8217; random.  Instead they are <a href="http://en.wikipedia.org/wiki/Pseudorandom_number_generator">pseudorandom</a> &#8211; my personal working definition of which is &#8220;A sequence of numbers generated by some deterministic algorithm in such a way that they have the same statistical properties of &#8216;true&#8217; random numbers&#8221;.  In other words, they are not random they just appear to be but the appearance is good enough most of the time.</p>
<p>Pseudorandom numbers are generated from deterministic algorithms with names like <a href="http://en.wikipedia.org/wiki/Mersenne_twister">Mersenne Twister</a>, L&#8217;Ecuyer&#8217;s mrg32k3a [1]  and <a href="http://en.wikipedia.org/wiki/Blum_Blum_Shub">Blum Blum Schub</a> whereas &#8216;true&#8217; random numbers come from physical processes such as radioactive decay or atmospheric noise (the website <a href="http://www.random.org/">www.random.org</a> uses atmospheric noise for example).</p>
<p>For many applications, the distinction between &#8216;truly random&#8217; and &#8216;pseudorandom&#8217; doesn&#8217;t really matter since pseudorandom numbers are &#8216;random enough&#8217; for most purposes.  What does &#8216;random enough&#8217; mean you might ask?  Well as far as I am concerned it means that the random number generator in question has passed a set of well defined tests for randomness &#8211; something like <a href="http://www.stat.fsu.edu/pub/diehard/">Marsaglia&#8217;s Diehard tests</a> or, better still, <a href="http://www.iro.umontreal.ca/~simardr/testu01/tu01.html">L&#8217;Ecuyer and Simard&#8217;s TestU01 suite</a> will do nicely for example.</p>
<p>The generation of random numbers is a complicated topic and I don&#8217;t know enough about it to do it real justice but I know a man who does.  So, if you want to know more about the theory behind random numbers then I suggest that you read <a href="http://www.iro.umontreal.ca/~lecuyer/myftp/papers/ensbs.pdf">Pierre L&#8217;Ecuyer&#8217;s paper simply called &#8216;Random Numbers&#8217;</a> (pdf file).</p>
<p>Back to MATLAB&#8230;</p>
<h2>Always the same seed</h2>
<p>So, which of my two groups are correct?  Is there a bug in MATLAB&#8217;s random number generator or not?</p>
<p><strong>There is nothing wrong with MATLAB&#8217;s random number generator at all</strong>. The reason why the command <strong>rand(10,1)</strong> will always return the same 10 numbers <strong>if executed on startup</strong> is because MATLAB always uses the same <a href="http://en.wikipedia.org/wiki/Random_seed">seed</a> for its pseudorandom number generator (which at the time of writing is a Mersenne Twister) unless you tell it to do otherwise.</p>
<p>Without going into details, a seed is (usually) an integer that determines the internal state of a random number generator.  So, if you initialize a random number generator with the same seed then you&#8217;ll always get the same sequence of numbers and that&#8217;s what we are seeing in the example above.</p>
<p>Sometimes, this behaviour isn&#8217;t what we want.  For example, say I am doing a <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo</a> simulation and I want to run it several times to verify my results.  I&#8217;m going to want a different sequence of random numbers each time or the whole exercise is going to be pointless.</p>
<p>One way to do this is to initialize the random number generator with a different seed at startup and a common way of achieving this is via the system clock.  The following comes straight out of the current MATLAB documentation for example</p>
<pre>RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock)));</pre>
<p>Do this once per MATLAB session and you should be good to go (there is usually no point in doing it more than once per session by the way&#8230;.your numbers won&#8217;t be any &#8216;more random&#8217; if you so.  In fact, there is a chance that they will become less so!).</p>
<h2>Condor and &#8216;random&#8217; random seeds</h2>
<p>Sometimes the system clock approach isn&#8217;t good enough either.  For example, at my workplace, Manchester University, we have a <a href="http://www.cs.wisc.edu/condor/">Condor Pool</a> of hundreds of desktop machines which is perfect for people doing Monte Carlo simulations.  Say a single simulation takes 5 hours and it needs to be run 100 times in order to get good results.  On one machine that&#8217;s going to take about 3 weeks but on our Condor Pool it can take just 5 hours since all 100 simulations run at the same time but on different machines.</p>
<p>If you don&#8217;t think about random seeding at all then you end up with 100 identical sets of results using MATLAB on Condor for the reasons I&#8217;ve explained above.  Of course you know all about this so you switch to using the clock seeding method, try again and&#8230;.get 100 identical sets of results[2].</p>
<p>The reason for this is that the time on all 100 machines is synchronized using internet time servers.  So, when you start up 100 simultaneous jobs they&#8217;ll all have the same timestamp and, therefore, have the same random seed.</p>
<p>It seems that what we need to do is to guarantee (as far as possible) that every single one of our condor jobs gets a <strong>unique</strong> seed in order to provide a unique random number stream and one way to do this would be to incorporate the condor process ID into the seed generation in some way and there are many ways one could do this.  Here, however, I&#8217;m going to take a different route.</p>
<p>On Linux machines it is possible to obtain <strong>small numbers </strong>of random numbers using the special files <strong>/dev/random </strong>and <strong>/dev/urandom</strong> which are interfaces to the kernel&#8217;s random number generator.  According to the documentation &#8216;T<em>he random number generator gathers environmental noise  from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the  number of bit of the noise in the entropy pool.  From this entropy pool random numbers are created.&#8217; </em></p>
<p>This kernel generator isn&#8217;t suitable for simulation purposes but it will do just fine for generating an initial seed for MATLAB&#8217;s pseudorandom number generator.  Here&#8217;s the MATLAB commands</p>
<pre>[status seed] = system('od /dev/urandom --read-bytes=4 -tu | awk ''{print $2}''')
seed=str2double(seed)
RandStream.setDefaultStream(RandStream('mt19937ar','seed',seed));</pre>
<p>Put this at the beginning of the MATLAB script that defines your condor job and you should be good to go.  Don&#8217;t do it more than once per MATLAB session though &#8211; you won&#8217;t gain anything!</p>
<h3>The end or the end of the beginning?</h3>
<p>If you asked me the question <strong>&#8216;How do I generate a random seed for a pseudorandom number generator?&#8217;</strong> then I think that the above solution answers it quite well.  If, however, you asked me &#8216;<strong>What is the best way to generate multiple independent random number streams that would be good for thousands of monte-carlo simulations?</strong>&#8216; then we need to rethink somewhat for the following reasons.</p>
<p><strong>Seed collisions: </strong>The Mersenne twister algorithm currently used as the default random number generator for MATLAB uses a 32bit integer seed which means that it can take on 2^32 or 4,294,967,296 different values &#8211; which seems a lot!  However, by considering a generalisation of the <a href="http://en.wikipedia.org/wiki/Birthday_problem">birthday problem</a> it can be seen that if you select such a seed at random then you have a 50% chance choosing two identical seeds after only 65,536 runs.  In other words, if you perform 65,536 simulations then there is a 50% chance that two such simulations will produce identical results.</p>
<p><strong>Bad seeds: </strong>I have read about (but never experienced) the possibility of &#8216;bad seeds&#8217;; that is some seeds that produce some very strange, non-random results &#8211; for the first few thousand iterates at least.  This has led to some people advising that you should &#8216;warm-up&#8217; your random number generator by asking for, and throwing away, a few thousand random numbers before you start using them. <strong>Does anyone know of any such bad seeds?</strong></p>
<p><strong>Overlapping or correlated sequences:</strong> All pseudorandom number generators are periodic (at least, all the ones that I know about are) &#8211; which means that after N iterations the sequence repeats itself.  If your generator is good then N is usually large enough that you don&#8217;t need to worry about this.  The Mersenne Twister used in MATLAB, for instance, has a <strong>huge</strong> period of (2^19937 &#8211; 1)/2 (half of the standard 32bit implementation).</p>
<p>The point I want to make is that you don&#8217;t get several different streams of random numbers, you get <strong>just one</strong>, albeit a very big one.  Now, when you choose a seed you are essentially <strong>choosing a random point in this stream</strong> and <strong>there is no guarantee</strong> how far apart these two points are.  They could be separated by a distance of trillions of points or they could be right next to each other &#8211; we simply do not know &#8211; and this leads to the possibility of overlapping sequences.</p>
<p>Now, one could argue that the possibility of overlap is very small in a generator such as the Mersenne Twister and I do not know of any situation where it has occurred in practice but that doesn&#8217;t mean that we shouldn&#8217;t worry about it.  If your work is based on the assumption that all of your simulations have used independent, uncorrelated random number streams then there is a possibility that your assumptions could be wrong which means that your conclusions could be wrong.  Unlikely maybe, but still no way to do science.</p>
<h3>Next Time</h3>
<p>Next time I&#8217;ll be looking at methods for generating guaranteed independent random number streams using MATLAB&#8217;s in-built functions as well as methods taken from the <a href="http://www.nag.co.uk/numeric/MB/start.asp">NAG Toolbox for MATLAB</a>.  I&#8217;ll also be including explicit examples that use this stuff in Condor.</p>
<h3>Ask the audience</h3>
<p>I assume that some of you will be in the business of performing Monte-Carlo simulations and so you&#8217;ll probably know much more about all of this than me.  I have some questions</p>
<ul>
<li>Has anyone come across any &#8216;bad seeds&#8217; when dealing with MATLAB&#8217;s Mersenne Twister implementation?</li>
<li>Has anyone come across overlapping sequences when using MATLAB&#8217;s Mersenne Twister implementation?</li>
<li>How do YOU set up your random number generator(s).</li>
</ul>
<p>I&#8217;m going to change my comment policy for this particular post in that I am not going to allow (most) anonymous comments.  This means that you will have to give me your email address (which, of course, I will not publish) which I will use <strong>once </strong>to verify that it really was you that sent the comment.</p>
<h3>Notes and References</h3>
<p>[1] L&#8217;Ecuyer P (1999) Good parameter sets for combined multiple  recursive random number generators <em>Operations Research</em> <strong>47:1</strong> 159–164</p>
<p>[2] More usually you&#8217;ll get several different groups of results.  For example you might get 3 sets of results, A B C, and get 30 sets of A, 50 sets of B and 20 sets of C.  This is due to the fact that all 100 jobs won&#8217;t hit the pool at precisely the same instant.</p>
<p>[3] Much of this stuff has already been discussed by The Mathworks and there is an excellent set of articles over at Loren Shure&#8217;s blog &#8211; Loren onThe Art of MATLAB.</p>
<ul>
<li><a href="http://blogs.mathworks.com/loren/2008/11/05/new-ways-with-random-numbers-part-i/">New ways with random numbers, Part 1</a></li>
<li><a href="http://blogs.mathworks.com/loren/2008/11/13/new-ways-with-random-numbers-part-ii/">New ways with random numbers, Part 2</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/hM7xfRlRpSQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2755</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Installing Gaussian 03 on Ubuntu 9.10</title>
		<link>http://www.walkingrandomly.com/?p=2761</link>
		<comments>http://www.walkingrandomly.com/?p=2761#comments</comments>
		<pubDate>Wed, 07 Jul 2010 15:15:11 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Chemistry]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2761</guid>
		<description><![CDATA[I was recently asked to install 32bit Gaussian 03 binaries on an Ubuntu 9.10 machine and when I tried to run a test job I got the following error message
Erroneous write during file extend. write -1 instead of 4096
Probably out of disk space.
Erroneous write during file extend. write -1 instead of 4096
Probably out of disk [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently asked to install 32bit Gaussian 03 binaries on an Ubuntu 9.10 machine and when I tried to run a test job I got the following error message</p>
<pre>Erroneous write during file extend. write -1 instead of 4096
Probably out of disk space.
Erroneous write during file extend. write -1 instead of 4096
Probably out of disk space.
Write error in NtrExt1
Write error in NtrExt1: Bad address
Segmentation fault
</pre>
<p>A bit of googling suggested that the following might work</p>
<pre>sudo echo 0 &gt; /proc/sys/kernel/randomize_va_space
</pre>
<p>but this will result in permission denied (<a href="http://superuser.com/questions/127238/how-to-turn-off-aslr-in-ubuntu-9-10">explanation here</a>).  The command you really want to use is</p>
<pre>sudo bash -c "echo 0 &gt; /proc/sys/kernel/randomize_va_space"
</pre>
<p>Once this was done, Gaussian worked as advertised.  Maybe this post will help a googler sometime in the future.</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/npicquZvhuQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2761</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A free version of the pdist command for MATLAB</title>
		<link>http://www.walkingrandomly.com/?p=2678</link>
		<comments>http://www.walkingrandomly.com/?p=2678#comments</comments>
		<pubDate>Sat, 26 Jun 2010 09:07:42 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[math software]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2678</guid>
		<description><![CDATA[MATLAB contains a function called pdist that calculates the &#8216;Pairwise distance between pairs of objects&#8217;.  Typical usage is
X=rand(10,2);
dists=pdist(X,'euclidean');

It&#8217;s a nice function but the problem with it is that it is part of the Statistics Toolbox and that costs extra.  I was recently approached by a user who needed access to the pdist function [...]]]></description>
			<content:encoded><![CDATA[<p>MATLAB contains a function called <a href="http://www.mathworks.de/access/helpdesk/help/toolbox/stats/pdist.html">pdist</a> that calculates the &#8216;Pairwise distance between pairs of objects&#8217;.  Typical usage is</p>
<pre>X=rand(10,2);
dists=pdist(X,'euclidean');
</pre>
<p>It&#8217;s a nice function but the problem with it is that it is part of the <a href="http://www.mathworks.com/products/statistics/">Statistics Toolbox</a> and that costs extra.  I was recently approached by a user who needed access to the pdist function but all of the statistics toolbox license tokens on our network were in use and this led to the error message</p>
<pre>??? License checkout failed.
License Manager Error -4
Maximum number of users for Statistics_Toolbox reached.
Try again later.
To see a list of current users use the lmstat utility or contact your License Administrator</pre>
<p>One option, of course, is to buy more licenses for the statistics toolbox but there is another way.  You may have heard of <a href="http://www.gnu.org/software/octave/">GNU Octave</a>, a free,open-source MATLAB-like program that has been in development for many years.  Well, Octave has a sister project called <a href="http://octave.sourceforge.net/">Octave-Forge</a> which aims to provide a set of free toolboxes for Octave.  It turns out that not only does Octave-forge contain a statistics toolbox but that toolbox contains an pdist function.  I wondered how hard it would be to take Octave-forge&#8217;s pdist function and modify it so that it ran on MATLAB.</p>
<p>Not very!  There is a script called <a href="http://octave.sourceforge.net/oct2mat/index.html">oct2mat</a> that is designed to automate some of the translation but I chose not to use it &#8211; I prefer to get my hands dirty you see.  I named the resulting function octave_pdist to help clearly identify the fact that you are using an Octave function rather than a  MATLAB function.  This may matter if one or the other turns out to have bugs.  It appears to work rather nicely:</p>
<pre>dists_oct = octave_pdist(X,'euclidean');
% let's see if it agrees with the stats toolbox version
all( abs(dists_oct-dists)&lt;1e-10)

ans =
     1
</pre>
<p>Let&#8217;s look at timings on a slightly bigger problem.</p>
<pre>&gt;&gt; X=rand(1000,2);
&gt;&gt; tic;matdists=pdist(X,'euclidean');toc
Elapsed time is 0.018972 seconds.
&gt;&gt; tic;octdists=octave_pdist(X,'euclidean');toc
Elapsed time is 6.644317 seconds.
</pre>
<p>Uh-oh!  The Octave version is 350 times slower (for this problem) than the MATLAB version.  Ouch!   As far as I can tell, this isn&#8217;t down to my dodgy porting efforts, the original Octave pdist really does take that long on my machine (Ubuntu 9.10, Octave 3.0.5).</p>
<p>This was far too slow to be of practical use and we didn&#8217;t want to be modifying algorithms so we ditched this function and went with the <a href="http://www.nag.co.uk/numeric/MB/start.asp">NAG Toolbox for MATLAB</a> instead (<a href="http://www.nag.co.uk/numeric/MB/manual_22_1/pdf/G03/g03ea.pdf">routine g03ea</a> in case you are interested) since Manchester effectively has an infinite number of licenses for that product.</p>
<p>If,however, you&#8217;d like to play with my MATLAB port of Octave&#8217;s pdist then download it below.</p>
<ul>
<li> <a href="http://www.walkingrandomly.com/images/downloads/octave_pdist.m">octave_pdist.m</a> makes use of some functions in the excellent <a href="http://biosig-consulting.com/matlab/NaN/">NaN Toolbox</a> so you will need to download and install that package first.</li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/m_ZcaNErLIQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2678</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MATLAB says “Hi”</title>
		<link>http://www.walkingrandomly.com/?p=2720</link>
		<comments>http://www.walkingrandomly.com/?p=2720#comments</comments>
		<pubDate>Thu, 17 Jun 2010 16:39:35 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[general math]]></category>
		<category><![CDATA[math software]]></category>
		<category><![CDATA[mathematica]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2720</guid>
		<description><![CDATA[One of the earliest posts I made on Walking Randomly (almost 3 years ago now &#8211; how time flies!) described the following equation and gave a plot of it in Mathematica.


Some time later I followed this up with another blog post and a Wolfram Demonstration.
Well, over at Stack Overflow, some people have been rendering this [...]]]></description>
			<content:encoded><![CDATA[<p>One of the <a href="http://www.walkingrandomly.com/?p=19">earliest posts</a> I made on Walking Randomly (almost 3 years ago now &#8211; how time flies!) described the following equation and gave a plot of it in Mathematica.</p>
<p><img src='http://www.walkingrandomly.com/latexrender/pictures/a5497a0464960f55ceddc8575d2efaba.gif' title='\light f(x,y)=e^{-x^2-\frac{y^2}{2}} \cos (4 x)+e^{-3\left((x+0.5)^2+\frac{y^2}{2}\right)} ' alt='\light f(x,y)=e^{-x^2-\frac{y^2}{2}} \cos (4 x)+e^{-3\left((x+0.5)^2+\frac{y^2}{2}\right)} ' align=absmiddle></p>
<p><img src="http://www.walkingrandomly.com/images/mathematica/hi.jpg" alt="" width="360" height="269" align="middle" /></p>
<p>Some time later I followed this up with<a href="http://www.walkingrandomly.com/?p=64"> another blog post and a Wolfram Demonstration</a>.</p>
<p>Well, <a href="http://stackoverflow.com/questions/3020220/plotting-hi-in-matlab">over at Stack Overflow,</a> some people have been rendering this cool equation using MATLAB. Here&#8217;s the first version</p>
<pre>x = linspace(-3,3,50);
y = linspace(-5,5,50);
[X Y]=meshgrid(x,y);
Z = exp(-X.^2-Y.^2/2).*cos(4*X) + exp(-3*((X+0.5).^2+Y.^2/2));
Z(Z&gt;0.001)=0.001;
Z(Z&lt;-0.001)=-0.001;
surf(X,Y,Z);
colormap(flipud(cool))
view([1 -1.5 2])</pre>
<p><img src="http://www.walkingrandomly.com/images/matlab/hi1_matlab.png" alt="" align="middle" /></p>
<p>and here&#8217;s the second.</p>
<pre>[x y] = meshgrid( linspace(-3,3,50), linspace(-5,5,50) );
z = exp(-x.^2-0.5*y.^2).*cos(4*x) + exp(-3*((x+0.5).^2+0.5*y.^2));
idx = ( abs(z)&gt;0.001 );
z(idx) = 0.001 * sign(z(idx)); 

figure('renderer','opengl')
patch(surf2patch(surf(x,y,z)), 'FaceColor','interp');
set(gca, 'Box','on', ...
    'XColor',[.3 .3 .3], 'YColor',[.3 .3 .3], 'ZColor',[.3 .3 .3], 'FontSize',8)
title('$e^{-x^2 - \frac{y^2}{2}}\cos(4x) + e^{-3((x+0.5)^2+\frac{y^2}{2})}$', ...
    'Interpreter','latex', 'FontSize',12) 

view(35,65)
colormap( [flipud(cool);cool] )
camlight headlight, lighting phong</pre>
<p><img src="http://www.walkingrandomly.com/images/matlab/hi2_matlab.jpg" alt="" align="middle" /></p>
<p>Do you have any cool graphs to share?</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/PQbQTb_TD7w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2720</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Math on iPad #1</title>
		<link>http://www.walkingrandomly.com/?p=2692</link>
		<comments>http://www.walkingrandomly.com/?p=2692#comments</comments>
		<pubDate>Fri, 11 Jun 2010 10:08:46 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[math software]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2692</guid>
		<description><![CDATA[Apple&#8217;s iPad hasn&#8217;t been available for very long but there is already a wealth of mathematical apps available for it and I expect the current crop to only be the tip of the iceberg.  So, this is the beginning of a new series of articles on Walking Randomly where I&#8217;ll explore the options for [...]]]></description>
			<content:encoded><![CDATA[<p>Apple&#8217;s iPad hasn&#8217;t been available for very long but there is already a wealth of mathematical apps available for it and I expect the current crop to only be the tip of the iceberg.  So, this is the beginning of a new series of articles on Walking Randomly where I&#8217;ll explore the options for doing mathematics on this new platform.</p>
<h3>SpaceTime Mathematics</h3>
<p style="text-align: left;"><img class="aligncenter" src="http://www.walkingrandomly.com/images/ipad/spacetime.jpg" alt="Spacetime" /><br />
The Rolls Royce of mobile mathematical applications and one that I have been using since my days as a <a href="http://www.walkingrandomly.com/?p=14">Windows Mobile user</a>.  The iPad version was one of the first apps I bought when I received my device and it is just beautiful!  Symbolic algebra and calculus, 2 and 3D interactive plotting, scripting, fractals linear algebra&#8230;the list of functions just goes on and on.  I would have loved to have access to this app when I was in high school or early university.</p>
<p>If you want to get an idea of the quality of SpaceTime&#8217;s graphical capabilities then check out the free demo, <a href="http://itunes.apple.com/us/app/graphbook/id348741481?mt=8">Graphbook</a>, but be aware that there is a lot more to SpaceTime than just graphics.</p>
<p>Regular readers of Walking Randomly will know that I am a big fan of <a href="http://demonstrations.wolfram.com/">Wolfram&#8217;s Demonstration project</a> which is made possible by Mathematica&#8217;s Manipulate function.  Well, SpaceTime has a similar, albeit simplified, version of Manipulate &#8211; a function called <a href="http://www.spacetime.us/manual/Scroll">Scroll</a>.  Interactive Fourier Series on the iPad anyone?</p>
<p>Something else that I like about SpaceTime is the fact that it is cross-platform with versions for Linux and Windows available in addition to iPhone, iPad and Windows Mobile.  So, students could use it in a classroom setting on PCs and use what they have learned on their own iPad/iPhone version.</p>
<p>If you only buy one mathematical application for iPad then this should be it.  It&#8217;s relatively expensive for an iPad app at £11.99 (at the time of writing) but is worth every penny and I bought it without hesitation &#8211; so should you!</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/spacetime-scientific-computing/id293619493?mt=8">SpaceTime iTunes Link</a></li>
<li><a href="http://www.spacetime.us/">Main website for SpaceTime</a></li>
</ul>
<h3>PocketCAS Pro</h3>
<p style="text-align: left;"><img class="aligncenter" src="http://www.walkingrandomly.com/images/ipad/pocketcaspro.png" alt="PocketCAS pro" /><br />
PocketCAS Pro is a computer algebra system that started out life as a Windows Mobile app and is now available for iPhone and iPad.  I haven&#8217;t had chance to try it out yet so I can&#8217;t comment on its quality but it has a lot of features including symbolic algebra and calculus, 2D plotting, numerical solution of equations and more.</p>
<p>At the time of writing, it is the same price as SpaceTime mathematics &#8211; £11.99 &#8211; and yet my first impression is that it has less functionality.   No 3d plotting for example.  I&#8217;ll know more when I buy a copy next month.</p>
<p>There is a free lite version available which includes some of the functionality of the main product to allow you to try it out.</p>
<ul>
<li><a href="http://itunes.apple.com/us/app/graphic-symbolic-scientific/id333261115?mt=8">PocketCAS Pro on iTunes</a>.</li>
<li><a href="http://itunes.apple.com/us/app/free-graphic-calculator-pocketcas/id333261649?mt=8">PocketCAS lite</a> &#8211; free, cut down version of PocketCAS Pro</li>
<li><a href="http://pocketcas.com/iphone/">PocketCAS main website</a></li>
</ul>
<h3>fxIntegrator</h3>
<p style="text-align: left;"><img class="aligncenter" src="http://www.walkingrandomly.com/images/ipad/fxintegrator.png" alt="fxIntegrator" /><br />
My favourite operating system is Linux where there is a philosophy of &#8220;Write programs that do one thing and do it well&#8221;.  fxIntegrator does one thing -the numerical solution of 1d integrals &#8211; but does it do it well?</p>
<p>Well, it&#8217;s not bad.  You enter the function you want to integrate using the nice, specially designed keyboard, then you enter the limits and press the = button to get the result.  Couldn&#8217;t get any easier and I like it.  The equation editor is very nice resulting in well formatted integrands but I did manage to confuse it once or twice.  FxIntegrator is also very cheap at only 59p &#8211; a real bargain!</p>
<p>I tried a few straightforward integrals on it and it gave the correct answer in all cases.  Then I got nasty and tried the following which has an algebraic-logarithmic singularity at the origin (<a href="http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html"></a><a href="http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html">original source for this integral</a>).</p>
<p style="text-align: center;"><img src='http://www.walkingrandomly.com/latexrender/pictures/0fe03b66998556de3b77947ad3a964a1.gif' title='\int_0^1 x^{-1/2} \ln(x) dx = -4' alt='\int_0^1 x^{-1/2} \ln(x) dx = -4' align=absmiddle></p>
<p>I wasn&#8217;t expecting fxIntegrator to cope and it didn&#8217;t.  Rather than giving the answer I just got an unhappy face indicating that it couldn&#8217;t compute the solution.  This isn&#8217;t a criticism though! I like the fact that rather than giving numerical garbage, fxIntegator simply said &#8216;I can&#8217;t do that&#8217;.</p>
<p>There are some niggles, however.  First of all, the list of elementary functions available is rather limited as it only includes square roots, powers,the trigonometric functions <strong>sin</strong>,<strong>cos</strong> and <strong>tan</strong>, the natural logarithm function <strong>ln</strong> and basic arithmetic.  Even when I was in high school I would have wanted more such as inverse trig functions.</p>
<p>Another problem with it is that although you can use the customised keyboard to enter the integrand, when you try to enter limits the standard iPad keyboard pops up.</p>
<p>These niggles aside, however, this is a nice little app for 59p and I hope the author continues to develop it.  If he does then here are some suggestions for functionality I&#8217;d like to see.</p>
<ul>
<li>Add a few more functions.  Inverse trig for a start.  If possible then maybe things such as Bessel functions.</li>
<li>Help turn this into a better teaching and learning tool by implementing a range of numerical methods for computing the integrand and allow the user to choose between them.  Methods such as the rectangle rule, trapezoidal rule and simpson&#8217;s rule along with the ability to change the sub-divison size.  The more methods the better <img src='http://www.walkingrandomly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Perhaps add some tutorial notes on each numerical method.</li>
<li>Give the calculation time for the result in seconds along with the number of evaluations of the integrand.  This will help students compare the trade off in speed/accuracy of each method.</li>
<li>Add the ability to plot the integrand along with the limits.  Allow the user to change limits by moving them on the graph as well as by direct input.  Once the calculation is performed, show the points on the curve where the algorithm sampled the function.</li>
</ul>
<p>This good little app could be turned into a great little app.</p>
<ul>
<li><a href="http://itunes.apple.com/app/fxintegrator/id375694881?mt=8">iTunes page for fxIntegrator</a></li>
<li><a href="http://sites.google.com/site/chir21/home/">Main wesbite for fxIntegrator</a></li>
</ul>
<h3>More articles from Walking Randomly on mobile Mathematics</h3>
<ul>
<li><a href="http://www.walkingrandomly.com/?p=1212">PocketCAS &#8211; a new computer algebra system for iPhone</a></li>
<li><a href="http://www.walkingrandomly.com/?p=1633">Detexify answers ‘What’s the LaTeX code for this symbol?’</a></li>
<li><a href="http://www.walkingrandomly.com/?p=28">Review of Gnuplot 4.2 for Windows Mobile</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/vOojpiPno90" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2692</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Supercomputers Vs Mobile Phones</title>
		<link>http://www.walkingrandomly.com/?p=2684</link>
		<comments>http://www.walkingrandomly.com/?p=2684#comments</comments>
		<pubDate>Wed, 02 Jun 2010 18:51:19 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2684</guid>
		<description><![CDATA[Ever wondered how fast the fastest computer on Earth is?  Well wonder no more because the latest edition of the Top 500 supercomputers was published earlier this week.  Thanks to this list we can see that the fastest (publicly announced) computer in the world is currently an American system called Jaguar.  Jaguar [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how fast the fastest computer on Earth is?  Well wonder no more because the <a href="http://www.top500.org/lists/2010/06">latest edition of the Top 500</a> supercomputers was published earlier this week.  Thanks to this list we can see that the fastest (publicly announced) computer in the world is currently an <a href="http://www.ornl.gov/info/press_releases/get_press_release.cfm?ReleaseNumber=mr20091116-02">American system called Jaguar</a>.  Jaguar currently consists of 37,376 <a href="http://techreport.com/articles.x/17005">six-core AMD Istanbul</a> processors and has a speed of 1.75 petaflops as measured by the<a href="http://en.wikipedia.org/wiki/LINPACK"> Linpack</a> benchmarks. <a href="http://news.bbc.co.uk/1/hi/technology/10181725.stm"> According to the BBC</a>, a computation that takes Jaguar a day would keep a standard desktop PC busy for 100 years.  Whichever way you look at it, Jaguar is a seriously quick piece of kit.</p>
<p>All this got me thinking&#8230;.how fast is my mobile phone compared to these computational behemoths?</p>
<p>The key to answering this question lies with the Linpack benchmarks developed by Jack Dongarra back in 1979.  Wikipedia explains:</p>
<p><em>&#8216;they [The Linpack benchmarks] measure how fast a computer solves a dense N by N system of linear equations Ax = b, which is a common task in engineering. The solution is obtained by Gaussian elimination with partial pivoting, with 2/3·N3 + 2·N2 floating point operations. The result is reported in millions of floating point operations per second (MFLOP/s).&#8217;</em></p>
<p>People have been using the Linpack benchmarks to measure the speed of computers for decades and so we can use the historical results to see just how far computers have come over the last thirty years or so.  Back in 1979, for example, the fastest computer on the block according to the N=100 Linpack benchmark was the Cray 1 supercomputer which had a<a href="http://www.netlib.org/utk/people/JackDongarra/faq-linpack.html#_Toc27885750"> measured speed of 3.4 Mflop/s</a> per processor.</p>
<p>More recently, a <a href="http://www.netlib.org/benchmark/linpackjava/">Java version of the Linpack benchmark</a> was developed and this was used by <a href="http://www.greenecomputing.com/">GreeneComputing</a> to produce an <a href="http://www.greenecomputing.com/apps/linpack/">Android version of the benchmark</a>.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.walkingrandomly.com/images/random/android_linpack.jpg" alt="Linpack for Android" /></p>
<p>I installed the benchmark onto my trusty T-Mobile G2 (a rebadged HTC Hero, currently running Android 1.5) and on firing it up discovered that it tops out at around 2.3 Mflop/s which makes it around 66% as fast as a single processor on a 1979 Cray 1 supercomputer.  OK, so maybe that&#8217;s not particularly impressive but the very latest crop of Android phones are a different matter entirely.</p>
<p>According to the current <a href="http://www.greenecomputing.com/apps/linpack/linpack-top-10/">Top 10 Android Linpack results</a>, a tweaked Motorola Droid is capable of scoring 52 Mflop/s which is over 15 times faster than the 1979 Cray 1 CPU.  Put another way, if you transported that mobile phone back to 1987 then it would be on par with the processors in one of the fastest computers in the world of the time, the <a href="http://en.wikipedia.org/wiki/ETA10">ETA 10-E</a>, and they had to be cooled by liquid nitrogen.</p>
<p>Like all benchmarks, however, you need to take this one with a pinch of salt.  As explained on the<a href="http://www.netlib.org/benchmark/linpackjava/"> Java Linpack page</a> <em>&#8216;This [the Java version of the] test is more a reflection of the state of the Java systems than of the floating point performance of the underlying processors.&#8217; </em>In other words, the underlying processors of our mobile phones are probably faster than these Java based tests imply.</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/2B_IdHx6NSU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2684</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MATLAB Mobile brings MATLAB to the iPhone and iPad (sort of)</title>
		<link>http://www.walkingrandomly.com/?p=2674</link>
		<comments>http://www.walkingrandomly.com/?p=2674#comments</comments>
		<pubDate>Mon, 24 May 2010 08:34:27 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[math software]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2674</guid>
		<description><![CDATA[The Mathworks have released a new app for iPhone and iPad called MATLAB Mobile.  When I first saw the headlines I was very excited but the product is rather disappointing in my opinion since all it does is offer a mobile interface to an instance of MATLAB running on a desktop machine.  While this might [...]]]></description>
			<content:encoded><![CDATA[<p>The Mathworks have released a new app for iPhone and iPad called <a href="http://www.mathworks.com/mobile/">MATLAB Mobile</a>.  When I first saw the headlines I was very excited but the product is rather disappointing in my opinion since all it does is offer a mobile interface to an instance of MATLAB running on a desktop machine.  While this might be useful to some people I have to admit that it doesn&#8217;t light any fires for me.  I&#8217;ll save my excitement for a mobile MATLAB application that can actually do some mathematics locally.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.walkingrandomly.com/images/matlab/matlab_mobile.jpg" alt="MATLAB Mobile" /></p>
<p style="text-align: left;">How about you though?  Will this new application be useful for the way you work?</p>
<p style="text-align: left;"><strong>More articles from Walking Randomly on mobile mathematics software</strong></p>
<ul>
<li><a href="http://www.walkingrandomly.com/?p=2692">Mathematics on iPad #1</a></li>
<li><a href="http://www.walkingrandomly.com/?p=14">Mathematics on the Pocket PC</a></li>
<li><a href="http://www.walkingrandomly.com/?p=1212">PocketCAS &#8211; a new computeger algebra system for the iPhone</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/hU16HRey-Bk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2674</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>MATLAB Tutorial – Reading csv files</title>
		<link>http://www.walkingrandomly.com/?p=2654</link>
		<comments>http://www.walkingrandomly.com/?p=2654#comments</comments>
		<pubDate>Fri, 21 May 2010 13:09:25 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[matlab]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2654</guid>
		<description><![CDATA[Reading comma separated value (csv) files into MATLAB is trivial as long as the csv file you are trying to import is trivial. For example, say you wanted to import the file very_clean.txt which contains the following data
1031,-948,-76
507,635,-1148
-1031,948,750
-507,-635,114
The following, very simple command, is all that you need
&#62;&#62; veryclean = csvread('very_clean.txt')

veryclean =

     [...]]]></description>
			<content:encoded><![CDATA[<p>Reading <a href="http://en.wikipedia.org/wiki/Comma-separated_values">comma separated value</a> (csv) files into <a href="http://www.mathworks.com/">MATLAB</a> is trivial as long as the csv file you are trying to import is trivial. For example, say you wanted to import the file <a href="http://www.walkingrandomly.com/images/matlab/csv/very_clean.txt">very_clean.txt </a>which contains the following data</p>
<pre>1031,-948,-76
507,635,-1148
-1031,948,750
-507,-635,114</pre>
<p>The following, very simple command, is all that you need</p>
<pre>&gt;&gt; veryclean = csvread('very_clean.txt')

veryclean =

        1031        -948         -76
         507         635       -1148
       -1031         948         750
        -507        -635         114</pre>
<p>In the real world, however, your data is rarely this nice and clean. One of the most common problems faced by MATLABing data importers is that of header lines. Take the file <a href="http://www.walkingrandomly.com/images/matlab/csv/quite_clean.txt">quite_clean.txt </a>for instance. This is identical to the previous example apart from the fact that it contains two header lines</p>
<pre>These are some data that I made using my hand-crafted code
Date:12th July 1996
1031,-948,-76
507,635,-1148
-1031,948,750
-507,-635,114</pre>
<p>This is all too much for the <strong>csvread</strong> command</p>
<pre>&gt;&gt; data=csvread('quite_clean.txt')
??? Error using ==&gt; dlmread at 145
Mismatch between file and format string.
Trouble reading number from file (row 1, field 1) ==&gt; This

Error in ==&gt; csvread at 52
    m=dlmread(filename, ',', r, c);</pre>
<p>Not to worry, we can just use the more capable <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/importdata.html">importdata</a> command instead</p>
<pre>&gt;&gt; quiteclean = importdata('quite_clean.txt')

quiteclean = 

        data: [4x3 double]
    textdata: {2x1 cell}</pre>
<p>The result above is a two element <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/struct.html">structure array</a> and our numerical values are contained in a field called data. Here&#8217;s how you get at it.</p>
<pre>&gt;&gt; quiteclean.data

ans =

        1031        -948         -76
         507         635       -1148
       -1031         948         750
        -507        -635         114</pre>
<p>So far so good. How do we handle a file like <a href="http://www.walkingrandomly.com/images/matlab/csv/messy_data.txt">messy_data.txt </a>though?</p>
<pre>header 1;
header 2;
1031,-948,-76, ,"12"
507,635,-1148, ,"34"
-1031,948,750, ,"45"
-507,-635,114, ,"67"</pre>
<p>This is the kind of file encountered by Walking Randomly reader<a href="http://www.walkingrandomly.com/?p=1502#comment-24690"> &#8216;reen&#8217;</a> and it contains exactly the same numerical values as the previous two examples. Unfortunately, it also contains some cruft that makes life more difficult for us. Let&#8217;s bring out the big-guns!</p>
<h3>Using textscan to import csv files in MATLAB</h3>
<p>When the going gets tough, the tough use <a href="http://www.mathworks.co.uk/access/helpdesk/help/techdoc/ref/textscan.html">textscan</a>.  Here&#8217;s the incantation for importing messy_data.txt</p>
<pre>fid=fopen('messy_data.txt');
data = textscan(fid,'%f %f %f %*s %*s','HeaderLines',2,'Delimiter',',','CollectOutput',1);
fclose(fid)</pre>
<p>The result is a one-element cell array that contains an array of doubles.  Let&#8217;s get the array of doubles out of the cell</p>
<pre>&gt;&gt; data=data{1}
data =
        1031        -948         -76
         507         635       -1148
       -1031         948         750
        -507        -635         114</pre>
<p>If the<strong> importdata</strong> command is a chauffeur then <strong>textscan</strong> is a Ferrari and I don&#8217;t know about you but I&#8217;d much rather be driving my own Ferrari than being chauffeured around (John Cook over at The Endeavour has <a href="http://www.johndcook.com/blog/2010/04/27/chauffers-and-ferraris-revisited/">more to say on Ferraris and Chauffeurs</a>).</p>
<p>Let&#8217;s de-construct the above set of commands.  The first thing to notice is that, unlike <strong>csvread</strong> and <strong>importdata</strong>, you have to explicitly open and close your file when using the<strong> textscan</strong> command.  So, you open your file using<strong> fopen</strong> and give it a file ID (which in this example is <strong>fid</strong>).</p>
<pre>fid=fopen('messy_data.txt');</pre>
<p>The first argument to textscan is just this file ID, fid. Next you need to supply a conversion specifier which in this case is</p>
<pre>'%f %f %f %*s %*s'</pre>
<p>The conversion specifier tells <strong>textscan</strong> what you want each row in your csv file to be converted to. <strong>%f</strong> means <em>&#8220;64 bit double&#8221; </em>and<strong> %s</strong> means <strong>&#8220;string&#8221;</strong> so <strong>&#8216;%f %f %f %s %s&#8217;</strong> means &#8220;3 doubles followed by 2 strings&#8221; (we&#8217;ll get onto the asterisks in the original specifier later). You can use all sorts of data types in a conversion specifier such as integers, quoted strings and pattern matched strings among others. Check out the MATLAB <a href="http://www.mathworks.co.uk/access/helpdesk/help/techdoc/ref/textscan.html">documentation for textscan</a> for the full list but an abbreviated list is shown below:</p>
<pre>%d signed 32bit integer
%u unsigned 32bit integer
%f 64bit double (you'll want this most of the time when using MATLAB)
%s string</pre>
<p>Now, in the command I used to import messy_data.txt the conversion specifier contained some asterisks such as <strong>%*s</strong> so what do these mean?  Quite simply, the asterisk just means <em>&#8216;ignore&#8217; </em>so <strong>%*s</strong> means <em>&#8216;ignore the string in this field&#8217;</em>.  So, the full meaning of my conversion specifier <strong>&#8216;%f %f %f %*s %*s&#8217;</strong> is <em>&#8220;read 3 doubles and ignore 2 strings&#8221; </em>and textscan will do this for every row.</p>
<p>The rest of the command is pretty self explanatory but I&#8217;ll explain it anyway for the sake of completeness</p>
<pre>'HeaderLines',2</pre>
<p>The file has 2 headerlines which should be ignored</p>
<pre>'Delimiter',','</pre>
<p>The fields are delimited (a posh word for separated) by a comma</p>
<pre>'CollectOutput',1</pre>
<p>If you supply a 1 (which stands for True) to the CollectOutput option then textscan will join consecutive output cells with the same data type into a single array. Since I want all of my doubles to be in a single array then this is the behaviour I went for.</p>
<p>Finally, once you have finished textscanning, don&#8217;t forget to close your file</p>
<pre>fclose(fid)</pre>
<p>That&#8217;s pretty much it for this mini-tutorial &#8211; I hope you find it useful.</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/2idXyXbrHA4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2654</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Maple 14 released</title>
		<link>http://www.walkingrandomly.com/?p=2646</link>
		<comments>http://www.walkingrandomly.com/?p=2646#comments</comments>
		<pubDate>Mon, 17 May 2010 04:10:02 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Maple]]></category>
		<category><![CDATA[math software]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2646</guid>
		<description><![CDATA[Version 14 of Maple was released a couple of weeks ago and it appears to have some very cool stuff in it.  Some of the highlights that stand out for me include

Accelerated linear algebra using graphics cards via NVIDIA&#8217;s CUDA.    Maple&#8217;s advertising blurb says that they have implemented matrix multiplication and that this will [...]]]></description>
			<content:encoded><![CDATA[<p>Version 14 of <a href="http://www.maplesoft.com/products/maple/">Maple</a> was released a couple of weeks ago and it appears to have some very cool stuff in it.  Some of the highlights that stand out for me include</p>
<ul>
<li>Accelerated linear algebra using graphics cards via <a href="http://www.nvidia.com/object/cuda_home_new.html">NVIDIA&#8217;s CUDA</a>.    Maple&#8217;s advertising blurb says that they have implemented matrix multiplication and that this will help speed up many linear algebra routines since this is such a fundamental operation.  I think that Maple are the first of the big general purpose mathematical packages to offer direct CUDA integration out of the box and this development is well worth watching.  The speed-ups that are possible from CUDA technology are nothing short of astonishing &#8211; hundreds of times in some cases.  However, Maplesoft are going to need to add a lot more than matrix multiplication in order for this to be truly useful.  A set of fast random number generators would be nice for example (I&#8217;m thinking superfast Monte-carlo simulations &#8211; the finance people would love it).</li>
<li>Maple uses <a href="http://software.intel.com/en-us/intel-mkl/">Intel&#8217;s Math Kernel Library</a> (MKL) for many of its low-level numerical linear algebra routines and this has been updated to version 10.0 in Maple 14.  For 32bit windows users this has sped certain operations up quite a lot but it is 64bit Windows users who will really see the benefit since 64bit Maple 13 only used a set of generic <a href="http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS routines</a>.  The practical upshot is that certain basic linear algebra routines, such as Matrix Multiplication, can be around <strong>10 times faster</strong> in 64bit windows Maple 14 compared to the previous version.  I couldn&#8217;t find mention of the Linux version.</li>
<li>A shed load of updates to their differential equation solvers including a new numerical routine called the <a href="http://en.wikipedia.org/wiki/Cash%E2%80%93Karp_method">Cash-Karp pair</a>.</li>
<li>The Maple toolbox for <a href="http://www.mathworks.com/">MATLAB</a> is no longer a separate product and is now included with Maple itself.  This is great news if you, like me, tend to work with several mathematical packages simultaneously.  Of course you need to have a copy of MATLAB installed to make use of this functionality &#8211; you don&#8217;t get a copy of MATLAB for free <img src='http://www.walkingrandomly.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>You can now import MATLAB binary files (compressed and uncompressed) directly into Maple using the ImportMatrix command.</li>
<li>Another product, The Maple-NAG connector, has also been integrated with Maple itself.  This allows you to easily call the <a href="http://www.nag.co.uk/numeric/cl/cldescription.asp">NAG C library</a> directly from Maple but, similar to the MATLAB toolbox, you&#8217;ll have to purchase the NAG C library separately to make use of this.</li>
</ul>
<p>As you can see, I tend to favour new features that lead to improved performance or better interoperability with other software packages in the first instance.  New mathematics and usability features take a little longer to sink in (for me at least).</p>
<p>I&#8217;ve not got a copy of Maple 14 yet but will try to write more if I upgrade (finances permitting).</p>
<p>For a full list of changes check out <a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=updates%2fMaple14%2findex">Maple&#8217;s online help section</a>.</p>
<h3>More on Maple from Walking Randomly</h3>
<ul>
<li><a href="http://www.walkingrandomly.com/?p=1563">Japanese firm buys Maplesoft</a></li>
<li><a href="http://www.walkingrandomly.com/?p=2029">Simulating Santa using Maple</a></li>
<li><a href="http://www.walkingrandomly.com/?p=1837">Parallel Programming in Maple</a></li>
</ul>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/71PHrjV85Lc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2646</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>When can’t MATLAB add up?</title>
		<link>http://www.walkingrandomly.com/?p=2629</link>
		<comments>http://www.walkingrandomly.com/?p=2629#comments</comments>
		<pubDate>Thu, 29 Apr 2010 10:02:34 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[math software]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2629</guid>
		<description><![CDATA[I have got a nice, shiny 64bit version of MATLAB running on my nice, shiny 64bit Linux machine and so, naturally, I wanted to be able to use 64 bit integers when the need arose.  Sadly, MATLAB had other ideas.  On MATLAB 2010a:
a=int64(10);
b=int64(20);
a+b
??? Undefined function or method 'plus' for input arguments of type 'int64'.
It doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I have got a nice, shiny 64bit version of <a href="http://www.mathworks.com/">MATLAB</a> running on my nice, shiny 64bit Linux machine and so, naturally, I wanted to be able to use 64 bit integers when the need arose.  Sadly, MATLAB had other ideas.  On MATLAB 2010a:</p>
<pre>a=int64(10);
b=int64(20);
a+b
??? Undefined function or method 'plus' for input arguments of type 'int64'.</pre>
<p>It doesn&#8217;t like any of the other operators either</p>
<pre>&gt;&gt; a-b
??? Undefined function or method 'minus' for input arguments of type 'int64'.

&gt;&gt; a*b
??? Undefined function or method 'mtimes' for input arguments of type 'int64'.

&gt;&gt; a/b
??? Undefined function or method 'mrdivide' for input arguments of type 'int64'.</pre>
<p>At first I thought that there was something wrong with my MATLAB installation but it turns out that this behaviour is expected and documented. At the time of writing, the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/int8.html">MATLAB documentation</a> contains the lines</p>
<pre>Note   Only the lower order integer data types support math operations.
Math operations are not supported for int64 and uint64.</pre>
<p>So, there you have it. When can&#8217;t MATLAB add up? When you ask it to add 64 bit integers!</p>
<p><strong>Update:</strong> Just had an email from someone who points out that <a href="http://www.gnu.org/software/octave/">Octave</a> (Free MATLAB Clone) can handle 64bit integers just fine</p>
<pre>octave:1&gt; a=int64(10);
octave:2&gt; b=int64(20);
octave:3&gt; a+b
ans = 30
octave:4&gt;</pre>
<p><strong>Update 2:</strong> Since I got <a href="http://tech.slashdot.org/story/10/05/02/2038255/MATLAB-Cant-Manipulate-64-Bit-Integers">slashdotted</a>, people have been asking why I (or, more importantly, the user I was helping) needed 64bit integers.  Well, we were using the <a href="http://www.nag.co.uk/numeric/MB/start.asp">NAG Toolbox for MATLAB</a> which is a MATLAB interface to the NAG Fortran library.  Some of its routines require integer arguments and on a 64bit machine these must be 64bit integers.  We just needed to do some basic arithmetic on them before passing them to the toolbox and discovered that we couldn&#8217;t.  The work-around was simple &#8211; use int32s for the arithmetic and then convert to int64 at the end so no big deal really.  I was simply surprised that arithmetic wasn&#8217;t supported for int64s directly &#8211; hence this post.</p>
<p><strong>Update 3: </strong>In the comments, someone pointed out that there is a package on the File Exchange that adds <a href="http://www.mathworks.com/matlabcentral/fileexchange/24725">basic arithmetic support for 64bit integers</a>.  I&#8217;ve not tried it myself though so can&#8217;t comment on its quality.</p>
<p><strong>Update 4: </strong>Someone has made me aware of an interesting discussion concerning this topic on MATLAB Central a few years back: <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/154955">http://www.mathworks.com/matlabcentral/newsreader/view_thread/154955</a></p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/Gxg7SmYRBoM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2629</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Interfacing the NAG C Library and Python on Windows</title>
		<link>http://www.walkingrandomly.com/?p=2188</link>
		<comments>http://www.walkingrandomly.com/?p=2188#comments</comments>
		<pubDate>Sat, 24 Apr 2010 22:01:37 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[NAG Library]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2188</guid>
		<description><![CDATA[Late last year I was asked to give a talk at my University to a group of academics studying financial mathematics (Black-Scholes, monte-carlo simulations, time series analysis &#8211; that sort of thing).  The talk was about the NAG Numerical Library, what it could do, what environments you can use it from, licensing and how they [...]]]></description>
			<content:encoded><![CDATA[<p>Late last year I was asked to give a talk at <a href="http://www.manchester.ac.uk/">my University</a> to a group of academics studying financial mathematics (<a href="http://en.wikipedia.org/wiki/Black%E2%80%93Scholes">Black-Scholes</a>, <a href="http://en.wikipedia.org/wiki/Monte_Carlo_methods_in_finance">monte-carlo simulations</a>, <a href="http://en.wikipedia.org/wiki/Time_series">time series analysis</a> &#8211; that sort of thing).  The talk was about the <a href="http://www.nag.co.uk/">NAG Numerical Library</a>, what it could do, what environments you can use it from, licensing and how they could get their hands on it via our site license.</p>
<p>I also spent a few minutes talking about <a href="http://www.python.org/">Python</a> including why I thought it was a good language for numerical computing and how to interface it with the NAG C library using <a href="http://www.walkingrandomly.com/?p=830">my tutorials</a> and <a href="http://www.walkingrandomly.com/?page_id=1662">PyNAG code</a>.  I finished off with a simple graphical demonstration that minimised the <a href="http://en.wikipedia.org/wiki/Rosenbrock_function">Rosenbrock</a> function using Python, Matplotlib and the NAG C-library running on Ubuntu Linux.</p>
<p>&#8220;So!&#8221;, I asked, &#8220;Any questions?&#8221;</p>
<p>The very first reply was &#8220;Does your Python-NAG interface work on Windows machines?&#8221; to which the answer at the time was &#8220;No!&#8221;  I took the opportunity to ask the audience how many of them did their numerical computing in Windows (Most of the room of around 50+ people), how many people did it using Mac OS X (A small group at the back), and how many people did it in Linux (about 3).</p>
<p>So, if I wanted the majority of that audience to use PyNAG then I had to get it working on Windows.  Fortunately, thanks to the portability of Python and the consistency of the NAG library across platforms, this proved to be rather easy to do and the result is now available for download on the main PyNAG webpage.</p>
<p>Let&#8217;s look at the main differences between the Linux and Windows versions</p>
<p><strong>Loading the NAG Library</strong></p>
<p>In the examples given in <a href="http://www.walkingrandomly.com/?p=830">my Linux NAG-Python tutorials</a>, the cllux08dgl <a href="http://www.nag.co.uk/numeric/CL/cldescription.asp">NAG C-library</a> was loaded using the line</p>
<pre>libnag = cdll.LoadLibrary("/opt/NAG/cllux08dgl/lib/libnagc_nag.so.8")</pre>
<p>In Windows the call is slightly different.  Here it is for CLDLL084ZL (Mark 8 of the C library for Windows)</p>
<pre>C_libnag = ctypes.windll.CLDLL084Z_mkl</pre>
<p>If you are modifying any of the codes shown in my NAG-Python tutorials then you&#8217;ll need to change this line yourself.  If you are using PyNAG, however, then it will already be done for you.</p>
<p><strong>Callback functions</strong></p>
<p>For my full introduction to NAG callback functions on Linux <a href="http://www.walkingrandomly.com/?p=830">click here</a>.  The main difference between using callbacks on Windows compared to Linux is that on Linux we have</p>
<pre>C_FUNC = CFUNCTYPE(c_double,c_double )</pre>
<p>but on Windows we have</p>
<pre>C_FUNC = WINFUNCTYPE(c_double,c_double )</pre>
<p>There are several callback examples in the <a href="http://www.walkingrandomly.com/?page_id=1662">PyNAG distribution</a>.</p>
<p>That&#8217;s pretty much it I think.  Working through all of the PyNAG examples and making sure that they ran on Windows uncovered one or two bugs in my codes that didn&#8217;t affect Linux for one reason or another so it was a useful exercise all in all.</p>
<p>So, now you head over to the <a href="http://www.walkingrandomly.com/?page_id=1662">main PyNAG page</a> and download the Windows version of my Python/NAG interface which includes a set of example codes.  I also took the opportunity to throw in a couple of extra features and so upgraded PyNAG to version 0.16, check out the readme for more details.  Thanks to several employees at NAG for all of their help with this including Matt, John, David, Marcin and Sorin.</p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/6manMkXGSQs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2188</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Playing with NAG’s Library for SMP &amp; multicore (Or parallel programming made easy)</title>
		<link>http://www.walkingrandomly.com/?p=2475</link>
		<comments>http://www.walkingrandomly.com/?p=2475#comments</comments>
		<pubDate>Tue, 20 Apr 2010 12:51:27 +0000</pubDate>
		<dc:creator>Mike Croucher</dc:creator>
				<category><![CDATA[Fortran]]></category>
		<category><![CDATA[NAG Library]]></category>
		<category><![CDATA[math software]]></category>
		<category><![CDATA[parallel programming]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.walkingrandomly.com/?p=2475</guid>
		<description><![CDATA[I work for the University of Manchester in the UK as a &#8216;Science and Engineering Applications specialist&#8217; which basically means that I am obsessed with software used by mathematicians and scientists.  One of the applications within my portfolio is the NAG library &#8211; a product that we use rather a lot in its various incarnations.  [...]]]></description>
			<content:encoded><![CDATA[<p>I work for the University of Manchester in the UK as a &#8216;Science and Engineering Applications specialist&#8217; which basically means that I am obsessed with software used by mathematicians and scientists.  One of the applications within my portfolio is the <a href="http://www.nag.co.uk">NAG library</a> &#8211; a product that we use rather a lot in its various incarnations.  We have people using it from Fortran, C, C++, MATLAB, Python and even Visual Basic in areas as diverse as engineering, applied maths, biology and economics.</p>
<p>Yes, we are big users of NAG at Manchester but then that stands to reason because NAG and Manchester have a collaborative history stretching back 40 years to NAG&#8217;s very inception.  Manchester takes a lot of NAG&#8217;s products but for reasons that are lost in the mists of time, we have never (to my knowledge at least) had a site license for their <a href="http://www.nag.co.uk/numeric/fl/FSdescription.asp">SMP library (more recently called The NAG Library for SMP &amp; multicore)</a>.  Very recently, that changed!</p>
<p>SMP stands for <a href="http://en.wikipedia.org/wiki/Symmetric_multiprocessing">Symmetric Multi-Processor</a> which essentially means &#8216;two or more CPUs sharing the same bit of memory.&#8217;  Five years ago, it would have been rare for a desktop user to have an SMP machine but these days they are everywhere.  Got a dual-core laptop or a quad-core desktop?  If the answer&#8217;s &#8216;yes&#8217; then you have an SMP machine and you are probably wondering how to get the most out of it.</p>
<h3>&#8216;How can I use all my cores (without any effort)&#8217;</h3>
<p>One of the most common newbie questions I get asked these days goes along the lines of &#8216;Program X is only using 50%/25%/12.5% of my CPU &#8211; how can I fix this?&#8217; and, of course, the reason for this is that the program in question is only using a single core of their multicore machine.  So, the problem is easy enough to explain but not so easy to fix because it invariably involves telling the user that they are going to have to learn how to program in parallel.</p>
<p><a href="http://en.wikipedia.org/wiki/Explicit_parallelism">Explicit parallel programming</a> is a funny thing in that sometimes it is trivial and other  times it is pretty much impossible &#8211; it all depends on the problem you see.  Sometimes all you need to do is drop a few <a href="http://openmp.org/wp/">OpenMP</a> pragmas here and there and you&#8217;ll get a 2-4 times speed up.  Other times you need to completely rewrite your algorithm from the ground up to get even a modest speed up.  Yet more times you are simply stuck because your problem is inherently non-parallelisable.  It is even possible to slow your code down by trying to parallelize it!</p>
<p>If you are lucky, however, then you can make use of all those extra cores with no extra effort at all!  Slowly but surely, mathematical software vendors have been re-writing some of their functions to ensure that they work efficiently on parallel processors in such a way that it is transparent to the user.  This is sometimes referred to as <a href="http://en.wikipedia.org/wiki/Implicit_parallelism">implicit parallelism</a>.</p>
<p>Take MATLAB, for example, ever since release 2007a more and more built in MATLAB functions have been modified to allow them to make full use of multi-processor systems.  If your program makes extensive use of these functions then you don&#8217;t need to spend extra money or time on the parallel computing toolbox, just run your code on the latest version of MATLAB, sit back and enjoy the speed boost.  It doesn&#8217;t work for all functions of course but it does for an <a href="http://www.walkingrandomly.com/?p=1795">ever increasing subset</a>.</p>
<h3>The NAG SMP Library &#8211; zero effort parallel programming</h3>
<p>For users of NAG routines, the zero-effort approach to making better use of your multicore system is to use their SMP library.  According to NAG&#8217;s advertising blurb you don&#8217;t need to rewrite your code to get a speed boost &#8211; you just need to link to the SMP library instead of the Fortran library at compile time.</p>
<p>Just like MATLAB, you won&#8217;t get this speed boost for every function, but you will get it for a significant subset of the library (around 300+ functions as of Mark 22 &#8211; <a href="http://www.nag.com/numeric/fl/nagdoc_fl22/html/GENINT/smptuned.html#SMPTUNED">the full list is available on NAG&#8217;s website</a>).  Also, just like MATLAB, sometimes the speed-up will be massive and other times it will be much more modest.</p>
<p>I wanted to test NAG&#8217;s claims for myself on the kind of calculations that researchers at Manchester tend to perform so I asked NAG for a trial of the upcoming Mark 22 of the SMP library and, since I am lazy, I also asked them to provide me with simple demonstration programs and I&#8217;d like to share the results with you all. <strong> These are not meant to be an exhaustive set of benchmarks</strong> (I don&#8217;t have the time to do such a thing) but should give you an idea of what you can expect from NAG&#8217;s new library.</p>
<p><strong>System specs</strong></p>
<p>All of these timings were made on a 3Ghz Intel Core2 Quad Q9650 CPU desktop machine with 8Gb of RAM running Ubuntu 9.10.  The serial version of the NAG library used was fll6a22dfl  and the SMP version of the library was fsl6a22dfl.  The version of gfortran used was 4.4.1 and the cpu-frequency governor was switched off as per <a href="http://www.walkingrandomly.com/?p=2587">a previous blog post of mine</a>.</p>
<p><strong>Example 1 &#8211; Nearest correlation matrix</strong></p>
<p>The first routine I looked at was one that calculated the nearest <a href="http://en.wikipedia.org/wiki/Correlation_and_dependence">correlation matrix</a>. In other words &#8216;Given a symmetric matrix, what is the nearest correlation matrix—that<sup> </sup>is, the nearest symmetric positive semidefinite matrix with<sup> </sup>unit diagonal?&#8217;<sup>[1]</sup> This is a problem that pops up a lot in Finance &#8211; option pricing, risk management &#8211; that sort of thing.</p>
<p>The NAG routine that calculates the nearest correlation matrix is G02AAF which is based on the algorithm developed by Qi and Sun<sup>[2]</sup>.  The example program I was sent first constructs a N x N tridiagonal matrix A of the form A(j,j)=2, A(j-1,j)=-1.1 and A(j,j-1)=1.0.  It then times how long it takes G02AAF to find the nearest correlation matrix to A.  You can download this example, along with all supporting files, from the links below.</p>
<p>To compile this benchmark against the<strong> serial library</strong> I did</p>
<pre>gfortran ./bench_g02aaf.f90 shtim.c wltime.f /opt/NAG/fll6a22dfl/lib/libnag_nag.a  \
/opt/NAG/fll6a22dfl/acml/libacml_mv.a -o serial_g02aaf</pre>
<p>To compile the <strong>parallel version</strong> I did</p>
<pre>gfortran -fopenmp ./bench_g02aaf.f90 shtim.c wltime.f /opt/NAG/fsl6a22dfl/lib/libnagsmp.a \
  /opt/NAG/fsl6a22dfl/acml4.3.0/lib/libacml_mp.a -o smp_g02aaf</pre>
<p>I didn&#8217;t need to modify the source code in any way when going from a serial version to a parallel version of this benchmark. The only work required was to link to the SMP library instead of the serial library &#8211; so far so good. Let&#8217;s run the two versions and see the speed differences.</p>
<p>First things first, let&#8217;s ensure that there is no limit to the stack size of my shell by doing the following in bash</p>
<pre>ulimit -s unlimited</pre>
<p>Also, for the parallel version, I need to set the number of threads to equal the number of processors I have on my machine by setting the OMP_NUM_THREADS environment variable.</p>
<pre>export OMP_NUM_THREADS=4</pre>
<p>This won&#8217;t affect the serial version at all. So, onto the program itself. When you run it, it will ask you for two inputs &#8211; an integer, N, and a boolean, IO. N gives the size of the starting matrix and IO determines whether or not to output the result.</p>
<p>Here&#8217;s an example run of the serial version with N=1000 and IO set to False. (In Fortran True is represented as<strong> .t.</strong> and False is represented  as<strong> .f. </strong>)</p>
<pre>./serial_g02aaf
 G02AAF: Enter N, IO
1000 .f.
 G02AAF: Time, IFAIL =    37.138997077941895                0
 G02AAF: ITER, FEVAL, NRMGRD =            4           5  4.31049822255544465E-012</pre>
<p>The only output I am really interested in here is the time and 37.13 seconds doesn&#8217;t seem too bad for a 1000 x 1000 matrix at first glance. Move to the parallel version though and you get a very nice surprise</p>
<pre>./smp_g02aaf
 G02AAF: Enter N, IO
1000 .f.
 G02AAF: Time, IFAIL =    5.1906139850616455                0
 G02AAF: ITER, FEVAL, NRMGRD =            4           5  4.30898281428799420E-012</pre>
<p>The above times were typical and varied little from run to run (although the SMP version varied by a bigger percentage than the serial version).  However I averaged over 10 runs to make sure and got <strong>37.14 s</strong> for the serial version and <strong>4.88 s</strong> for the SMP version which gives a speedup of <strong>7.6 times</strong>!</p>
<p>Now, this is rather impressive.  Usually, when one parallelises over N cores then the very best you can expect in an ideal word is a speed up of just less than N times, so called &#8216;linear scaling&#8217;.  Here we have N=4 and a speedup of 7.6 implying that NAG have achieved &#8217;super-linear scaling&#8217; which is usually pretty rare.</p>
<p>I dropped them a line to ask what was going on.  It turns out that when they looked at parallelising this routine they worked out a way of speeding up the serial version as well.  This serial speedup will be included in the serial library in its next release, Mark 23 but the SMP library got it as of Mark 22.</p>
<p>So, some of that 7.6 times speedup is as a result of serial speedup and the rest is parallelisation.  By setting OMP_NUM_THREADS to 1 we can force the SMP version of the benchmark to only run on only one core and thus see how much of the speedup we can attribute to parallelisation:</p>
<pre>export OMP_NUM_THREADS=1
./smp_g02aaf
 G02AAF: Enter N, IO
1000 .f.
 G02AAF: Time, IFAIL =    12.714214086532593                0
 G02AAF: ITER, FEVAL, NRMGRD =            4           5  4.31152424170390294E-012</pre>
<p>Recall that the 4 core version took an average of 4.88 seconds so the speedup from parallelisation alone is <strong>2.6 times</strong> &#8211; much closer to what I expected to see.  Now, it is probably worth mentioning that there is an extra level of complication (with parallel programming there is <strong>always</strong> an extra level of complication) in that some of this parallelisation speedup comes from extra work that NAG has done in their algorithm and some of it comes from the fact that they are linking to parallel versions of the BLAS and LAPACK libraries.  We could go one step further and determine how much of the speed up comes from NAG&#8217;s work and how much comes from using parallel BLAS/LAPACK but, well, life is short.</p>
<p>The practical upshot is that if you come straight from the Mark 22 serial version then you can expect a <strong>speed-up of around 7.6 times</strong>.  In the future, when you compare the Mark 22 SMP library to the Mark 23 serial library then you can expect a speedup of around 2.6 times on a 4 core machine like mine.</p>
<p><strong>Example 2 &#8211; Quasi random number generation</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Low-discrepancy_sequence">Quasi random numbers</a> (also referred to as &#8216;Low discrepancy sequences&#8217;) are extensively used in Monte-Carlo simulations which have applications in areas such as finance, chemistry and computational physics.  When people need a set of quasi random numbers they usually need a LOT of them and so the faster they can be produced the better.  The NAG library contains several quasi random number generators but the one considered here is the routine g05ymf.  The benchmark program I used is called bench_g05ymf.f90 and the full set of files needed to compile it are available at the end of this section.</p>
<p>The benchmark program requires the user to input 4 numbers and a boolean as follows.</p>
<ul>
<li>The first number is the quasi random number generator to use with the options being:
<ol>
<li>NAG&#8217;s newer Sobol generator (based on the 2008 Joe and Kuo algorithm<sup>[3]</sup> )</li>
<li>NAG&#8217;s older Sobol generator</li>
<li>NAG&#8217;s Niederreiter generator</li>
<li>NAG&#8217;s Faure generator</li>
</ol>
</li>
<li>The second number is the order in which the generated values are returned (The parameter RCORD as referred to in the documentation for g05ymf). Say that the matrix of returned values is called QUAS then if RCORD=1, QUAS(i,j) holds the jth value for the ith dimension, otherwise QUAS(i,j) holds the ith value for the jth dimension.</li>
<li>The third number is the number of dimensions required.</li>
<li>The fourth number is the number of number of quasi-random numbers required.</li>
<li>The boolean (either .t. or .f.) determines whether or not the output should be verbose or not.  A value of .t. will output the first 100 numbers in the sequence.</li>
</ul>
<p>To compile the benchmark program against the serial library I did:</p>
<pre>gfortran ./bench_g05ymf.f90 shtim.c wltime.f /opt/NAG/fll6a22dfl/lib/libnag_nag.a  \
/opt/NAG/fll6a22dfl/acml/libacml_mv.a -o serial_g02aaf</pre>
<p>As before, the only thing needed to turn this into a parallel program was to compile against the SMP library and add the -fopenmp switch</p>
<pre>gfortran -fopenmp ./bench_g05ymf.f90 shtim.c wltime.f /opt/NAG/fsl6a22dfl/lib/libnagsmp.a  \
/opt/NAG/fsl6a22dfl/acml4.3.0/lib/libacml_mp.a -o smp_g02aaf</pre>
<p>The first set of parameters I used was</p>
<pre>1 2 900 1000000 .f.</pre>
<p>Which uses NAG&#8217;s new Sobol generator with RCORD=2 to generate and store 1,000,000 numbers over 900 dimensions with no verbose output.  Averaged over 10 runs the times were <strong>5.17 seconds</strong> for the serial version and <strong>2.14 seconds</strong> for the parallel version giving a <strong>speedup of 2.4x</strong> on a quad-core machine.  I couldn&#8217;t push number of dimensions much higher because the benchmark stores all of the numbers in one large array and I was starting to run out of memory.</p>
<p>If you only want a relatively small sequence then switching to the SMP library is actually slower thanks to the overhead involved in spawning extra threads.  For example if you only want 100,000 numbers over 8 dimensions:</p>
<pre>1 2 8 100000 .f.</pre>
<p>then the serial version of the code takes an average of <strong> 0.0048 seconds</strong> compared to <strong>0.0479 seconds</strong> for the parallel version so the parallel version is almost 10 times slower when using 4 threads for small problems. Setting OMP_NUM_THREADS to 1 gives exactly the same speed as the serial version as you might expect.</p>
<p>NAG have clearly optimized this function to ensure that you get a good speedup for large problem sets which is where it really matters so I am very pleased with it.  However, the degradation in performance for smaller problems concerns me a little.  I think I&#8217;d prefer it if NAG were to modify this function so that it works serially for small sequences and to automatically switch to parallel execution if the user requests a large sequence.</p>
<p><strong>Conclusions</strong></p>
<p>In the old days we could speedup our programs simply by buying a new computer.  The new computer would have a faster clock speed than the old one and so our code would run faster with close to zero effort on our part.  Thanks to the fact that clock speeds have stayed more or less constant for the last few years those days are over.  Now, when we buy a new computer we get more processors rather than faster ones and this requires a change in thinking.  Products such as the NAG Library for SMP &amp; multicore help us to to get the maximum benefit out of our machines with the minimum amount of effort on our part.  If switching to a product like this doesn&#8217;t give you the performance boost you need then the next thing for you to do is to learn how to program in parallel.  The free ride is over.</p>
<p>In summary:</p>
<ul>
<li>You don&#8217;t need to modify your code if it already uses NAG&#8217;s serial library.  Just recompile against the new library and away you go.  You don&#8217;t need to know anything about parallel programming to make use of this product.</li>
<li>The SMP Library works best with big problems.  Small problems don&#8217;t work so well because of the inherent overheads of parallelisation.</li>
<li>On a quad-core machine you can expect speed-ups around 2-4 times compared to the serial library.  In exceptional circumstances you can expect speed-up as large as 7 times or more.</li>
<li>You should notice a speed increase in over 300 functions compared to the serial library.</li>
<li>Some of this speed increase comes from fundamental libraries such as BLAS and LAPACK, some of it comes from NAG directly parallelising their algorithms and yet more comes from improvements to the underlying serial code.</li>
<li>I&#8217;m hoping that this Fortran version is just the beginning.  I&#8217;ve always felt that NAG program in Fortran so I don&#8217;t have to and I&#8217;m hoping that they will go on to incorporate their SMP improvements in their other products, especially their <a href="http://www.nag.co.uk/numeric/CL/cldescription.asp">C library</a> and <a href="http://www.nag.co.uk/numeric/MB/start.asp">MATLAB toolbox</a>.</li>
</ul>
<p><strong>Acknowledgements</strong></p>
<p>Thanks to several staff at NAG who suffered my seemingly endless stream of emails during the writing of this article.  Ed, in particular, has the patience of a saint.  Any mistakes left over are all mine!</p>
<p><strong>Links</strong></p>
<ul>
<li>The Nearest Correlation Matrix benchmark program used here &#8211; <a href="http://www.walkingrandomly.com/images/NAG/SMP/bench_g02aaf.zip">bench_g02aaf.f90</a> &#8211; along with the source code for the timing routine.</li>
<li><a href="http://www.nag.co.uk/numeric/fl/nagdoc_fl22/pdf/G02/g02aaf.pdf">NAG&#8217;s documentation for the g02aaf routine</a>.</li>
<li>The Quasi Random Number benchmark program used here &#8211; <a href="http://www.walkingrandomly.com/images/NAG/SMP/bench_g05ymf.zip">bench_g05ymf.f90</a> &#8211; along with the source code for the timing routine.</li>
<li><a href="www.nag.co.uk/.../introduction_to_quasi_random_numbers.pdf">An Introduction to quasi random numbers</a> (written by a member of NAG&#8217;s staff)</li>
<li><a href="http://www.nag.co.uk/numeric/fl/nagdoc_fl22/pdf/G05/g05ymf.pdf">Official NAG documentation for g05ymf</a> &#8211; the quasi random number generator considered here.</li>
</ul>
<p><strong>References</strong></p>
<p>[1] &#8211; Higham N, Computing the nearest correlation matrix—a problem from finance, IMA Journal of Numerical Analysis 22 (3): 329–343</p>
<p>[2] &#8211; Qi H and Sun D (2006), A Quadratically Convergent Newton Method for Computing the Nearest<br />
Correlation Matrix, SIAM J. Matrix AnalAppl 29(2) 360–385</p>
<p>[3] &#8211; Joe S and Kuo F Y (2008) Constructing Sobol sequences with better two-dimensional projects SIAM J. Sci. Comput. 30 2635–2654</p>
<p><strong>Dislaimer: This is a personal blog and the opinions expressed on it are mine and do not necessarily reflect the policies and opinions of my employer, The University of Manchester.</strong></p>
<img src="http://feeds.feedburner.com/~r/WalkingRandomly/~4/gJiApvyq9NE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.walkingrandomly.com/?feed=rss2&amp;p=2475</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.532 seconds --><!-- Cached page served by WP-Cache -->
