Browsing All Posts filed under »python«

Sampling Gamma random variates through the ratio-of-uniforms method

October 9, 2011


One year ago I had the chance to take a class on Monte Carlo simulation with prof. Ion Văduva, and my assignment for the class was to implement exactly what it says in the title of the blog post. I am going to walk you through the idea behind this. General formulation The ratio-of-uniforms is […]

Optimizing Orthogonal Matching Pursuit code in Numpy, part 2

August 11, 2011


EDIT: There was a bug in the final version of the code presented here. It is fixed now, for its backstory, check out my blog post on it. When we last saw our hero, he was fighting with the dreaded implementation of least-angle regression, knowing full well that it was his destiny to be faster. […]

Optimizing Orthogonal Matching Pursuit code in Numpy, part 1

August 7, 2011


After intense code optimization work, my implementation of OMP finally beat least-angle regression! This was the primary issue discussed during the pull request, so once performance was taken care of, the code was ready for merge. Orthogonal matching pursuit is now available in scikits.learn as a sparse linear regression model. OMP is a key building […]

Newton interpolation and numerical differentiation

April 15, 2011


I am sharing some Python code code that I wrote as a school assignment. This computes the Newton form of the interpolation polynomial of a given set of points, and allows for the evaluation of both the polynomial and its derivative, at a given point. This is an accurate way of estimating the derivative of a […]

Tweaking matplotlib subplots for pretty results

April 4, 2011


When plotting multiple subplots using matplotlib, the axes rarely look pretty with the default configuration. Since matplotlib figures are abstract objects, designed for consistency in print as well as on screen, tweaking their layout can get tricky. An example The following code is taken from the face recognition example in scikits.learn: pl.figure(figsize=(1.8 * n_col, 2.4 […]

On setuptools subpackages

April 4, 2011


Today, I spent more than two hours trying to figure out why, despite things working out fine in my development scikits.learn folder, python install would completely ignore the module I refactored into a subpackage. I imagined that simply adding it to the parent __all__ attribute would do, I kind of thought that setuptools […]