A nifty little election time dynamic program

Oct 22, 2008 22:43

Take a look at xkcd's election predictor. It scrapes a bunch of election outcome probabilities per state from intrade and uses them to provide a prediction for the overall election. It does so by using a Monte Carlo simulation, given the probabilities, it runs a mock election assuming each state outcome is independent a whole bunch of times with ( Read more... )

election, algorithms, xkcd, dynamic programming

Leave a comment

Comments 12

Randall Monroe? anonymous October 23 2008, 08:46:10 UTC
His name is Munroe. Randall Monroe is the guy in the Geek Hero Webcomic http://geekhero.iovene.com/

Reply


Nitpickery mgedmin October 23 2008, 09:52:24 UTC
list objects do not have a 'sorted' method in Python. You want sorted(l).

The original code tried to put the largest number first. Your code puts it last. You want sorted(l, reverse=True).

Reply

Re: Nitpickery ru_linux_geek October 23 2008, 13:14:52 UTC
Nice catch, and I thought I tested it before submitting! I shouldn't edit code in the LJ interface.

Reply


malaprop October 23 2008, 12:28:20 UTC
There are not 50 races in the electoral college, there are 57. You've both left out DC and the fact that Maine and Nebraska split up their electoral votes.

If you're interested in solid Monte-Carlo analysis, you probably can't do better than 538.

Reply

ru_linux_geek October 23 2008, 13:20:02 UTC
I read 538 often. There is another high quality electoral analysis site here, http://election.princeton.edu/.

This site uses an algorithm similar to the one I described, but (maybe?) a bit faster and more complicated. From their FAQ.

In general, the probability distribution for all possible outcomes is given by the coefficients of the polynomial

((1 - P1) + P1 * x^EV1) * ((1 - P2) + P2 * x^EV2) * … * ((1 - P51) + P51 * x^EV51)

Reply

malaprop October 26 2008, 02:00:01 UTC
Right, this is a standard application of generating functions.

-Chris

Reply


larrytc October 23 2008, 21:25:07 UTC
This is a 250 in TC. Haha.

Reply

ru_linux_geek October 23 2008, 21:29:34 UTC
They have 250s with DP and probability now? I think it would be more like a 500.

Reply

larrytc October 24 2008, 00:38:43 UTC
It's gotten harder and harder.. =P

Reply

larrytc October 29 2008, 14:47:25 UTC
Oh ya, as a side note, once on an interview a few years ago, I was given a simple problem to solve. Right off the bat, I knew the answer, so I was like "ya, so you would use dynamic programming on this one". To which the interviewer replied "so, how would you program this dynamically?"

Go figure.

Reply


Leave a comment

Up