{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Machine Learning and Statistics for Physicists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Material for a [UC Irvine](https://uci.edu/) course offered by the [Department of Physics and Astronomy](https://www.physics.uci.edu/).\n", "\n", "Content is maintained on [github](github.com/dkirkby/MachineLearningStatistics) and distributed under a [BSD3 license](https://opensource.org/licenses/BSD-3-Clause).\n", "\n", "##### ► [View course table of contents](Contents.ipynb)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Prerequisites" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- [Create a github account](https://github.com/join) if you don't already have one.\n", "- [Download](https://git-scm.com/downloads) and install the git command-line tools on your computer, if necessary.\n", "- [Download](https://www.anaconda.com/download/) and install the current python 3.x version of the [anaconda distribution](https://www.anaconda.com/distribution/) on your computer, if necessary.\n", "\n", "> Notes that are indented like this provide additional details on more advanced topics.\n", "\n", "> If you already have an older version of anaconda installed that you want to keep, the instructions below create a new environment that should not disrupt your previous work and you can probably continue with the instructions below after running:\n", "```\n", "conda update conda\n", "```\n", "\n", "This course assumes a basic familiarity with the core python language. If you are rusty or still learning, I recommend the free ebook [A Whirlwind Tour of Python](https://www.oreilly.com/programming/free/files/a-whirlwind-tour-of-python.pdf), which is *\"a fast-paced introduction to essential components of the Python language for researchers and developers who are already familiar with programming in another language\"*.\n", "\n", "> If you are currently using python 2.x and reluctant to move to python 3, read [this](https://wiki.python.org/moin/Python2orPython3) and [this](http://www.python3statement.org/).\n", "\n", "No previous experience with git or github is necessary for this course (but they are useful research tools so worth learning - [here](https://guides.github.com/introduction/git-handbook/) is a good starting point). If you are finding the git learning curve to be steep, you are [not alone](https://explainxkcd.com/wiki/index.php/1597:_Git)." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Install course material" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Clone the course material from github with the following command, which will create a subdirectory called :\n", "```\n", "git clone https://github.com/dkirkby/MachineLearningStatistics.git\n", "```\n", "\n", "> This command may prompt you for your github username and password but you can streamline future [github access using ssh](https://help.github.com/articles/which-remote-url-should-i-use/).\n", "\n", "You should now have a subdirectory called `MachineLearningStatistics`. Enter it for the remaining steps:\n", "```\n", "cd MachineLearningStatistics\n", "```\n", "Any instructions below that assume you are in this subdirectory will be prefaced with the shell comment:\n", "```\n", "# cd MachineLearningStatistics/\n", "```" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Create the course python environment" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will use the [conda command](https://conda.io/docs/commands.html) to create a standard [python environment](https://conda.io/docs/user-guide/tasks/manage-environments.html) for this course." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new environment using the following command at a shell prompt:\n", "```\n", "# cd MachineLearningStatistics/\n", "conda env create -f environment.yml\n", "```\n", "This command may run for several minutes.\n", "\n", "> We are using python version 3.8 for this environment which, as of Apr 2021, is the anaconda default.\n", "\n", "Activate the new environment using (this should add \"(MLS)\" to your command prompt, as a reminder of your current environment):\n", "```\n", "conda activate MLS\n", "```\n", "\n", "> To \"deactivate\" this enironment and return to your default base environment, use:\n", "```\n", "conda deactivate\n", "```\n", "\n", "> Older versions of conda used a [different syntax](https://conda.io/docs/user-guide/tasks/manage-environments.html#activating-an-environment) to activate and deactivate an environment.\n", "\n", "Install the [tensorflow](https://www.tensorflow.org/) machine-learning framework:\n", "```\n", "pip install tensorflow\n", "```\n", "\n", "> This pip command will only install tensorflow into your MLS environment (since it uses a version of pip that is local to the MLS environment).\n", "\n", "> If you are installing onto a linux or windows system with a [CUDA-enabled GPU card](https://www.tensorflow.org/install/gpu), use instead:\n", "```\n", "pip install tensorflow-gpu\n", "```\n", "\n", "Install the [pytorch](https://pytorch.org/) machine-learning framework. The exact command is different for Mac and linux/windows. On a Mac, use:\n", "```\n", "conda install pytorch torchvision -c pytorch\n", "```\n", "On a windows or linux system, use:\n", "```\n", "conda install pytorch torchvision cpuonly -c pytorch\n", "```\n", "\n", "> See [here](https://pytorch.org/get-started/locally/) for alternate install commands for a linux or windows system with a CUDA-enabled GPU card.\n", "\n", "Install the [jax](https://jax.readthedocs.io/en/latest/notebooks/quickstart.html) machine-learning framework:\n", "```\n", "pip install jax jaxlib\n", "```\n", "\n", "> See [here](https://github.com/google/jax#pip-installation) to install on a system with a CUDA-enabled GPU card.\n", "\n", "Enable a jupyter notebook [extension](https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/exercise2) we will use for in-class exercises:\n", "```\n", "jupyter nbextension enable exercise2/main\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> In case something goes wrong with your installation and you want to start again, shutdown any jupyter sessions with the old environment, then use:\n", "```\n", "conda deactivate\n", "conda remove --name MLS --all\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, install the course code and data into your new environment using:\n", "```\n", "# cd MachineLearningStatistics/\n", "pip install .\n", "```" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Launch notebook server" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To launch the [notebook server](http://jupyter-notebook.readthedocs.io/en/stable/notebook.html) at any time, you can now use:\n", "```\n", "# cd MachineLearningStatistics/\n", "conda activate MLS\n", "cd notebooks\n", "jupyter notebook\n", "```\n", "\n", "> We are not using the newer [JupyterLab](https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906) since it is [not compatible with notebook extensions](https://github.com/ipython-contrib/jupyter_contrib_nbextensions#jupyterlab).\n", "\n", "Click on `Contents.ipynb` if this is your first time doing this, to check that you can view a notebook.\n", "\n", "These instructions allow you to modify and run python code on your local computer from within your browser. If you just want to view these notebooks online, try this [nbviewer link](https://nbviewer.jupyter.org/github/dkirkby/MachineLearningStatistics/tree/master/notebooks/)." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Update course material" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can skip this section if you are installing MLS for the first time.\n", "\n", "These instructions are only needed in case you need to update your local version of the MLS files, to synchronize with a change on github.\n", "\n", "> For git experts: you will normally be working on the master branch to simplify the workflow. This means that your local work must be discarded or saved to another branch each time you update, using the instructions below.\n", "\n", "The first step is to \"factory reset\" your installation before getting the updates. The simplest method is to throw away any changes you have made using:\n", "```\n", "# cd MachineLearningStatistics/\n", "git checkout master\n", "git reset --hard\n", "```\n", "Alternatively, you can keep a permanent record of your changes in a [git branch](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell) with a name of your choice, for example \"08-Jan-2021\":\n", "```\n", "# cd MachineLearningStatistics/\n", "git checkout -b \"08-Jan-2021\"\n", "git commit -a -m \"Save work in progress\"\n", "git checkout master\n", "```\n", "\n", "The second step is to download the changes from github:\n", "```\n", "# cd MachineLearningStatistics/\n", "git pull\n", "```\n", "If this commands reports `Already up-to-date.` then there are no updates to download.\n", "\n", "The final step is to update your local python environment:\n", "```\n", "# cd MachineLearningStatistics/\n", "conda activate MLS\n", "pip install . --upgrade\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 2 }