Monty Hall anyone?

Ξ November 23rd, 2012 | → 1 Comments | ∇ Coding, Geeky, Maths, Programming, Research |

I won’t detail the so called ‘Monty Hall Problem‘ here: if you don’t know about it already, you’ll find more detail (than you’d probably like) here.

Anyway, the MHP is one of my favourite Conditional Probability problems (I’m a lecturer in this branch of mathematics) as it’s a nice example of how computing – via a Monte Carlo Simulation – is useful in testing such a hypothesis (by the way, Monty has no relation to Monte).

And so .. to code! Now, I’m no expert in Python, and so please feel free to abbreviate/re-write/deride this effort at writing a simulation: I’m using Python with a version >3 here.

As it is, this effort  plays 10,000 ‘games’ – and its default strategy is that the player always chooses to swap doors. To change that to having the player stick with their original door, comment out this line by prefixing it with a ‘#’.

    (playerDoor, ) = list(set(doors) - set([playerDoor, hostDoor])

Here’s to code (copy it to a file called monty.py. Once you’ve python installed, run it using python monty.py)

import random
def playGame(carsWon):
    doors = [1,2,3]
    carDoor = random.choice(doors) playerDoor = random.choice(doors)
    # The host opens a different door to reveal a goat (always able to do this).
    hostDoor = random.choice(list(set(doors) - set([carDoor, playerDoor])))
    # ~~~~ To stick, just comment out the next line of real code with a #
    # ~~~~ Player chose to swap doors.
    (playerDoor, ) = list(set(doors) - set([playerDoor, hostDoor])
    if playerDoor == carDoor: carsWon += 1
    return carsWon
# The program's entry point is here.
carsWon = 0
for games in range(1000): carsWon = playGame(carsWon)
print("The player won the car " + str(round(carsWon / (games / 100))) + "% percent of the time.")

I must say that, even though I know more or less nothing about Python, it’s a succinct language.

Anyone fancy coding this in something like ML, Haskell or Scala?  I’m too embarrassed to post my versions here!

 

QSL Blast from the Past

Ξ March 14th, 2011 | → 0 Comments | ∇ Geeky, Programming, Radio |

Someone just sent me a copy of my old QSL card – from 1983.  It’s really nice to have an image of it as it was drawn by my older brother.

G4SFI’s QSL card from 1983

Me – in the shack!

 

This was also in around 1983 – thus the rather trendy shirt!  The computer is a Tatung Einstein – which I had a little to do with (as did the ‘silent key’, Roy Clarke, G8AYD)

 

Dead MacBook Pro Anyone?

Ξ February 16th, 2011 | → 0 Comments | ∇ Geeky, Programming |

Seen The Social Network (sure you have).  Remember that scene where Eduardo Saverin (Andrew Garfield) smashes Mark Zuckerberg’s (Jesse Eisenberg) MacBook Pro?  Fake machine – right (like in Ikea)?

One down, n to go ...

Well, I was watching the bonus DVD yesterday and was amazed to see that the laptop was most likely real (the machines display blue screens (lol); as you can see in the shot above – the content is digitally inserted during post-production?).  Now note that the director was David (n > 2x takes) Fincher – so there wasn’t just one MacBook smashed…

Part of a 'pan' around the graveyard

Part of a ‘pan’ shot showing the dead Macs

Another part of the 'pan' around the graveyard

Continuing on – the fade-through can’t be helped (sorry).

Close-up of one of the dead

Close-up – I wonder what the yellow/black tape is for – ‘this one doesn’t work anymore’?

At one point someone asks (I think it’s probably Fincher) ‘how many more do we have’, to which the reply is ‘I think we have quite a lot’.  Nice.

 

Editors!

Ξ January 10th, 2011 | → 0 Comments | ∇ Mumble |

I’ve been pondering editors lately, and how crude they still are.  For example, that all the web authoring tools that I know of/use essentially require you to textually specify your css styles.  Why can’t you, say, colour the color[sic] of some style in, um, the colour you’d like?

E.g., h1 { color; } instead of using #f5a323 or whatever?

And I’m sure there’s lively debate on this somewhere – why use different syntax in css files and html files? Or, if you really have to, why not have your wizzy development tool manage that for you, e.g., you write <h1> in your stylesheet, and *it* converts this to h1{color:#ff0000; } – or actually, why not just write h1?  Or why edit a stylesheet at all – create a truly intelligent editor that you just *write* in!  You use whatever tools it provides to create your page(s), and *it* not *you* works out what’s a style and should go in your css.  For example, most web-developers don’t use tables any more – they use divs instead. Ok, why not *still* insert a table in your document, and have your intelligent editor implement it as a set of divs?  It seems to me that if you have to edit the code that the tools aren’t up to the job (remember, you’re only creating a document for goodness sake)!

Shouldn’t web-development (page design/layout) be as simple as Word Processing is in Word? Think about it – it’s been a very long time since we’ve had to mark up our documents (goodbye Wordstar), and I wonder how long it will be until we find ourselves doing the same for the web.

Maybe it’s me, and I’m just not using the tools correctly? For example, I note that Microsoft’s Expression Web 4 has, in design view (html or wysiwyg), extra panels to create and apply styles – and it’s got a wysiwyg look.  But, you know what; I reckon if I start playing about with those that it’ll end in grief!  An ‘old dog’ indeed – or perhaps a wise one?

Of course, one of the problems is the browser!  As in how each does its own thing when it comes to layout … you can see how Word – being in sole control of how ‘Word things look’ has a relatively easy time of it.  So, before I get back to editors, this leads me on to another question that’s been nagging me for years: why don’t we have one rendering engine?

Imagine the likes of Microsoft, Google Mozilla getting together to jointly develop a single rendering engine; and not just them – why not have that an open group, that any interested party could join.  The result and aim would be to create a single parser and rendering engine that renders exactly the same on devices with the same capabilities (colour depth, pixel count etc).  I’ve never understood why this hasn’t (yet) happened – I mean, haven’t you seen all that …

<!–[if IE 6]>
<script src=”/javascript/ie6.js” type=”text/javascript”></script>
<![endif]–>
<link rel=”stylesheet” type=”text/css” href=”/css/front/themes/root.css” />
<!–[if IE 6]>
<link rel=”stylesheet” type=”text/css” href=”/css/front/ie.css” />
<![endif]–>
<!–[if IE 7]>
<link rel=”stylesheet” type=”text/css” href=”/css/front/ie7.css” />

<![endif]–>

… and that’s just for Microsoft!  Doesn’t it a) annoy you, b) cause you a lot of work?  Fact: there’s over 3.5 million Google results for browser detection

And anyway – why do the likes of Google, Microsoft and Mozilla (want to) spend gazillions of dollars doing their own thing, and then give the product away for free?  Yes, competition is great, but it’s not (currently) like Word – a cash cow product.  Why not join forces – give us a single standard browser, save yourselves heaps of cash, and make web development much simpler?

But back to editors, as it’s not just web editing tools that annoy me. I spend most of my time editing code – *real* code; you know, C++ etc. Now, here’s a question – why can’t I put what’s referred to as ‘rich content’ in my code?  For example, say you’ve coded up an algorithm that you first designed and then documented using a mixture of pictures, words and perhaps a small test harness.  Why shouldn’t you embed these into your live code – so that the documentation is stored with the actual implementation?  Could be there as a link; could optionally be unfolded in-line … a picture is worth a thousand words!

We’ve only recently got a folding editor in Microsoft’s Visual Studio – and I remember seeing my first one of those over 25 years ago.  How long before code editors catch-up to the likes of Microsoft’s Word: insert a table, picture, footnotes, … whatever makes your own and your colleaques’ life easier.

 

No Country for Old BBC Programmes

Ξ December 11th, 2009 | → 1 Comments | ∇ Mumble |

I love the way the web allows you to arrive at a page, and then [sans the ‘Back Button’] find yourself wondering how on Earth you got here!

I had a moment like that just now, and arrived at a YouTube video of Derek Jacobi playing Alan Turing in a BBC drama called ‘Breaking the Code’ – here’s the link.

I well remember seeing this when it first came out in 1996. It was great, won prizes, and was nominated for two BAFTAs – according to Wikipedia that is, and I found myself wondering why I hadn’t got this on DVD?

Now here’s the ‘what!’ – it’s not available!  How can the BBC not have something this good available!  How?

Actually, this is the second time in a few days that has seen me asking that same question; the first was when I went searching for another great programme, that Nigel Calder made for the BBC in 1979, it was called ‘Einstein’s Universe’.  Featuring the Wonderful Peter Ustinov, and near light-speed motor-cycles – it was just wonderful!  Alas, it’s also not available.  Actually, I did find it on Amazon.com, but why oh why isn’t it available *here*; from the BBC?

I’m now suffering from deja, vu as I’m sure I’ve travelled this road many a time now – great programmes, probably all or most coming from the BBC [paid for by me in other words] and yet gone and seemingly forgotten (care to jog my memory?)  What a drag.

 

 

Wolfram|Alpha

Ξ June 5th, 2009 | → 1 Comments | ∇ Software, Technical, Writing |

Thought it might be interesting to post these here. A two part article on Wolfram|Alpha I did for Computer Weekly [WARNING: may contain traces of coin tossing references].

Here’s a pdf of the first bit, and here’s a link to the edited version on Computer Weekly’s website.

And – wait for it …

Here’s a pdf of the second bit, and here’s a link to the edited version on Computer Weekly’s website.

Just in case you do compare the version, I should add that I did some minor edits after they were sent in.

 

Not Much Use – IMHO!

Ξ May 14th, 2009 | → 1 Comments | ∇ Geeky |

I’ve been doing a little free web-development for some pals of mine, and, in the course of that, trying to get their website towards the top of all search-engines’ results.

So I was interested when a few days ago they had a call from a company that claimed that given a few keywords, they could guarantee to get them at the top of Google’s search results.

Hmmm, interesting!

When I told my pals that I doubted the credibility of such a claim [I got starry-eyed stares when I tried to explain to them the why of this], I thought I’d best have a look at what this company was offering.

In a nutshell, this company has got a Google AdWords account, and in using it, they will, for a few pounds, place you at the top of a Google search – you know, in those ‘Sponsored Link’ bits.

Ok, so what’s the problem with that?

1.

Well they’re charging £20 per month – which is just enough to have most people say ‘well it’s not that much’ [and sign-up], yet either over or under what placing a top-result will actually cost you.

If you don’t know, Google ads ‘pay’ [Google] and ‘cost’ [you] whenever someone clicks them.  How much?   It depends upon a figure that you’ll have to agree with Google [it depends upon other bidders], and that fits within your budget – so here we’re talking about £20 per month apparently.

So what if you spend all your budget?  Well, you disappear from the results … rather, you slide to the place where Google’s PageRank algorithm would normally place you [which may be nowhere of course!]

So this company hopes that to place you will cost maybe a penny per click, and that for your 20 quid they’ll have some left over at the end of the month to pocket for themselves [that’s 2,000 people clicking through – so they probably will!].  But what if you go ‘over budget’?   Well, I assume they’ll either get you to stump up a bit more, or simply hope that you don’t notice your sudden disappearing act!

2.

Who clicks ads?

Well, there must be a lot of people that do, because that’s Google main source of revenue I believe!

Personally however, I rarely click them – for one thing, they’re mostly sat off to the right-hand side of the search results, so I don’t see them [I assume that the best payers are the ones that appear at the top of the search results – rather than towards the right-hand side].

But the main reason I don’t click them is because Google’s PageRank works very well, i.e., websites that rank highly via PageRank are normally worth looking at – as they’re effectively being voted for by others that link to them [see the link I just used above – well, according to Google, I’ve just voted for the webpage that explains PageRank].   However, is that true when someone pays to get themselves at the top of the results?  Probably not!  After all, if they were actually first-rate – worth looking at – wouldn’t they get there by themselves – through their own merit, osmosis – call it what you will? I think so.

The result is that the more savvy person will often not rate/trust a paid-for link – or at least not as much as one that makes it to the top through its own merit.

3.

Who will see the advert/link?

Well, maybe lots of people/maybe no one:

You’ll see it if:

  1. the paying customer’s monthly budget hasn’t been used up when you conduct your search;
  2. IF – and only if – you use Google!

Yup – no one will see it it they don’t use Google – perhaps they use Yahoo, or some other search-engine [Ask.com, A9.com, Live.com, …] – no-Google = no-Where to be seen.

 

More Probability – HTH vs. HTT

Ξ May 8th, 2009 | → 5 Comments | ∇ Maths, Oxford |

Imagine tossing a fair coin successively, and waiting until the first time a particular pattern appears; say HTT. For example, if the sequence of tosses was HHTHHTHHTTHHTTTHTH, the pattern HTT would first appear after the 10th toss.

Ok, now let’s take two such patterns – HTT and HTH.  Given both these sequences, and a lot of trials [where you conduct this, “it first appears when” experiment, and then average the number of tosses], is it more likely that you’ll:

  • hit HTT in less tosses than HTH;
  • hit HTH in less tosses than HTT;
  • find that the number of tosses is the same?

Most people [many mathematicians amongst them] will pick the third option.  Surely, any such pattern is equally likely to show up in some yet to be discovered average number of tosses!

Actually, it’s not the case – that they’re equally likely. In reality the average number of tosses required to see HTH is 10, whilst for HTT it’s 8! How can that be???

Let’s see why.

Note that HTH overlaps itself, i.e., if you got HTHTH you’ll find that you’ve got two occurrences of the pattern in only five tosses, i.e., HTHTH and HTHTH. Ah, so doesn’t this sound like HTH is more likely then, rather than the other way around?

Well, with HTT there isn’t such an overlap – and it turns out – perhaps unintuitively – that that’s important; in a way that leads to HTH‘s downfall. So, let’s run a couple of experiments to see how this works.

Let’s go looking for HTH

Best scenario:

Toss Result Comment
H 1st token in our pattern excellent start!
T 2nd token quite excited!
H 3rd token We won!


Second best scenario:

Toss Result Comment
H 1st token in our pattern excellent start!
T 2nd token quite excited!
T Bugger!


Now we’ll need to continue tossing the coin until we see an H; as that’s the first token in our sought-after sequenc



Now let’s go looking for HTT

Best scenario:

Toss Result Comment
H 1st token in our pattern excellent start!
T 2nd token quite excited!
T 3rd token We won!


Second best scenario:

Toss Result Comment
H 1st token in our pattern excellent start!
T 2nd token quite excited!
H/H Bugger!


However, and this is the important bit, at this stage we don’t need to toss the coin again in order to get to find our starting token – we just threw it – an H!



If you doubt any of this, here’s a little simulator I wrote [CoinToss.zip contains CoinToss.exe].

 

21 – Blackjack Movie

Ξ May 6th, 2009 | → 1 Comments | ∇ Books, Geeky, Maths, Oxford |

Watched 21 last night – not a bad film, in fact, regarding entertainment vs. cost value [it ran us just £3 from Matalan!] it was rather good.

The film is based upon the MIT Blackjack team, and as I’ve read/and-seen quite a lot about them before, I was quite happy to have the film thicken the plot [maybe that should be ‘have one’?] – and there’s a nice twist or two at the end.  As to the film’s inspiration, you can’t do much better than watch the BBC Horizon documentary on this:

Making Millions the Easy Way

I wish ‘Oxford types’ would get up to stuff like this [of course, they might do (would they tell their lecturers?)]; it’d be so much more fun!

Probability

I was quite pleased to see some probability stuff in the film being partially explained, i.e., their running through the Monty Hall problem [although the implied cleverness of the student here is a bit hard to swallow really].

Anyway, here’s the problem:

Suppose you’re on a game show, and you’re given the choice of three doors:  Behind one door is a car; behind the other two, goats.  You pick a door, say number 1, and the host, who knows what’s behind all of the doors, always opens another door – to reveal a goat – let’s say that’s door number 3.  He then says to you, “Do you want to swap?”, i.e., swap your initial choice of door number 1, and change to door number 2?   The crux being – is it to your advantage to swap?

In the film, the problem is presented in this clip.  By the way, the answer is in this too, so if you want to think about it, get ready to hit the pause button at the 44s mark!

The explanation I find that works quite well here [and I’ve had my Oxford stats students scratching their heads over this problem initially (as do most people I believe)] is:

Given this scenario: when you pick a door, you’re more likely to pick a goat-door than sole car-door, i.e., you’ve a probability of .66 [or 66% chance if you prefer] of picking one of the two goat-doors vs. the only car-door.  Hopefully, that’s obvious.

So, if chance [substitute luck of the draw/fate/the odds/divine-intervention …] did the right thing here, and you picked a goat-door, you know with a decent probability that the car is behind one of the two remaining doors – but which one?  Now, when the host reveals another goat behind one of the two remaining doors, the car’s obviously [again, if the odds etc worked for your initial pick] behind the other door!

Basically, it comes down to this: if you picked a goat-door initially [which you will 66% of the time], by swapping later, you’ll always win the car.  Conversely, and given once again that you initially picked a goat-door, if you don’t swap, you’ll lose 66% of the time.  Or, one other way … by swapping, you’ll only lose if you picked the sole car-door as your first pick [which you’re likely not to have done].

 

XBox 360 Networking/Internet Access Made Easy

Ξ May 3rd, 2009 | → 4 Comments | ∇ Geeky, Microsoft, Mumble, Rant |

I hate gaming/gamers!  Probably because A) I can’t see the point [read a book, go for a walk, …], and B) because two people I [thought I] knew very well are very sadly addicts – one for The Sims [or practically anything else that might distract them from normality/life], and the other for the World of Warcraft [where she’s a kiss-ass Elf, or some such shite!].  Oh, and C), my twelve-year-old son also plays too much!  Sad individuals indeed.  I truly can’t see the point.

