February 28, 2009

Look! A python module for learning bayesian network structures has surfaced on the JMLR software track – bits of the author’s blog are quite interesting too… This is article number 5 for the software track in JMLR, and it’s been going over a year now! I suppose 5 examples is quite enough to figure out what’s required for submission here, though, so maybe uptake will improve…


The Pirate Bay Trial

February 28, 2009

So Stina wrote a piece for the independent about the Pirate Bay Trials which reminded me: I’m really upset about the implications of this attack one of the main hubs of the new social order! Just in case  you don’t know, The Pirate Bay is a place for downloading torrent files, which are little files that help you download bigger files from people all over the world. Generally, it’s used for downloading things you’ve not bought, and so helps us in the grand copyright infringement which, apart from making us feel kind of smug and priatey, proves the inefficiency in the market for such digital things and ultimately, hopefully, will change the state of play. See Steal This Film for more info.

Here, I just wanted to link to some coverage of the trial, which is illuminating. There’s Spectrical which is the sort of `official’ coverage, then there’s also TorrentFreak’s coverage which has an especially moving piece about one of the wife of one of the witnesses for the defence being sent a load of flowers. Then there’s also the mainstream coverage in the Guardian, in Cory Doctorow’s column Digital rights, digital wrongs. It all goes to show the lengths people go in order to restrict change. I wonder if I’ll be as motivated as the record companies when something I don’t want to change comes along? Hopefully, at least, I’ll be better informed than these dinosaurs…

Latex, Beamer, Python, Beauty

February 25, 2009

This post quickly shows how to create pretty latex beamer slides, that don’t look anything much like maths seminar slides, and  that can include well formatted (Python) code, as well as the normal stuff that Beamer is so good at (maths, videos, etc). I’m assuming you’ve got a `standard’ install of latex (by standard I mean: like mine) that includes beamer and the listings package. I’m also assuming that you already know how to use beamer, so I’ve not included all the documentclass junk and so on. Here’s a taster of what it looks like, how to do it is after the break:


Read the rest of this entry »

This is a derivation of the forward equations for the Segment HMM to follow on from my last post. Again I should say that this mostly based on Kevin Murphy’s Segment HMM tutorial which you should probably be reading instead of these posts.

Read the rest of this entry »

Segment HMMs

February 21, 2009

I’ve been finding out about segment HMMs. They’re a generalisation of explicit state duration HMMs and a specific case of the hierarchical HMM. I’ll describe them a bit in this post, and then describe the forward algorithm in the next post. Both posts will be culled mostly from Kevin Murphy’s Segment HMM tutorial. All of the errors in this post will be mine, as I’m trying to interpret Kevin’s stuff without using the Dynamic Bayesian Networks, which I’m starting to think is a horrible mistake on my part.

Instead of this post you should probably read a tech report from Cambridge called The Theory of Segmental Hidden Markov Models, which is from the early 90s, and also stuff about hierarchical HMMs, which I think generalise segment HMMs, starting with The Hierarchical Hidden Markov Model: Analysis and Applications by Fine, Singer and Tishby in 1998 and maybe Kevin’s 2001 NIPS paper Linear Time Inference in Hierarchical HMMs.

Read the rest of this entry »

Python Scope Example

February 20, 2009

Wow I just learnt a new thing about Python’s scope! Below are two examples.


x = 1
def foo():
    print x


x = 1
def foo():
    print x
    x = 2

Code snippet number 1 works. It looks up the variable x in its global namespace and prints it. Easy!

Code snippet number 2 breaks on line 3, because there’s an x defined in the function’s local namespace (even though it comes later) and so it knows that x is local and hence barfs when you try to print it before assigning it a value!

Having battled through this in Matlab, doing it the Python way is extremely easy on any platform. One makes use of Mencoder, which we can just call using os.system. Here’s an idiom, culled mostly from the scipy wiki:

from pylab import *
import os
# set the interactive mode of pylab to ON
# opens a new figure to plot into
fig_hndl = figure()
# make an empty list into which we'll append
# the filenames of the PNGs that compose each
# frame.
# filename for the name of the resulting movie
filename = 'animation'
number_of_frames = 100
for t in range(number_of_frames):
	# draw the frame
	# form a filename
	fname = '_tmp%03d.png'%t
	# save the frame
	# append the filename to the list
# call mencoder	
os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 
	-ovc lavc -lavcopts vcodec=wmv2 -oac copy 
	-o " + filename + ".mpg")
# cleanup
for fname in files: os.remove(fname)

Depending on how complicated the plot is, this can take anywhere from a while to ages and ages. It’s good quality, though! You can muck about with the frame rate in the call to encoder where it says fps=10. Change that 10 to something else (30 seems popular!). Also there are probably better codecs than wmv2!

Having written this, it strikes me we could probably do all this in Matlab in the same way, rather than trying to make movies using Matlab’s builtins…