- 2018 Midterm 3
- 2018 Midterm 3 Solutions
- 2018 Midterm 2
- 2018 Midterm 2 Solutions
- 2018 Midterm 1
- 2018 Midterm 1 Solutions
- 2017 Midterm 3
- 2017 Midterm 3 Solutions
- 2017 Midterm 2
- 2017 Midterm 2 Solutions
- 2017 Midterm 1
- 2017 Midterm 1 Solutions
- 2016 Midterm 3
- 2016 Midterm 3 Solutions
- 2016 Midterm 2
- 2016 Midterm 2 Solutions
- 2016 Midterm 1
- 2016 Midterm 1 Solutions
- 2015 Midterm 2
- 2015 Midterm 2 Solutions
- 2015 Midterm 1
- 2015 Midterm 1 Solutions
Although this course is language agnostic, we will use Julia to demonstrate various algorithms. It is a high-level language for scientific computing that provides exceptional run-time performance, approaching that of statically-compiled languages like C. The software is free and open source and is under active development. Julia 1.0 was recently released!
If you are already familiar with MATLAB, R, or Python, see this list of notable differences.
There are many ways to get going with Julia. Here are some options:
- Install Julia on your own machine. You can download and install the command line version or a version that is bundled with the Juno IDE.
- All you need to do is ssh into rice.stanford.edu to access the shared computing environment. The default version of Julia available on the machines is 0.5. To use the latest Julia 1.0, first load the Julia module and check the version. You can then save it to be the default:
$ module load julia $ julia --version julia version 1.0.0 $ module save
- Run Julia in the cloud on JuliaBox. You will want to make sure to back up your code to a Google Drive folder or a Git repository to reduce the risk of losing your work. Also, be sure not to exceed 500MB, otherwise your older files will be lost.
- You can use the Vocareum terminal (where you will submit your Projects) to run Julia. However, due to the way it is set up, you may not be able to add Julia packages with the package manager. We have already installed all packages needed for the projects; if you still need other packages installed and are having trouble adding them from your terminal, let Shushman know.
Note: Please be sure you are using Julia version 1.0.x!
Using Julia Packages
Julia’s base installation already comes with several handy packages for containers, linear algebra, random number generation, and the like. The
Base features are directly usable in the REPL while for the Standard Library, you need to import individual stdlib packages in the REPL with
julia> using LinearAlgebra and so on. Check the left-hand pane of the docs for the list of features under Base and under Standard Library. For any further packages, you will have to add them separately. You can use the Package manager (which is part of stdlib) by doing
julia> using Pkg; Pkg.add("XYZ") or by pressing
] in the REPL to go to package manager mode directly and doing
] add XYZ, where
XYZ is the name of some registered package. It is unlikely you will need to install unregistered packages, but if so, check here for more instructions or ask us in office hours.
Local Installation of Course Notebooks
To install the course software on your local machine, complete the steps outlined here.
Note: Throughout this section, lines beginning with
julia> should be run in the Julia REPL. If anything goes wrong, see Troubleshooting below.
- Install Julia 1.0: Instructions
- To install Jupyter, Start Julia, invoke the package manager
IJulia. Run the following lines:
julia> using Pkg
Alternatively, you can go directly into Package Manager mode from the REPL with the
]key and do
] add IJulia
- Download and unzip the aa228-notebook directory: aa228-notebook-archive.zip (or use
gitto clone the sisl/aa228-notebook repository)
- In Julia, run the install script to install all dependencies, replacing
$PATH_TO_AA228_NOTEBOOKwith the path to the aa228-notebook directory.
- Run jupyter in the aa228-notebook directory
julia> using IJulia julia> notebook(dir="$PATH_TO_AA228_NOTEBOOK")
- In Julia, run the install script to install all dependencies, replacing
Note: Since the last iteration of this course, Julia has updated to 1.0 with a different package management system. Some of you may have issues installing! Please come to office hours if so.
Potential fixes for things that could go wrong.
Problems installing jupyter
First, check to see if IJulia was able to install it.
julia> Pkg.add("IJulia") will download the IJulia Julia package, and, if you do not already have jupyter, this will automatically install it via miniconda via the Conda.jl package.
To test the installation, in Julia, run
julia> using IJulia julia> notebook()
This should open a jupyter notebook browser in the current directory. If this doesn’t work, jupyter may not be installed correctly.
If you are using Windows and you get the message
failed to create process, it is likely that you have spaces in the file path (if you are in this situation please contact Jayesh at firstname.lastname@example.org so I can verify that these instructions are correct). Check to see if there are any spaces in the path returned by
julia> Pkg.dir(). If there are, one workaround is to install Miniconda in a path that does not have spaces:
- Install miniconda with python 3.6 from here. Make sure to select install for all users. This should install miniconda in a directory like
- Install the required jupyter python package. In the windows command prompt, run the following command:
conda install jupyter
- Close all command prompts and restart julia so that the environment is updated with the new miniconda installation, and rebuild IJulia:
- Start the notebook with the following command in a command prompt:
jupyter notebookand try creating a new Julia 0.6 notebook.
Note: If you use this workaround, you may need to manually install dependencies for other packages (such as
conda instead of from within julia, and you may have to notify julia of your Anaconda installation with
julia> ENV["PYTHON"]="C:\\Miniconda3\\python.exe; Pkg.build("PyCall").
HDF5 build error when installing BayesNets.jl from
HDF5 is a data storage library (the same that is used in Matlab’s .mat files). Julia should automatically download and install the library, but you may need to do it manually. More instructions are at the HDF5.jl repo – Ubuntu:
sudo apt-get install hdf5-tools
Bayesian network graph visualizations do not display correctly in notebooks
- If text is displayed without an image – TikzGraphs.jl or one of its dependencies may not be installed correctly. Try reinstalling it.
- If only edges are displayed or node labels do not display correctly – Use the google-chrome browser. Firefox and other browsers may not display the svgs correctly.
PGFPlots/SVG conversion errors when running notebooks
If you get an error similar to
Error saving as SVG could not spawn `pdf2svg tikzpicture.pdf tikzpicture.svg`: no such file or directory (ENOENT)
You need to have
pdf2svg installed on your machine. If on OSX, run:
brew install pdf2svg
sudo apt-get install pdf2svg
If on Windows, download this: https://github.com/jalios/pdf2svg-windows/archive/master.zip. Extract the zip file where you want to keep it. Then add the directory inside called “dist-64bits” to your path. Instructions on how to do this can be found here.
And make sure that you add pdf2svg to your path, regardless of your platform, so that you can run “pdf2svg” from the terminal.
If you get an error similar to:
Error saving as SVG could not spawn `lualatex --enable-write18 --output-directory=. tikzpicture`: no such file or directory (ENOENT)
then you do not have tex plotting capabilities. To get plotting to work, we recommend installing texlive (either through your package manager on linux [texlive-extra-utils on ubuntu] or from https://www.tug.org/texlive/quickinstall.html) or from https://www.tug.org/texlive/acquire-netinstall.html.