Thursday, 26 June 2008

Harmonic Stars

One of my pet projects is a web based system for recording all the DVDs and Videos that we own. The original aim of the system was to simply record everything we owned so that we would know what there was to watch. As with everything else software related that I start, I have spent more time on it then is reasonable and so it has grown to be so much more than a simple database. One of the more useful features that I added was a way for a group of people to figure out what they should sit down and watch. To improve the suggestions the system was making I decided to add star ratings. Now each user can assign a star rating to each film which is then used to make suggestions for the group. The problem arose when I was trying to work out the combined star rating for a group of users.

The easiest approach is simply to average the star ratings from the members of a group. For now I'm ignoring the issue of what to do with a film which one or more users hasn't rated (in the final system they are never actually suggested so the problem nicely disappears). Unfortunately simply averaging doesn't produce nice results. Lets assume (for the sake of simplicity) that there are just two users, then if they both give a film 3 out of 5 stars then it gets an average of 3 stars. This seems totally reasonable. If, however, one gives it a 5 and the others gives it a 1, then it also recieves an average star rating of 3. Clearly this isn't right. There is no way we should be suggesting a film that one person loves and one hates.

So my requirements are a function that 1) ranges between 0 and 5 so that I can match the combined star ratings onto the same scale as the individual ratings and 2) gives a combined star rating that matches my logical intuition of what should happen. Well that shouldn't be too hard to find!

After a long period of simply trying every averaging function in Excel I came to the conclusion that the clear winner was the harmonic mean. That is the reciprical of the arithmetic mean of the recipricals or for n positive real numbers:



I have no clear idea as to why the harmonic mean works but it does. Just to show you the difference here is all possible combinations of ratings from two users, showing both the average and harmonic mean to 2 decimal places and the final joint rating (the harmonic mean to 0 decimal places)

Rating 1Rating 2AverageHarmonic MeanJoint Rating
5.005.00
4.504.44
4.504.44
4.004.00
4.003.75
4.003.75
3.503.43
3.503.43
3.003.00
3.502.86
3.502.86
3.002.67
3.002.67
2.502.40
2.502.40
2.002.00
3.001.67
3.001.67
2.501.60
2.501.60
2.001.50
2.001.50
1.501.33
1.501.33
1.001.00

Note that the list is sorted by the harmonic mean so you can see by looking at the average column that it not only gives different numerical results but also would give a different ordering.

Maybe some of the more mathematically inclined of my readers may care to enlighten us all as to why the harmonic mean seems to be a good fit.

Not long after starting to write this post I came across another place where the same problem occurs: peer reviewing papers. I'm currently organising a workshop and so had to decide which of the submitted papers to accept based upon 3 reviews per paper. The system we use to help manage the process (START V2) by default simply averages the overall scores assigned to a paper. This though, suffers from the same problem as the star ratings and should probably be changed to use the harmonic mean. Fortunately in the case of my workshop while the order of the papers did change it didn't make any difference to which papers I accepted, but something to remember for the future.

Sunday, 22 June 2008

Shopping in the Souks - Part 2

When I described my trip to the souk in Marrakech I mentioned that I actually did do some shopping. Almost every meal served in Morocco will end with mint tea. So I bought a tea set so that when I try and cook Moroccan food at home I can also try and make mint tea in the proper kind of pot and serve it in the right kind of glasses.

Of course nothing in the souk has a fixed price. I have no idea if I paid way over the odds for the set or not but I did manage to bring the price down by 200 dirhams (about £14) from his initial asking price.

Monday, 16 June 2008

Creamy Asparagus Pasta

Ingredients (serves 2)
1 garlic glove
200g young asparagus
180ml double cream
two handfuls finely grated parmesan cheese
400g fresh tagliatelle

Cooking Instructions
Peel the garlic clove and place in a small pan with the double cream. Gently heat the cream almost until boiling and then remove from heat and allow to cool a little.

Remove the tips from the asparagus and then finely chop the stems. Boil the chopped asparagus for about 10 minutes until soft. Remove the garlic clove from the cream and then add the boiled asparagus and parmesan cheese. Using a hand blender, blend the asparagus, cream and cheese together to make the sauce.

Cook the fresh tagliatelle (usually about four minutes in boiling water) and the asparagus tips together. Drain the pasta and place on a plate. Spoon the sauce on top and serve.

A Large Moon

I've always wondered why sometimes the moon looks a lot larger than it does most of the rest of the year. Seems I'm not the only one, but if NASA doesn't know why it happens then I guess there is no reason that I should.

Wild Garlic Soup

On the first day at Dalhousie Castle we spent the morning exploring the substantial castle grounds. No matter where we walked we couldn't escape the sight (and smell) of Wild Garlic. It was under the trees, around the edge of the lower field and by the river -- it really was everywhere.

It came as no surprise then to see Wild Garlic Soup on the menu the following evening! It should also be no surprise that in-line with my life long aim to try and eat everything I had the soup and can report that it was fantastic. In fact I think I'll have to find a source for wild garlic leaves to try making my own version.

Friday, 13 June 2008

Before You All Get Confused...

Before you all get confused I'd like to point out that I am no longer in Marrakech. In fact I was only there for three days. The problem is that whenever I go away I end up with more to blog about than time allows and so I continue posting when I get back. So I still have plenty of posts to write about Marrakech as well as about our honeymoon.

Just to prove that I am back here is the page from my passport showing both the entry and exit stamps from Morocco. These are only the second set of stamps I've managed to collect in my passport -- the first set being from my trip to Budapest back in 2003.

Tuesday, 3 June 2008

Shopping in the Souks

Of course no trip to Marrakech would be complete without a shopping trip in the Souks.


Apparently the Souks are divided up into named sections based on what is sold there. I spotted a number of signs (two of which you can see above) naming a section but I couldn't work out what was being sold -- my guide book didn't list these names and everywhere you look almost everything you could think of is being sold anyway.

I did do some shopping (an interesting experience when nothing has a price on it) but I'll leave that for another time.