set up of homework projects

This commit is contained in:
mhjensen
2018-08-27 17:23:51 +02:00
parent dd5e7bb8df
commit 930ffb34fa
10 changed files with 1268 additions and 123 deletions
+111 -2
View File
@@ -5,8 +5,117 @@ DATE:Today
===== Exercise 1 =====
Make sure you have installed all necessary t
The first exercise here is of a mere technical art. We want you have installed
* git as a version control software and to establish a user account on a provider like GitHub. Other providers like GitLab etc are equally fine. You can also use the University of Oslo "GitHub facilities":"https://www.uio.no/tjenester/it/maskin/filer/versjonskontroll/github.html".
* Install various Python packages
We will make extensive use of Python as programming language and its
myriad of available libraries. You will find
IPython/Jupyter notebooks invaluable in your work. You can run _R_
codes in the Jupyter/IPython notebooks, with the immediate benefit of
visualizing your data. You can also use compiled languages like C++,
Rust, Fortran etc if you prefer. The focus in these lectures will be
on Python, but we will provide many code examples for those of you who
prefer R or compiled languages. You can integrate C++ codes and R in for example
a Jupyter notebook.
If you have Python installed (we recommend Python3) and you feel
pretty familiar with installing different packages, we recommend that
you install the following Python packages via _pip_ as
o pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
For _Tensorflow_, we recommend following the instructions in the text of
"Aurelien Geron, HandsOn Machine Learning with ScikitLearn and TensorFlow, O'Reilly":"http://shop.oreilly.com/product/0636920052289.do"
We will come back to _tensorflow_ later.
For Python3, replace _pip_ with _pip3_.
For OSX users we recommend, after having installed Xcode, to
install _brew_. Brew allows for a seamless installation of additional
software via for example
o brew install python3
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution,
you can use _pip_ as well and simply install Python as
o sudo apt-get install python3 (or python for pyhton2.7)
If you don't want to perform these operations separately and venture
into the hassle of exploring how to set up dependencies and paths, we
recommend two widely used distrubutions which set up all relevant
dependencies for Python, namely
* "Anaconda":"https://docs.anaconda.com/",
which is an open source
distribution of the Python and R programming languages for large-scale
data processing, predictive analytics, and scientific computing, that
aims to simplify package management and deployment. Package versions
are managed by the package management system _conda_.
* "Enthought canopy":"https://www.enthought.com/product/canopy/"
is a Python
distribution for scientific and analytic computing distribution and
analysis environment, available for free and under a commercial
license.
We recommend using _Anaconda_.
===== Exercise 2 =====
===== Exercise 3 =====
We will generate our own dataset for function $y(x)$ where $x \in [0,2]$ and defined by random numbers computed with the uniform distribution. The function $y$ is a quadratic polynomial in $x$ with added stochastic noise according to the normal distribution $\cal {N}(0,1)$.
The following simple Python instructions define our $x$ and $y$ values (with 100 data points).
!bc pycod
x = np.random.rand(100,1)
y = 5*x*x+0.1*np.random.randn(100,1)
!ec
o Write your own code (following the examples under the "regression slides":"https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression-bs.html" for computing the parametrization of the data set fitting a second-order polynomial.
o Use thereafter _scikit-learn_ (see again the examples in the regression slides) and compare with your own code.
o Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error or loss defined as
!bt
\[ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n}
\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2,
\]
!et
and the $R^2$ score function.
If $\tilde{\hat{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as
!bt
\[
R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2},
\]
!et
where we have defined the mean value of $\hat{y}$ as
!bt
\[
\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
\]
!et
Discuss the meaning of these results. Try also to vary the coefficient in front of the added stochastic noise term and discuss the quality of the fits.
===== Exercise 3, variance of the parameters $\beta$ in linear regression =====
Show that the variance of the parameters $\beta$ in the linear regression method (chapter 3, equation (3.8) of "Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer":"https://www.springer.com/gp/book/9780387848570") is given as
!bt
\[
mathrm{Var}(\hat{\beta}) = \left(\hat{X}^T\hat{X}\right)^{-1}\sigma^2,
\]
!et
with
!bt
\[
\sigma^2 = \frac{1}{N-p-1}\sum_{i=1}{N} (y_i-\tilde{y}_i)^2,
\]
!et
where we have assumed that we fit a function of degree $p-1$ (for example a polynomial in $x$).
+6 -94
View File
@@ -1,100 +1,12 @@
TITLE: Project 1 on Machine Learning, deadline October 1
TITLE: Homework 1
AUTHOR: "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo, Norway
DATE: May 2018
DATE:Today
===== Regression analysis and classification =====
===== Exercise 1 =====
=== Introduction ===
Make sure you have installed all necessary t
===== Exercise 2 =====
=== Part a): The data ===
===== Background literature =====
===== Introduction to numerical projects =====
Here follows a brief recipe and recommendation on how to write a report for each
project.
* Give a short description of the nature of the problem and the eventual numerical methods you have used.
* Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.
* Include the source code of your program. Comment your program properly.
* If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
* Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.
* Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.
* Try to give an interpretation of you results in your answers to the problems.
* Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.
* Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
===== Format for electronic delivery of report and programs =====
The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:
* Use Devilry to hand in your projects, log in at URL:"http://devilry.ifi.uio.no" with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.
* Upload _only_ the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.
* In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
* In this and all later projects, you should include tests (for example unit tests) of your code(s).
* Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
Finally,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. You can then hand in a common report.
===== Software and needed installations =====
If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
we recommend that you install the following Python packages via _pip_ as
o pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow
For Python3, replace _pip_ with _pip3_.
See below for a discussion of _tensorflow_ and _scikit-learn_.
For OSX users we recommend also, after having installed Xcode, to install _brew_. Brew allows
for a seamless installation of additional software via for example
o brew install python3
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use _pip_ as well and simply install Python as
o sudo apt-get install python3 (or python for python2.7)
etc etc.
If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely
o "Anaconda":"https://docs.anaconda.com/" Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system _conda_
o "Enthought canopy":"https://www.enthought.com/product/canopy/" is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
Popular software packages written in Python for ML are
* "Scikit-learn":"http://scikit-learn.org/stable/",
* "Tensorflow":"https://www.tensorflow.org/",
* "PyTorch":"http://pytorch.org/" and
* "Keras":"https://keras.io/".
These are all freely available at their respective GitHub sites. They
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing.
===== Exercise 3 =====