OCaml for Scientists

Chapter 10: Complete Examples

This page contains programs derived from chapter 10 of our book OCaml for Scientists.

In order to compile the programs on this page, you will need to have the OCaml compilers and run-time installed as well as any libraries required by the individual example programs.

Maximum Entropy Method

Extend experimentally-observed diffraction data using the Maximum Entropy Method (MEM).

The program requires the FFTW library to run and the OCaml bindings to FFTW to compile.

Features: Fourier transforms, local minimization and the maximum entropy method.

Download: Source code

Simulated Annealing

Solve the travelling salesman problem using simulated annealing.

The algorithm used by this program exploits functional programming and has better asymptotic complexity than the conventional implementation (e.g. given in Numerical Recipies).

Features: randomized algorithms, global minimization, closures and vector arithmetic.

Download: Source code

Finding nth-nearest neighbours

Compute the set of vertices in the nth-nearest neighbour shell of a given vertex.

This program uses OCaml's purely functional set implementation to solve a set-theoretic recurrence relation succinctly and efficiently.

Features: set-theoretic operations, implicit periodicity and graph theory.

Download: Source code

Matrix Eigenvalue Distribution

Compute the eigenvalue distribution of a random matrix.

In order to compile this program, you must have BLAS and LAPACK installed as well as the LACAML bindings to these libraries.

Features: arrays, matrix computations and random matrix theory.

Download: Source code

Discrete Wavelet Transform

Compute the 1D Haar wavelet transform in only 5 lines of code.

Features: pattern matching and wavelets.

Download: Source code