The Summer of Jeff

Python Code for Tennis Markov

Posted in programming, tennis by Jeff on January 13, 2011

I’ve published my code for the tennis markov project.  You can find it here:

  • Single game outcome. Takes the server’s probability of winning a single point and the current score, returns server’s chance of winning game.
  • Tiebreak outcome. Takes server’s probability of winning a single service point, prob of winning single return point, and current score, returns server’s chance of winning tiebreak.
  • Single set outcome. Takes server’s probability of winning a single service point, prob of winning single return point, and current game score, returns server’s chance of winning set. (Assumes standard tiebreak set.)
  • Match outcome. Takes server’s probability of winning a single service point, prob of winning single return point, current score in points, games, and sets, and number of sets, returns server’s chance of winning match.

The logic in the tiebreak problem is knotty, and the code reflects that; I’m sure there’s a better way of doing it, I just didn’t feel like working it out once I got to the answer.

In the other functions, the code is pretty clean, and I’ve commented it more than I otherwise would.  The math gets a little hairy, though.

Advertisements

3 Responses

Subscribe to comments with RSS.

  1. David Pinto said, on January 13, 2011 at 5:42 pm

    I’m glad to see someone else doing sports research in Python!

  2. Mr. Red said, on January 14, 2011 at 3:29 am

    I’ve started messing around with Python after your recommendation in “Python for baseball.” However, I can’t seem to find a free Python IDE that I really like. What do you use?

    Thanks,
    Mr. Red

    • Jeff said, on January 14, 2011 at 3:20 pm

      I use IDLE, which is part of the standard python download. I’m easy to please, though.


Comments are closed.

%d bloggers like this: