### In which Ben learns about code optimization the hard way….

I’m currently involved in a project for a paper I’m writing where I’m trying to find the auto-covariance function of a queue, which involves evaluating modified Bessel functions of the first kind; in essence these are the solutions to a particular form of differential equations which tell you how queues work, and each evaluation takes a relatively large amount of time: they are the limiting step in getting towards the answer I’m after in my code. I’m very close to generating the results I think I need to finish the paper, and was getting very frustrated by how slowly the code ran.

For my application, the Bessel function, implemented in matlab and (with a really weird bug initially) in Octave, as `besseli` is ideal. Essentially, I need to evaluate this over and over again; the Bessel function has two parameters, an index, which in my case is an integer, and another parameter, in my case a positive real number, which is fixed for each function evaluation.

The thing I learnt last night is the extreme time saving in doing things in a sensible order- I’ve had quite a lot of coding training, but to be honest, never really come across situations where using it is needed. So essentially my code was doing this for each z,

``` out=myOldFunction(z,n,N) for m=(1:N) out+=m*(besseli(m-n,z)-besseli(m+n,z) +...% (more functions of besseli) end ```

This function has many calls to `besseli`, each of which is an expensive step. Sometimes we even evaluate the same function twice. By replacing this function with a vectorized call to `besseli`, we should reduce the overall calls to `besseli`.

``` out=myNewFunction(z,n,N) b=besseli((0:(n+N+50)),z); % <-Vectorized version of besseli for m=(1:N) out+=m*(b(abs(m-n)+1)-b(abs(m+n)+1) +...%(more functions of b) ```

