The goal of this first exercise is get you up and programming in Clojure in a very short period of time. The installation instructions that follow cover installing the software required to complete the first three homework assignments
The goal of the first three assignments is to get you comfortable programming in Clojure and Anglican, and, more importantly, have an idea about with how to program in probabilistic programming languages in general. The first assignment reviews functional Programming and introduces Clojure syntax.
Complete the worksheets
exercises/worksheets/intro-to-clojure/01-clojure-overview.clj
and
exercises/worksheets/intro-to-clojure/02-clojure-exercises.clj
in this repository. Follow the installation instructions below to get started.
This assignment is not graded.
Anglican is a probabilistic programming language that compiles to Clojure which subsequently compiles to JVM bytecode. For this reason
you need the Java and Clojure ecosystems installed on either your own personal computer or on a
machine into which you can ssh
, and, in the latter case, to which you can open socket (http) connections.
Clojure depends on having a recent Java Development Kit installed. Windows and Mac OS X users can download Java DK installers from here (version 8u73 is fine). Linux users who do not already have Java installed can install from their package managers:
# Debian/Ubuntu
sudo apt-get install default-jdk
# Fedora
sudo yum install java-1.7.0-openjdk
Leiningen is a self-installing automated Clojure project management system. You must install Leiningen from http://leiningen.org/. lein
(short for Leiningen) is a self installing script as well as the primary means
of invoking both Anglican and Clojure read eval print loops (REPL). Fortunately
lein
is trivial to install in Unix environments (see below).
Note that Leiningen version $>$2.x is required; the version in GNU-Linux package repositories may be quite a bit out of date.
The following sequence of commands will, by-in-large, install and make lein
runnable on your system. For Unix experts the particulars are obvious and simply involve downloading and running a shell script.
# Download lein to, e.g., ~/bin
mkdir ~/bin
cd ~/bin
wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
# Make executable
chmod a+x ~/bin/lein
# Add ~/bin to path
# Note: Mac OS X users should replace ".bashrc" with ".profile"
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Run lein
lein
Windows users have it just as easy. They just can use the Leiningen installer, which installs the latest version of Leiningen.
The exercises themselves can be cloned from a BitBucket repo (requires a BitBucket accounts):
https://bitbucket.org/probprog/ppaml-summer-school-2016}
When you have managed to do all this successfully then, in effect, you will have a Leiningen (Clojure) project with a set of web-based Gorilla REPL notebooks sitting locally on your machine. Within it you should try to start a web-based, Anglican-enabled Gorilla REPL.
# replace "ppaml-summer-school-2016" with name of the unzipped directory
# containing the exercises
cd ppaml-summer-school-2016/exercises
lein gorilla :port 8990
which will start a web service on port 8990 which allows you to view, edit, and run
the different Anglican example programs. Users installing on a server will instead run lein gorilla :ip 0.0.0.0
If it says “Could not reserve enough space…,”” no worries. Just reduce the amount of the memory for the heap by modifying the appropriate line in /project.clj
to something like this:
:jvm-opts ["-Xmx1g" "-Xms1g"]
Use a web browser (Chrome, e.g.) to open http://localhost:8990/worksheet.html. Using the menu on the top right you should be able to open and interactively run the exercises, using the “Load a worksheet” command.
Start by completing the specified worksheets.