Anyway, rant over, my son received a one month’s free trial on XBox [Saddoes] Live – or some such thing – and asked me if I could get his XBox 360 to connect to the Internet.  As he’s in a room where there’s no wired network point, this meant doing it via a wireless connection.

So, on checking out the various sockets on the back of the 360 box, I tried connecting the thing using a LinkSys USB wireless adapter I had laying around. It didn’t work, and upon further reading, I’m led to believe that one requires a special Microsoft adapter.

That’s the bad news.

Now for the good news … if you’ve a wireless laptop, that also has a wired network-interface, there’s a workaround:

1. Connect your laptop to the Internet, via its built-in wireless;

2. Connect your XBox to your laptop, via a standard network cable [one is supplied with an XBox 360];

3. Bridge the laptop’s wired and wireless connections.

So, here’s the steps I went through on my ThinkPad [with XP installed]:

1. Boot/connect the machine to the network, via its wireless;

2. Connect the XBox to the ThinkPad’s wired network interface using a standard network cable;

3. Open your laptop’s Network Connections [Start | Control Panel | Network Connections];

4. Select both the wireless and wired connections;

5. Right-click on the selected connections, and select Bridge

Here’s the result:

And that was it:  son-networked, playing even more games … hmmmmm – did I do the right thing?

 

Next Page »

Blog Roll


Top BBC Tech News Items