Useful links:

Code to reproduce our published results

Interfacing Gnuplot with OCaml


Requirements: UNIX, Gnuplot

If you use OCaml for scientific/research purposes, you may have been disappointed by the absence of a plotting facility. There is a great scientific plotting tool called Gnuplot, which I found was easy to interface with OCaml using pipes. You can download my Gnuplot module here. The philosophy was really to keep this module as simple as possible. The only thing this module does is make sure your data buffers are transmitted to Gnuplot (it basically writes them into files, but you can directly pipe them too). The rest is just you sending command strings to Gnuplot. This means you can really do everything that Gnuplot allows for, as long as you've read the Gnuplot manual. For example:

let x = Array.init 1000 float
let y = (fun z ->
  sin (2. *. 3.1415 *. z /. 200.)) x
let _ =
  let f = Gp.figure () in
  Gp.send ["set xlabel 'foo'"; "set ylabel 'bar'"] f;
  Gp.send ["set title 'my first plot'"] f;
  Gp.plot [[x,y],"w lines ls 7"] f;
  Gp.close f

There is a shortcut for quick data plotting:

let _ = Gp.quick (Gp.plot [[x,y],"w lines ls 7"])

I often use

set term epslatex standalone solid color \
  font '\sfdefault,10' \
  header '\usepackage[scaled]{helvet}'
set output 'plot.tex'

as my gnuplot terminal, which allows me to integrate LaTeX formulas in the plot. This produces two files: plot.tex and plot-inc.eps. I wrote a little script to combine the two of them, resulting in both an eps and a pdf file. You can download it here, and compile it with

ocamlopt -o gp2pdf

Then to use it:

gp2pdf plot.tex

which produces plot.pdf.

GPU programming on ATI hardware

In order to speed up some computations on ATI graphics cards, I wrote some basic OCaml bindings to Brook+, a high-level language that describes the flow of data and computations to and from the ATI hardware. I used it successfully in my Frontiers paper (see Publications) to accelerate the computation of information theoretic quantities. If you are interested, please do send me an email, I'll package it. Be aware though that OpenCL has now replaced Brook+ in the official ATI GPU framework.