MGL

Common Lisp machine learning library by Gabor Melis with some parts
contributed by Ravenpack International. Implements:
- Restricted Boltzmann Machines and Deep Belief Networks
- Semi Restricted Boltzmann Machines
- Boltzmann Machines
- Backprop networks
- Unrolling DBN to backrop network
- Contrastive Divergence, Persistent Contrastive Divergence
- Gradient descent optimization
- Conjugate gradient optimization

It's under the MIT licence. See COPYING.


* Tests

Run the built in tests with:

  (ASDF:OOS 'ASDF:TEST-OP '#:MGL)

Note, that most of the tests are rather stochastic and can fail once
in a while.


* Matlisp

If Matlisp is loaded, MGL takes advantage of it which speeds things up
by a factor of 2-4. Matlisp may be loaded at any time, before or after
MGL. In src/matlisp/ there is a very small Lisp implementation of some
of the Matlisp functionality to allow operation without Matlisp. This
implementation was largely ripped from the true Matlisp distribution
with trivial modifications.


* Installing BLAS

Installing BLAS can be a pain. For example, on my Debian Lenny desktop
machine with sbcl I did this to get BLAS:

First you need to install a BLAS implementation. Don't bother with the
fortran reference implementation, it's slower than the lisp code.
Install the platform specific atlas or mkl (not free) package.
Compiling atlas locally can be a big gain in some cases.

On my Debian Lenny I compiled the ATLAS from source like this:

  # apt-get install gfortran
  # echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  $ cd ATLAS
  $ mkdir build-f95-dyn
  $ cd build-f95-dyn/
  $ ../configure -Fa alg -fPIC
  $ make
  $ cd lib
  $ make ptshared
  $ cd ..
  $ make ptcheck
  $ make time


* Installing Matlisp

Get Matlisp:

  cvs -d:pserver:anonymous@matlisp.cvs.sourceforge.net:/cvsroot/matlisp login
  cvs -z3 -d:pserver:anonymous@matlisp.cvs.sourceforge.net:/cvsroot/matlisp \
      co -P matlisp

If you have the stock sse2 package of ATLAS then configure it as:

  ./configure --with-atlas=/usr/lib/sse2/ --with-lisp=sbcl --prefix=`pwd`

or 

  ./configure --with-atlas=/home/mega/ATLAS/build-f95-dyn/lib/ \
              --with-lisp=sbcl --prefix=`pwd` \
              --with-lisp-exec='sh /home/mega/lisp/sbcl/run-sbcl.sh'

in my case. You may also have to use --with-f77=gfortran or something
similar. On a suse system, I had to set FFLAGS to '-fPIC -g -O2'
before configure and edit matlisp.mk to add -fPIC to the compile flags
for dlamch.f else ld could not link it the dynamic lib. Oh, and
sometimes loading of matlisp.so fails with a complaint about __powidf2
in which case you either downgrade to autonconf2.59 and run it at the
top of the source tree or simply add -lgcc_s to FLIBS in matlisp.mk or
matlisp.mk.in.

Edit the generated lib/lazy-loader.lisp:

  #+:sbcl
  (defun load-blas-&-lapack-libraries ()
    (sb-alien:load-shared-object "/usr/lib/sse2/libatlas.so.3")
    (sb-alien:load-shared-object "/usr/lib/sse2/libcblas.so.3")
    (sb-alien:load-shared-object "/usr/lib/sse2/libf77blas.so.3")
    (sb-alien:load-shared-object "/usr/lib/sse2/liblapack_atlas.so.3")
    (sb-alien:load-shared-object "matlisp:lib;libmatlisp.so"))

for me it was:

  #+:sbcl
  (defun load-blas-&-lapack-libraries ()
    (sb-alien:load-shared-object
    "/home/mega/ATLAS/build-f95-dyn/lib/libatlas.so")
    (sb-alien:load-shared-object
    "/home/mega/ATLAS/build-f95-dyn/lib/libptcblas.so")
    (sb-alien:load-shared-object
     "/home/mega/ATLAS/build-f95-dyn/lib/libptf77blas.so")
    (sb-alien:load-shared-object
    "/home/mega/ATLAS/build-f95-dyn/lib/liblapack.so")
    (sb-alien:load-shared-object "matlisp:lib;libmatlisp.so"))

or if you have MKL:

  (defun load-blas-&-lapack-libraries ()
    (sb-alien:load-shared-object
     "/home/mega/intel/mkl/10.2.2.025/lib/32/libmkl_core.so")
    ;; The threaded lib makes sbcl die, use the sequential one.
    #+nil
    (sb-alien:load-shared-object
     "/home/mega/intel/mkl/10.2.2.025/lib/32/libiomp5.so")
    #+nil
    (sb-alien:load-shared-object
     "/home/mega/intel/mkl/10.2.2.025/lib/32/libmkl_gnu_thread.so")
    (sb-alien:load-shared-object
     "/home/mega/intel/mkl/10.2.2.025/lib/32/libmkl_sequential.so")
    (sb-alien:load-shared-object
     "/home/mega/intel/mkl/10.2.2.025/lib/32/libmkl_gf.so")
    (sb-alien:load-shared-object "matlisp:lib;libmatlisp.so"))

although it was unexpectedly slower than atlas.

Build Matlisp:

  $ make

finally load matlisp/start.lisp.