Code written by Iain
If for any reason it isn’t entirely obvious, none of this code comes with any warranty of any kind. Unless stated otherwise, code is copyright Iain Murray and may be redistributed under the GPL (version 2 or 3). If you ask me, I’ll probably agree to a simpler more permissive license.
Matlab / Octave utilities
Updated Nov 2009: I’ve bundled up some of the Matlab/Octave utility functions that I’ve written: imurray-matlab-1.028.tar.gz, browse, Contents.m. They’re simple functions that at some point I thought were general enough to warrant copying out of whatever project directory I was working in at the time.
I also have a collection of potentially-missing or replacement functions for people without certain toolboxes, or (older versions of) Octave.
If you are interested in neat Matlab utility functions, I recommend Tom Minka’s lightspeed Matlab toolbox. (Personally I’ve stuck with an old version of lightspeed, which has a more liberal MIT-style license.)
Fast numerics
I have written mex files to do sum(log(X)) fast and accurately in Matlab. With a bit of tweaking the C code should work elsewhere too. It works by bit-twiddling the IEEE floating point representation, but these days that is pretty portable. The code is reasonably careful to deal with infinities and NaNs correctly. This should be usable as a general, drop-in replacement for sum(log(X)).
Approximate exp for Matlab, two different versions with different time/accuracy/memory tradeoffs. They are written in C and could easily be adapted for use in any environment. They are less recommended than the sum(log(X)) code because the approximations make these routines less safe for general use.
Finally, although not recommended, “Softmax”: C/C++ code to evaluate log(exp(a)+exp(b)) or log(1+exp(-x)) (for x>0) approximately, but more quickly than using standard routines. Uses a bad implementation of a Taylor expansion. Possibly useful somewhere, but I never use this now.
Swendsen–Wang
Swendsen–Wang is a sampling algorithm which is amazing on some Ising model distributions. When I was first working out the details of Swensen–Wang sampling I put a hacked together implementation on the web. I’ve since documented and put up a faster and more general Matlab/mex implementation, although it is still not perfect. The README gives lots more information. You can download an archive containing all of the above: swendsen_wang.tar.gz.
Unsorted / Misc
The following miscellaneous blobs of code are not packaged up very nicely. There’s a small chance something will be useful.
- Derivative with respect to the log of a matrix, from derivatives with respect to the matrix itself. Possibly useful if you want to convert a constrained algorithm into an unconstrained one. Matlab/octave code available for arbitrary and symmetric matrices.
- I’ve written Octave and Matlab wrappers to David MacKay’s macopt, a gradient-only optimiser. The wrappers are on the main site, but will probably require updating to work with recent Octave or Matlab.
- I’ve played a small part in the Dasher project.
- I have reasonable Matlab/Octave code for ML learning for a mixture of multivariate Bernoulli variables using EM. Sadly I can’t put it online as it would help certain cheating students too much, but I’m prepared to share it.
- Slice Sampling, a simple Matlab implementation. A different simple version here. (Neither are exactly what I use, but what I packaged up once.)
- So you read “numerical recipes” but ignored it and do dumb gradient descent in your Matlab/Octave code anyway? “Bold driver” is a reasonable heuristic for picking epsilon that works surprisingly well. On a Gaussian process learning problem I tried it was >10x slower than Carl’s minimize, so use that or macopt (see above).
- Smallest sphere that encloses a bunch of points. This seems to be a standard exercise: can you solve this with a quadratic program? The answer is in the code, but little explanation of where it came from, so I doubt I’m helping students much. See Convex Optimization, Stephen Boyd and Lieven Vandenberghe.
Miscellaneous scripting hacks:
Before running any of these take a quick look at the source and see if it is what you want. I take no responsibility for any damage, some of these (eg rmx) are potentially very dangerous!
- google_viewer.user.js a user
script that makes links to pdfs on all websites appear
like this
— the original link to the PDF is left unchanged, the added icon allows you to view the document in Google’s online viewer. You can just click the script to install in Google Chrome (version 4.0.249.4) or in Firefox with Greasemonkey. It also works in Opera with manual installation. There are also Greasemonkey equivalents for other browsers.
- utf8_to_ascii.c, utf8_to_ascii.pl or utf8_to_ascii.py: simple programs that take a UTF-8 input stream and spits out an ASCII version that will be equivalent as part of an HTML or XML document. The ASCII version will be less efficient, but might be easier or safer to deal with. You can convert back with ascii_to_utf8.py or ascii_to_utf8.pl. For a more powerful solution try the command-line tools that come with uni2ascii.
- eps2fixedbb — add a tight bounding box to eps files (uses gs).
- fai — concise shell loops.
- latex2png — poor man’s tex2im or dvi2bitmap.
- mutt2gmailcsv — mutt mail alias exporter for gmail.
- mycal — wrapper around the BSD cal command so it’s more friendly.
- ncat — cat multiple files with headers giving their names.
- rmx — delete everything but specified files.
- sort_executables — recursively reset executable bit of file permissions to a sensible guess. Useful if you have copied files from a FAT file system.
- snaffle webpage hierarchies. This is just a wrapper to wget using the options I like to take a mirror of a sub-branch of a webserver.
- untar — this is a wrapper around utilities for unpacking archives in many formats. It tries to unpack into an intelligent place, not splurging many files into the current directory and not clobbering existing files without your permission. See comments inside the script for more detail. This script has not been that extensively tested. As with everything here, use at your own risk and inspect the source yourself. If you were used to it, you can get the old version, which behaved a bit differently.
- renameall.sh is called by the following to recursively rename all files and directories below the current level: all2lower.sh, all2upper.sh, spaces2hyphens.sh, spaces2underscores.sh. (Nasty code. If/when I rewrite these I'll probably use os.walk in Python.)
- tex.exp — expect wrapper to (pdf)(la)tex, meta(post|font), etc. See the source for how to set it up. Makes the programs stop and quit on first error, and stops “clever” Ctrl-C handing. None of the normal interaction modes seem to do what I want. Apparently recent tetex supports a -halt-on-error option, the version I have installed does not, which used to lead to much cursing, keyboard bashing and deleting files called .log. (I discovered later that maybe I should have trained myself to hit Ctrl-D for end-of-input instead of Ctrl-C).
- A bibtex wrapper.
- docmatlab — takes an Octave/Matlab function definition line from standard input and turns it into a skeleton for comments (example). I call this from my editor. I find having an easy-to-view list of the sizes of everything greatly helps both while writing code and while working out how to call it months later. (Tweaked Jan. 2009 to match Matlab’s documentation style better).
- lsd — drives ls(1) but ignores files, showing only directories.
Obsolete
- Mozex for Firefox 1.5 with UTF-8, for editing web forms with your favourite text editor. None of this was written by me, I just combined two branches of the code. I now use It’s All Text! instead.
- xmms — a wrapper to audacious media player that works around bugs so that I can enqueue or play files from the command-line like I used to with xmms. The bugs have now been fixed in the version of audacious2 that ships with Ubuntu Karmic.
- ps2djvu — wrapper around DjVu libre utilities. It has always been the case that the online service any2djvu did a better job. Now djvudigital has been released, you can run it on your own machine, although due to annoying licensing issues you have to compile the necessary ghostscript driver yourself. Another option that is better than my old shell script is pdf2djvu.
Bad postscript hacks:
- flip.pl — mirroring for transparencies
- flip2.pl — another attempt
- psinvert — invert black and white colors (sometimes)
Quines
Last and definitely least in usefulness, some quine attempts:
- I did these shell scripts a long time ago: quine.sh, quine2.sh, quine3.sh.
- More recently I've got into python. This quite short quine attempts to be “pythonic”, fairly short and clear, while making it shorter seems to involve nasty tricks that make it less clear. Sadly including a #! line and a doc string tends to make things a bit messier
- And here's a nasty Octave/Matlab quine.