And it’s as simple as that; it helps in this case that the function is symmetric (and `besseli(n,z)-besseli(-n,z)`. The results are that the code runs about four times faster. For those of you that programme more regularly, and as it should have been for me, this is quite obvious. I write this because

1. With a little bit of thought, I could have saved myself many hours of computing time, and have finished this paper about a month ago, probably.
2. It might help someone else out.
3. As a reminder to myself to think carefully about things like this before any serious coding happens.

Originally published at Ben Parker's Blog. You can comment here or there.

### More bad use of statistics

I’ve been listening to the news today, and every news bulletin has a report, which cites an AA/Populus poll, that motorists are using less petrol; Sky news has a fairly common story here. Now, I’ve been unable to find the original source of the article, but here’s the interpretation.

Basically, the AA said that 16.3 billion litres were used in a period in 2008; 14.9 billion litres were used in the same period in 2009 ( a drop of 8.6%), and 13.9 billion used in 2010. The theme of the article is that the reason people are using less fuel is because it’s so expensive: another doom and gloom story, economic depression forces poor people off the road, the roads are once again the domain of the gentrified rich, and isn’t this terrible?

But official statistics from the department of energy and climate change  show that the average person drove 3332 miles in 2009, as opposed to 3485 miles in 2008; a drop of 4.4%; there is no data yet for 2010. There was a small rise in the number of passenger miles in a car.

So petrol sales have fell by 8.6%; approximately half of this fall seems to be due to falling demand for driving, but the other half seems to be due to people getting more energy efficient: presumably cars are more efficient, there are more electric cars and cars which do not use petrol, and almost every newer car seems to be doing more miles per gallon.This is backed up by the DECC data that driving had an efficiency of 37.2 (thousand tonnes of oil equivelent per billion km) in 2008 as opposed to 38.0 in 2009; a drop of 2.2%.

Even more than this, perhaps we are commuting less because more people are taking advantage of technology, and working from home? There seems to be little data available post 2005 (when the office for National Statistics stopped compiling this), but working at locations other than an office seemed to be on the rise until 2005, and it would be reasonable to extrapolate this upwards as technology has continued to improve until now.

Overall, it seems people are travelling less far to go to work; we are burning less fuel when we do go commute due to more efficient technology.  Should we not therefore rejoice in our green credentials, and perhaps acknowledge that there is a good side to this story as well as a bad?

Moreover, should we not ask that the press do a tiny bit of research to put statistics in context? Making conclusions that are not supported by the data, or at least not exploring more than one likely cause, seems irresponsible and lazy to me.

Originally published at Ben Parker's Blog. You can comment here or there.

### What I saw in Edinburgh 2011…

A bit of a late post, but I recently came across my collection of tickets for this year’s Edinburgh fringe, the world’s largest arts festivel. Now, due to not being well and one thing or the other, I didn’t see nearly as much as I would like to; we must fix that next year.
I’ve also forgotten what else I’ve seen; if anybody who was there can remind me, I was probably drunk at the time!

In no particular order with marks out of 5*.:

The Axis of Awesome These guys are cool; seriously, very cool, they deconstruct modern music in a very funny way. However, most of their material, even their fake ad libs, was precisely the same as I saw last year down to the geeky pauses. I did enjoy hearing the songs, but to be honest, I got nothing new from seeing them again. If you haven’t heard the four chord song, this is worth five minutes of your time. http://youtu.be/5pidokakU4I.  ***

Thirty Two Teeth, Jam Jar Productions. I took a risk on this as a last minute freebie. Thirty Two Teeth was a script based on the, admittedly novel, idea that by capturing the tooth fairy, you could do whatever you wanted, as long as you gave her enough teeth. It is, as far as I know, the only play to touch on dentistry, and fairy bondage, using the conveniently located chain on stage. The acting was very school-play intense, and I think the actors were thoroughly bored with what was a good idea for a ten minute piece of writing, but did not captivate me for more than about 15, leaving the other 45 to wonder whether I would have preferred a trip to the dentist. *

A tribute to the Blues Brothers- Live, Hartshorn and Hook. I have seen this company do some amazing things; unfortunately this wasn’t one of them. The band were phenomenal, particularly the hot trumpeter, but, oh dear, the singing was karaoke tastic. I think if you were in the mood (i.e. a little tipsy) then this would have been a great 11pm show; unfortunately I wasn’t, and it was actually annoying to have one third of the audience dancing in the aisles while the other two thirds looked slightly uncomfortable. The frequent trips of the choorus through the audience made me feel it was a bit like Blues Brothers: The Panto, which is an awesome idea, but not what was sold. **1/2

Armageddapocalypse: The Explosioning, Exploding First Productions. I enojoyed this show; there were some great puns, one liners, and performances, with some great acting from the overworked cast. The shoestring production nature made a lot of it funnier; the script could have done with a bit more of a polish, the best lines were very good, the rest unremarkable, but overall enjoyable and fresh. ****

Sunday in the Park With George, One Academy Productions. Wow. I have been to the fringe 10 times, and I think this is the best thing I have ever seen. Admittedly, I do like Sonddheim, so I had high hopes, but the singing was beautiful, the musicians perfect, staging immaculate, artistic design exquisite, and what’s more it wasn’t jsut a collection of songs; these kids can act. For no reason particularly, I cried through most of the second half, and loved every minute of it.. *****

Showstoppers, The Improvised Musical . I normally hate impro shows; I mean I love them, but I’d rather do them than watch, because once you’e done a bit, it becomes technical appreciation rather than usually genuinely funny. But once again, these guys seem to have all the impro skills, the musical skills, and are also genuinely funny and talented, the last being what a lot of impro misses. The format is superb as well: having a director able to intervene, give fourth-wall breaking penalties, and move the story along helps in those times where, inevitably, things go down the wrong road. I regret only seeing this once, but it could never be the same again. ****

Originally published at Ben Parker's Blog. You can comment here or there.

### Where has all the money gone and why do we care?

So here’s my question- and please be gentle as I know very little about economics- is where has all the money gone, and why do we care?

Let me explain; most people I know owe a little money, either on credit cards, or mortgages, or student loans, or whatever. But all the people who they owe this money to (the banks, the government) owe a lot of money. We keep being told how much money everyone owes. The country owes a lot of money; presumably to banks, who also owe a lot of money. The Americans owe a ridiculous amount of money. Greece owes more money than it can perhaps pay back to all the other people that owe money.

So where is all this money? Is it sitting in some vault in china somewhere? Or is there some kind of hilarious mistake where somebody’s missed a few zeros off in some computer code somewhere. And if nobody has any money (Except the chinese), why does it matter? Why do we not all get together and say, right, let’s start again, everybody has zero debt, and china can go worry about itself. SUre, it would cause some problems, but we could stop talking about how much everyone owes all the time.

Originally published at Ben Parker's Blog. You can comment here or there.

### Mac or PC?

What ho,
As part of my new job I have to get a new computer. The two options are either a PC or a mac. Never having had Mac hardware before, I’m tempted to go for the Mac; I intend to run Linux on it mostly. So, Internet people, is there any reason not to get an apple? The specifications look better for the Mac!

Or am I being seduced by the shinyness….

Mac

 Model iMac 21.5-inch Processor 2.5GHz Intel Quad- Core i5 Processor Memory (RAM) 4GB (1333MHz DDR3) Hard disk 500GB (7200RPM)
 Model Viglen desktop (Intel DQ67SW Motherboard) Processor Intel Core i5 Processor i5-2400 3.10GHz Memory (RAM) 4GB 1333MHz PC3-10600 DDR3 Memory Hard disk 320GB Serial ATA2 Hard Drive Optical drive Serial ATA Multi-format DVD Writer/CD-RW Drive Monitor 19″ Multimedia TFT monitor, height adjustable

Originally published at Ben Parker's Blog. You can comment here or there.

I’m fed up of the news today; we’re having a bit of warm weather, and the temperature today was forecast to be the “hottest September for more than 100 years”. See for example, The Daily Mirror.

But is this  all that unusual? I am assuming that the data being used is the Hadley Central England Temperature data ; I’ve no real interest in weather or climate statistics, but this is the longest series available in the world, and I think well respected. I’ve not done the calculations to check, but this daily detailed data goes back goes back to 1878, or 133 years before this one.

Now, let’s assume that we had 133 years worth of data, and we get a new one for this year, so we have 134 data. What is the probability that this year’s is the highest of the 133? Assuming we know nothing else, under this null hypothesis, the best guess we can make on this is 1/134.

So any day in the year chosen at random should have a probability of 1/134 of being the hottest day with that date on record. Thus, every year, we should expect to see the hottest particular day of the year approximately 3 times; in other words, it’s not that surprising.If we broaden it to the hottest or the coldest day on record, something “remarkable” we should see this headline 6 times a year, or once every two months.

Nor is it particularly surprising that if day x is the hottest, day x+1 is the hottest on record, although the calculations here would require some more science to work out. Now the cynic in me seems to think that it might be an excuse for newspapers to publish lots of pictures of fruity girls in bikinis; but surely The Daily Mail would never do that?

Non-news story. How about “Weather patterns still random”. Move on!

Originally published at Ben Parker's Blog. You can comment here or there.

### The Alumni Light Entertainment Society (ALES)

ALES (The Alumni Light Entertainment Society) is a loose conglomeration of alumni from various light entertainment societies,  predominantly Cambridge University (CULES), Oxford University (OULES), and more recently the University of Sheffield (USLES).

ALES exists to keep in touch with the light entertainment societies, and also to socialise with fellow alumni; alumni have even in the past put on a show or two at work friendly times for those that cannot get to the theatre.

There is no constitution, rules, but we do have a very silly charter. (I will post a link here when we find it!)

We tend to meet up for a drink every month (on the 16th, whatever day of the week that falls on), a Christmas dinner. Most events do tend to be in London, but we have been around the country at other times, and non-London events very much encouraged.

Our primary means of communication is via the  (low volume) ALES mailing list  at http://lightentertainment.org/mailman/listinfo/ales-announce/ approx 1 messages a month). We also tend to talk a lot of rubbish at http://lightentertainment.org/mailman/listinfo/ales-witter/ for a slightly higher volume social and discussion list (5/6 a week!). Please feel free to sign up for either of both.

## Upcoming Events/Pub Meets

Here is a list of upcoming events/pub meets.

16th September: PUB CAPTAIN BETH! Venue TBD

16th October: PUB CAPTAIN BEN! Venue TBD

16th November: PUB CAPTAIN ???- VOLUNTEER NOW!

16th December (Friday): The ALES Christmas Dinner

##### 1) There will be some meeting, normally in a pub, on the 16th of every month, whatever day this falls on. This allows us to balance weekdays/weekends, etc, in a good way, and means that people with regular commitments on a particular day can come at various times 2) This activity is generally something free that everyone can drop in to, at least for most of the time; there may be some kind of ticketed event, or something before or after such as a show, event, whatever, but people seem to generally prefer this not to be the focus of the ALES meet. 3) Of course if you do want to organise something ALESy and invite people on some day other than the 16th, or some place other than a pub, please do! 4) A pub captain shall volunteer for each pub meet who will be responsible for choosing pub and any sundry events. The pub captain shall be addressed as “Captain” at all times whilst in the pub, and shall be responsible for providing a witty anecdote, song, or dance, in the case that everyone is being boring. 5) The pub captain should e-mail the ales-witter list and the ales-announce list around a week before with the details, and update the facebook group with an event if they can be bothered!

Originally published at Ben Parker's Blog. You can comment here or there.

### HTC Hero wifi problem

After several months effort, I seem to have solved my wifi problem; my HTC hero isn’t able do to 802.11n. Setting my Netgear wireless router (provided by virgin) to only go up to 54MBps (which I think is 802.11g but it doesn’t say so!) seems to have been an easy fix.

I’m a little bit annoyed by this as I thought the devices should be clever enough to work out the fastest protocol they can both speak. They didn’t. Now, I’m not an expert on wifi, (but understand it enough to have written a paper on one element of it), but my giddy aunt, not nice.

Originally published at Ben Parker's Blog. You can comment here or there.

### Maths/ CompSci help needed

I have a feeling that this problem is easy if I know what to search for, but have spent some time trying to do it and can’t at the moment.

I am trying to generate a list of n elements, where each of the elements is a label from {1,…,k}. This is easy- there are k^n of them.

However, I want to exclude any lists which are the same if you change the labels. So for example, for n=5, k=3
1,1,1,1,2 is the same as 2,2,2,2,1
1,2,1,1,1 is the same as 1,3,1,1,1

as we could just swap 1 with 2 in the first case, and 3 with 2 in the second case.

My algorithm so far is
0) WLOG, let the first element be 1.
1) Enumerate all possible lists of length n-1 with k choices for each element
2) Throw away any where the first “2″ is not preceded by “1″, where the first “3″ is not preceded by “2″

So not very sophisticated. Am I missing a very simple way to do this? Do these lists have a name?

Two and a a half brownie points and a gin for anyone that solves it!

###### Background: For each set of labels, I need to do something hard (invert a (2k+1)x(2k+1) matrix). These labels don’t mean anything, so are interchangeable. I really just need to know which labels are different from all the others for the purposes of the hard step.

Originally published at Ben Parker's Blog. You can comment here or there.

### Nomination of Brian Blessed for Chancellor of Cambridge University

I sent a letter today. Perhaps the most useful thing I’ve done in months.

Friday 3 June 2011

To whom it may concern,

Nomination of Brian Blessed for Chancellor of Cambridge University

I hereby nominate actor, author and mountaineer Brian Blessed for the role of Chancellor of Cambridge University.

Brian’s accomplishments are legendary; a distinguished Shakespearian actor yet a gentleman with the common touch. A mountain of a man, yet one who climbs mountains. Members of the senate, let us not let this opportunity go by to nominate the greatest living Englishman as chancellor of our great university.

Yours faithfully,

Ben Parker,
Pembroke College,
Matriculation year 1996

Originally published at Ben Parker's Blog. You can comment here or there.