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 me and may be redistributed under the GPL. If you ask me I’ll probably agree to other license terms.
The following miscellaneous blobs of code are not packaged up very nicely. There’s a small chance something will be useful.
- New (July 2008): I’ve packaged up some Matlab/Octave utility functions that I’ve written. Read Contents.m to see what’s available. They’re simple functions, but fairly reusable and reasonably carefully implemented.
- I’ve written Octave and Matlab wrappers to David MacKay’s macopt, a gradient-only optimiser. Probably suffering from bit-rot, as I haven’t tested with recent Octave or Matlab.
- 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. In a couple of years when things work more reliably you may want to convert back with ascii_to_utf8.py or ascii_to_utf8.pl. For a more powerful solution see uni2ascii (ignore the ugly GUI, the command-line tools are good).
- OLD: Mozex for Firefox 1.5 with UTF-8, for editing web forms with your favourite text editor. None of this is written by me, I just combined two existing versions and am hosting the result.
- “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. This is a quick and dirty first stab, it’s really pretty horrible, and not greatly recommended.
- 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.
- 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.
- 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.
- Slice Sampling, a simple Matlab implementation. I like Skilling’s computer-friendly slice sampling, but I haven’t gotten around to coding it up, or wrapping his C code.
- 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.
- “Swendsen Wang” auxilliary variable sampling is amazing on Ising models. I haven’t wrapped my C code for this. This Matlab code is from when I first played with the algorithm. It works (very very slowly) on binary systems with positive and/or negative pairwise connections. If you haven’t seen this algorithm in action you might want to give it a go counting iterations (rather than time) and get a better implementation.
- mvnrnd.m multivariate normal random variates in Octave/Matlab. Thanks to Paul Kienzle this is now part of octave-forge. Lots of comments suitable for students. Doesn’t support all the same options as mvnrnd in the Matlab stats toolbox. If you want this sort of thing I’d hunt out Tom Minka’s lightspeed Matlab toolbox. (Personally I’ve stuck with an old version of lightspeed, which has a more liberal MIT-style license.)
- plus_diag/ trivial Matlab functions I refer to on my Matlab/Octave tricks page.
- unique_totals.m simple vectorized Matlab/Octave function to return a set of unique positions along with the sum of values associated with each position. (New: slight performance improvement Feb. 2008).
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! I use Bourne-like shells (too much), perl (less so now), expect (for driving other programs easily), and python (which I like a lot).
- 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.
- ps2djvu — wrapper around DjVu libre utilities if any2djvu is unavailable. Another option is to use djvudigital, but due to annoying licensing issues you have to compile the necessary ghostscript driver yourself.
- 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.
- 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). Unless I have an easy-to-view list of the sizes of everything I go insane. I currently call this from my editor, although feel that I should use a better, easier-to-update documentation solution, which should also test the dimensions as documented.
- lsd — drives ls(1) but ignores files showing only directories.
Bad postscript hacks:
- flip.pl — mirroring for transparencies
- flip2.pl — another attempt
- psinvert — invert black and white colors (sometimes)
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.