Posts

Generating Data for benchmarking clustering algorithms

Image
As I have been working on some clustering algorithms recently, I invested some time last weekend to refactor some code inside sklearn to generate some toy data sets to visualize the results of clustering algorithms. That looks something like this: While the first two are nice to show off that your algorithm can handle non-convex clusters, these data sets obviously look nothing like the data you'll see in practice. So I wanted to have some a bit more general data set generator. What I ended up doing is a nonparametric mixture of Gaussians. While Gaussians are a bit boring, combining them with a non-parametric prior makes them somewhat more general. As I didn't found some very easy to use package to do that (though David pointed out p ymc ) I went ahead and wrote the generative model down myself. It's a mixture of Gaussians with a Chinese restaurant process as prior for the mixture components and Wishard-Gaussian priors for mean and variance. You can find the ...

Simplistic Minimum Spanning Tree in Numpy [update]

Image
I started working with spanning trees for euclidean distance graphs today. The first think I obviously needed to do was compute the spanning tree. There are MST algorithms in Python, for example in pygraph and networkx . These use their native graph formats, though, which would have meant I'd have to construct a graph from my point set. I didn't see a way on how to do this and set the edge weights without iterating over all edges. That would probably take longer than the computation of the MST, so I decided to do my own small implementation using numpy. This is an instantiation of Prim's algorithm based on numpy matrices. The input is a dense matrix of distances, the output a list of edges. It is not as pretty as I would have hoped but still reasonably short. If any one has suggestions how to make this prettier, I'd love that. [edit] Using line_profiler I had a quick look a the code and made some minor improvements. It's now significantly faster than net...

Changing Python search path - for good. Or: the magic of the 'site' package.

After using Python for about two years now and being a somewhat active developer, I still frequently run into problems with my Python search path. Luckily, I usually have root on the boxes I work on, so I could do some hacks. At the moment, I'm at the IST Austria , where I can use the cluster, but I don't have root. So this time I needed a real solution. Here it goes: The problem is the following: I have some locally installed packages, like scikit-learn and joblib, that are not globally installed. That would be easy enough to solve by setting the PYTHONPATH environment variable in my .profile , pointing to the install location. But I also have newer versions of already installed packages, like IPython. Here, modifying the Python path environment variable doesn't help, as this is appended to the search path. A somewhat hacky solution is to insert your package dir into the search path at the beginning of each script, like so: import sys sys.path.insert(0, "...

Matplotlib Errorbars Weirdness

Some time ago, I was having trouble with using error bars with a legend in matplotlib. I did some hack to fix it that time. Today, I came across the same issue again at the scikit-learn sprint. Obviously this time we wanted to do it right^TM. The problem is that when doing a plot with error bars, the colors in the legend don't correspond to the colors of the lines. The problem seems to be solved in never versions, though. After fiddling a bit with it I found the problem: The errorbars command actually returns a list of artists, corresponding to the lines AND the individual error bars. That seems to really confuse the legend. You can solve the problem by doing errorbar  = pl.errorbars(x, y, err) line = errorbar[0] legend(line, 'the line') taking the zeroth element of the tuple extracts just the line from the collection of artists and everything works out :)

Pascal VOC workshop papers online

One week after ICCV ended, the Pascal VOC workshop papers are online . This is brand new unpublished work and I find it always exciting! The image net workshop does not seem to have any materials online, though. I would be very interested in what Florent Perronnin did with his Fisher vectors this time.

Ask the locals: multi-way local pooling for image recognition

ICCV! In Barcelona! Regrettably, I had to stay home in cold Bonn. Today, I went through the accepted papers, and one of the many I found interesting was "Ask the locals: multi-way local pooling for image recognition" by  Y-Lan Boureau, Nicolas Le Roux, Francis Bach, Jean Ponce and Yann LeCun. Many big names on this one :) In this work the authors highlight a feature of many recent coding algorithms for visual descriptors: locality in the feature space. They formulate the encoding as a maximum pooling operation that is local in an image as well as in features space, by using a coarse k-means clustering on features (that are histograms of sparse codes if I understood correctly). The paper reports very good results on Caltech 101 and 256, and the scenes dataset. In particular, good results are achieved with quite small dictionaries, i.e. of size 256. My colleague Hannes pointed out that the features space binning is basically a layer of an RBF network. Which is not menti...

Random Ramblings on ImageNet

After looking trough ImageNet for a little while now, I found some things that I did not really expect. So here are some properties of ImageNet that I found interesting (even though some of them might be obvious). But first, a quick recap on what ImageNet is: It's a hand annotated dataset, consisting of 10 million images with 10 thousand object classes. The images were collected using search engines and flickr. Classes correspond to "synsets" in WordNet. A synset is a collection of semantically equivalent nouns. For example, there is a synset called 'n04037443' (this is the IMID, the image net id), which corresponds to the nouns 'racer, race car, racing car' and is described as 'a fast car that competes in races'. The synsets in WordNet have an additional hierarchical structure, given by a directed graph. Going down the graph goes from more general concepts to more specific concepts. For example 'mammal' is above 'canine' whi...