diff --git a/doc/pub/week34/html/._week34-bs000.html b/doc/pub/week34/html/._week34-bs000.html index 743aee240..6c35019c1 100644 --- a/doc/pub/week34/html/._week34-bs000.html +++ b/doc/pub/week34/html/._week34-bs000.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
-

 

 

 

- - - -
-

Week 34: Introduction to the course, Logistics and Practicalities

+
+

Week 34: Introduction to the course, Logistics and Practicalities

+
-

-

Morten Hjorth-Jensen [1, 2]
- -

+

+[1] Department of Physics, University of Oslo +
+
+[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
+
+
+

Nov 13, 2021

+
+
-
[1] Department of Physics, University of Oslo
-
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
-

-

Oct 12, 2021

-
-

Read »

@@ -412,25 +400,18 @@ MathJax.Hub.Config({
  • »
  • -
    - - -
    © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week34/html/._week34-bs001.html b/doc/pub/week34/html/._week34-bs001.html index 43fdb5828..efd6035d5 100644 --- a/doc/pub/week34/html/._week34-bs001.html +++ b/doc/pub/week34/html/._week34-bs001.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Overview of first week

    -

    -

    - +

    • Wednesday August 25: Introduction to software and repetition of Python Programming
    • Thursday August 26: First lecture: Presentation of the course, aims and content
    • @@ -383,7 +369,6 @@ MathJax.Hub.Config({
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs002.html b/doc/pub/week34/html/._week34-bs002.html index 6000b6d5c..0b781483c 100644 --- a/doc/pub/week34/html/._week34-bs002.html +++ b/doc/pub/week34/html/._week34-bs002.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Reading Recommendations

    -

    -

    -For the reading assignments we use the following abbreviations: - + +

    For the reading assignments we use the following abbreviations:

    • GBC: Goodfellow, Bengio, and Courville, Deep Learning
    • CMB: Christopher M. Bishop, Pattern Recognition and Machine Learning
    • HTF: Hastie, Tibshirani, and Friedman, The Elements of Statistical Learning
    • AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow
    - -Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html +

    Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs003.html b/doc/pub/week34/html/._week34-bs003.html index 2ec093d3b..8175eb6be 100644 --- a/doc/pub/week34/html/._week34-bs003.html +++ b/doc/pub/week34/html/._week34-bs003.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Thursday August 26

    -

    -The lectures will be recorded and updated videos will be posted after the lectures. +

    The lectures will be recorded and updated videos will be posted after the lectures.

    -

    -"Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage

    -

    -Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09 +

    Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09

    +

    Video of Lecture from Fall Semester 2020.

    -Video of Lecture from Fall Semester 2020. - -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs004.html b/doc/pub/week34/html/._week34-bs004.html index 51c8ce86b..1461a98a2 100644 --- a/doc/pub/week34/html/._week34-bs004.html +++ b/doc/pub/week34/html/._week34-bs004.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Lectures and ComputerLab

    -

    -

    - +

    • Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).
    • Weekly reading assignments and videos needed to solve projects and exercises.
    • @@ -384,7 +370,6 @@ MathJax.Hub.Config({
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs005.html b/doc/pub/week34/html/._week34-bs005.html index 7ddfd8d99..61272e1e0 100644 --- a/doc/pub/week34/html/._week34-bs005.html +++ b/doc/pub/week34/html/._week34-bs005.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Announcement

    -

    -NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html +

    NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs006.html b/doc/pub/week34/html/._week34-bs006.html index ba15ac7bc..5ddc25613 100644 --- a/doc/pub/week34/html/._week34-bs006.html +++ b/doc/pub/week34/html/._week34-bs006.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Communication channels

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs007.html b/doc/pub/week34/html/._week34-bs007.html index 54b32c5ca..06097d02c 100644 --- a/doc/pub/week34/html/._week34-bs007.html +++ b/doc/pub/week34/html/._week34-bs007.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Course Format

    -

    -

    - +

    • Three compulsory projects. Electronic reports only using Canvas to hand in projects and git as version control software and GitHub for repository (or GitLab) of all your material.
    • Evaluation and grading: The three projects are graded and each counts 1/3 of the final mark. No final written or oral exam. -
      1. For the last project each group/participant submits a proposal or works with suggested (by us) proposals for the project.
      2. If possible, we would like to organize the last project as a workshop where each group makes a poster and presents this to all other participants of the course
      3. Poster session where all participants can study and discuss the other proposals.
      4. Based on feedback etc, each group finalizes the report and submits for grading.
      -
    • Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and github address of the course.
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs008.html b/doc/pub/week34/html/._week34-bs008.html index 056781ad4..b8618eb6f 100644 --- a/doc/pub/week34/html/._week34-bs008.html +++ b/doc/pub/week34/html/._week34-bs008.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Teachers

    -

    -

    + -

    Teachers : -

    • Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no
    • -
      • Phone: +47-48257387
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ470
      • Office hours: Anytime! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning.
      -
    • Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ452
      -
    • Stian Dysthe Bilek stian.bilek@fys.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ450
      -
    • Linus Ekstrøm, linueks@gmail.com, linus.ekstrom@fys.uio.no
    • Nicholas Karlsen, nicholaskarlsen1102@gmail.com, nicholas.karlsen@fys.uio.no
    • Bendik Steinsvåg Dalen, b.s.dalen@fys.uio.no
    • @@ -405,7 +384,6 @@ MathJax.Hub.Config({
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs009.html b/doc/pub/week34/html/._week34-bs009.html index de2868328..2cbbba9e2 100644 --- a/doc/pub/week34/html/._week34-bs009.html +++ b/doc/pub/week34/html/._week34-bs009.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Deadlines for projects (tentative)

    -

    -

    +

    1. Project 1: October 11 (available September 10) graded with feedback)
    2. -
    3. Project 2: November 15 (available October 12, graded with feedback)
    4. -
    5. Project 3: December 13 (available November 8, graded with feedback)
    6. +
    7. Project 2: November 20 (available October 12, graded with feedback)
    8. +
    9. Project 3: December 17 (available November 13, graded with feedback)
    - -Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas. - -

    +

    Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs010.html b/doc/pub/week34/html/._week34-bs010.html index a998fc406..5a9b808e9 100644 --- a/doc/pub/week34/html/._week34-bs010.html +++ b/doc/pub/week34/html/._week34-bs010.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -
    1. The lecture notes are collected as a jupyter-book at https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html.
    - -In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below. +

    In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below.

    1. Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, https://www.springer.com/gp/book/9780387310732.
    2. Ian Goodfellow, Yoshua Bengio, and Aaron Courville. The different chapters are available for free at https://www.deeplearningbook.org/. Chapters 2-14 are highly recommended. The lectures follow to a larg extent this text. The weekly plans will include reading suggestions from these two textbooks.
    - -Additional textbooks: +

    Additional textbooks:

    1. Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, https://www.springer.com/gp/book/9780387848570. This is a well-known text and serves as additional literature.
    2. Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/. This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course.
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs011.html b/doc/pub/week34/html/._week34-bs011.html index 1729fd337..2d034cd1e 100644 --- a/doc/pub/week34/html/._week34-bs011.html +++ b/doc/pub/week34/html/._week34-bs011.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Prerequisites

    -

    -Basic knowledge in programming and mathematics, with an emphasis on +

    Basic knowledge in programming and mathematics, with an emphasis on linear algebra. Knowledge of Python or/and C++ as programming languages is strongly recommended and experience with Jupiter notebook is recommended. Required courses are the equivalents to the University @@ -377,8 +364,8 @@ of the corresponding computing and programming courses INF1000/INF1110 or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1100. Most universities offer nowadays a basic programming course (often compulsory) where Python is the recurring programming language. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs012.html b/doc/pub/week34/html/._week34-bs012.html index de101ca39..a298b76d1 100644 --- a/doc/pub/week34/html/._week34-bs012.html +++ b/doc/pub/week34/html/._week34-bs012.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Learning outcomes

    -

    -

    + -

    -This course aims at giving you insights and knowledge about many of +

    This course aims at giving you insights and knowledge about many of the central algorithms used in Data Analysis and Machine Learning. The course is project based and through various numerical projects, normally three, you will be exposed to fundamental research problems @@ -386,6 +372,7 @@ Learning is applied to, get acquainted with computing facilities and learn to handle large scientific projects. A good scientific and ethical conduct is emphasized throughout the course. More specifically, after this course you will +

    • Learn about basic data analysis, statistical analysis, Bayesian statistics, Monte Carlo sampling, data optimization and machine learning;
    • @@ -403,7 +390,6 @@ specifically, after this course you will
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs013.html b/doc/pub/week34/html/._week34-bs013.html index 8a599a544..6313d674f 100644 --- a/doc/pub/week34/html/._week34-bs013.html +++ b/doc/pub/week34/html/._week34-bs013.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Topics covered in this course: Statistical analysis and optimization of data

    -

    -The course has two central parts +

    The course has two central parts

    1. Statistical analysis and optimization of data
    2. Machine learning
    +

    These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms

    -These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms - -

    -

    - -

    -We plan to cover the following topics: + +

    We plan to cover the following topics:

    • Basic concepts, expectation values, variance, covariance, correlation functions and errors;
    • Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions;
    • @@ -398,7 +381,6 @@ We plan to cover the following topics:
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs014.html b/doc/pub/week34/html/._week34-bs014.html index 19af70aae..7e9caf178 100644 --- a/doc/pub/week34/html/._week34-bs014.html +++ b/doc/pub/week34/html/._week34-bs014.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Topics covered in this course: Machine Learning

    -

    -

    -The following topics will be covered - + +

    The following topics will be covered

    • Linear Regression and Logistic Regression;
    • Neural networks and deep learning, including convolutional and recurrent neural networks
    • @@ -382,15 +368,11 @@ The following topics will be covered
    • Boltzmann Machines
    • Unsupervised learning Dimensionality reduction, from PCA to clustering
    - -Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics. - -

    +

    Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs015.html b/doc/pub/week34/html/._week34-bs015.html index 3969f450f..8e96e427b 100644 --- a/doc/pub/week34/html/._week34-bs015.html +++ b/doc/pub/week34/html/._week34-bs015.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - - -

    -

    - +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs016.html b/doc/pub/week34/html/._week34-bs016.html index b58c3db49..1be4e5258 100644 --- a/doc/pub/week34/html/._week34-bs016.html +++ b/doc/pub/week34/html/._week34-bs016.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Other courses on Data science and Machine Learning at UiO

    -

    -The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO. +

    The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO.

    1. STK2100 Machine learning and statistical methods for prediction and classification.
    2. @@ -383,7 +370,6 @@ The link here STK4051 Computational Statistics
    3. STK4021 Applied Bayesian Analysis and Numerical Methods
    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs017.html b/doc/pub/week34/html/._week34-bs017.html index 667a4b4e7..85017794f 100644 --- a/doc/pub/week34/html/._week34-bs017.html +++ b/doc/pub/week34/html/._week34-bs017.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Introduction

    -

    -Our emphasis throughout this series of lectures +

    Our emphasis throughout this series of lectures is on understanding the mathematical aspects of -different algorithms used in the fields of data analysis and machine learning. +different algorithms used in the fields of data analysis and machine learning. +

    -

    -However, where possible we will emphasize the +

    However, where possible we will emphasize the importance of using available software. We start thus with a hands-on and top-down approach to machine learning. The aim is thus to start with relevant data or data we have produced @@ -387,24 +374,24 @@ the data and predictions. We move thereafter to more interesting cases such as data from say experiments (below we will look at experimental nuclear binding energies as an example). These are examples where we can easily set up the data and then use machine learning algorithms included in for example -Scikit-Learn. +Scikit-Learn. +

    -

    -These examples will serve us the purpose of getting +

    These examples will serve us the purpose of getting started. Furthermore, they allow us to catch more than two birds with a stone. They will allow us to bring in some programming specific topics and tools as well as showing the power of various Python -libraries for machine learning and statistical data analysis. +libraries for machine learning and statistical data analysis. +

    -

    -Here, we will mainly focus on two +

    Here, we will mainly focus on two specific Python packages for Machine Learning, Scikit-Learn and Tensorflow (see below for links etc). Moreover, the examples we introduce will serve as inputs to many of our discussions later, as well as allowing you to set up models and produce your own data and get started with programming. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs018.html b/doc/pub/week34/html/._week34-bs018.html index f9551796b..ebd53f0fe 100644 --- a/doc/pub/week34/html/._week34-bs018.html +++ b/doc/pub/week34/html/._week34-bs018.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    What is Machine Learning?

    -

    -Statistics, data science and machine learning form important fields of +

    Statistics, data science and machine learning form important fields of research in modern science. They describe how to learn and make predictions from data, as well as allowing us to extract important correlations about physical process and the underlying laws of motion in large data sets. The latter, big data sets, appear frequently in essentially all disciplines, from the traditional Science, Technology, Mathematics and Engineering fields to Life Science, Law, education -research, the Humanities and the Social Sciences. +research, the Humanities and the Social Sciences. +

    -

    -It has become more +

    It has become more and more common to see research projects on big data in for example the Social Sciences where extracting patterns from complicated survey data is one of many research directions. Having a solid grasp of data @@ -393,17 +380,17 @@ in the private or the public sector. This author has had several students or met students who have been hired recently based on their skills and competences in scientific computing and data science, often with marginal knowledge of machine learning. +

    -

    -Machine learning is a subfield of computer science, and is closely +

    Machine learning is a subfield of computer science, and is closely related to computational statistics. It evolved from the study of pattern recognition in artificial intelligence (AI) research, and has made contributions to AI tasks like computer vision, natural language processing and speech recognition. Many of the methods we will study are also -strongly rooted in basic mathematics and physics research. +strongly rooted in basic mathematics and physics research. +

    -

    -Ideally, machine learning represents the science of giving computers +

    Ideally, machine learning represents the science of giving computers the ability to learn without being explicitly programmed. The idea is that there exist generic algorithms which can be used to find patterns in a broad class of data sets without having to write code @@ -411,10 +398,10 @@ specifically for each problem. The algorithm will build its own logic based on the data. You should however always keep in mind that machines and algorithms are to a large extent developed by humans. The insights and knowledge we have about a specific system, play a central -role when we develop a specific machine learning algorithm. +role when we develop a specific machine learning algorithm. +

    -

    -Machine learning is an extremely rich field, in spite of its young +

    Machine learning is an extremely rich field, in spite of its young age. The increases we have seen during the last three decades in computational capabilities have been followed by developments of methods and techniques for analyzing and handling large date sets, @@ -434,8 +421,8 @@ solid command of linear algebra, multivariate theory, probability theory, statistical data analysis, understanding errors and Monte Carlo methods are central elements in a proper understanding of many of algorithms and methods we will discuss. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs019.html b/doc/pub/week34/html/._week34-bs019.html index 396cf0f11..19187ff53 100644 --- a/doc/pub/week34/html/._week34-bs019.html +++ b/doc/pub/week34/html/._week34-bs019.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Types of Machine Learning

    -

    -The approaches to machine learning are many, but are often split into +

    The approaches to machine learning are many, but are often split into two main categories. In supervised learning we know the answer to a problem, and let the computer deduce the logic behind it. On the other hand, unsupervised learning is a method for finding patterns and @@ -377,17 +364,17 @@ Some authours also operate with a third category, namely reinforcement learning. This is a paradigm of learning inspired by behavioral psychology, where learning is achieved by trial-and-error, solely from rewards and punishment. +

    -

    -Another way to categorize machine learning tasks is to consider the +

    Another way to categorize machine learning tasks is to consider the desired output of a system. Some of the most common tasks are: +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs020.html b/doc/pub/week34/html/._week34-bs020.html index c5eb1da2a..f04c01518 100644 --- a/doc/pub/week34/html/._week34-bs020.html +++ b/doc/pub/week34/html/._week34-bs020.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Essential elements of ML

    -

    -The methods we cover have three main topics in common, irrespective of +

    The methods we cover have three main topics in common, irrespective of whether we deal with supervised or unsupervised learning. +

    - - -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs021.html b/doc/pub/week34/html/._week34-bs021.html index fd7a96690..657a546a2 100644 --- a/doc/pub/week34/html/._week34-bs021.html +++ b/doc/pub/week34/html/._week34-bs021.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    An optimization/minimization problem

    -

    -At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods. +

    At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs022.html b/doc/pub/week34/html/._week34-bs022.html index d494a2bd5..142c167a8 100644 --- a/doc/pub/week34/html/._week34-bs022.html +++ b/doc/pub/week34/html/._week34-bs022.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    A Frequentist approach to data analysis

    -

    -When you hear phrases like predictions and estimations and +

    When you hear phrases like predictions and estimations and correlations and causations, what do you think of? May be you think of the difference between classifying new data points and generating new data points. @@ -376,9 +363,9 @@ Or perhaps you consider that correlations represent some kind of symmetric state if \( A \) is correlated with \( B \), then \( B \) is correlated with \( A \). Causation on the other hand is directional, that is if \( A \) causes \( B \), \( B \) does not necessarily cause \( A \). +

    -

    -These concepts are in some sense the difference between machine +

    These concepts are in some sense the difference between machine learning and statistics. In machine learning and prediction based tasks, we are often interested in developing algorithms that are capable of learning patterns from given data in an automated fashion, @@ -387,15 +374,15 @@ assessments of newly given data. In many cases, our primary concern is the quality of the predictions or assessments, and we are less concerned about the underlying patterns that were learned in order to make these predictions. +

    -

    -In machine learning we normally use a so-called frequentist approach, +

    In machine learning we normally use a so-called frequentist approach, where the aim is to make predictions and find correlations. We focus less on for example extracting a probability distribution function (PDF). The PDF can be used in turn to make estimations and find causations such as given \( A \) what is the likelihood of finding \( B \). +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs023.html b/doc/pub/week34/html/._week34-bs023.html index 222050c89..f6bcf30f7 100644 --- a/doc/pub/week34/html/._week34-bs023.html +++ b/doc/pub/week34/html/._week34-bs023.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    What is a good model?

    -

    -In science and engineering we often end up in situations where we want to infer (or learn) a +

    In science and engineering we often end up in situations where we want to infer (or learn) a quantitative model \( M \) for a given set of sample points \( \boldsymbol{X} \in [x_1, x_2,\dots x_N] \). +

    -

    -As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a +

    As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a straight line, or if we wish to be more sophisticated to a more complex function. +

    -

    -The reason for inferring such a model is that it +

    The reason for inferring such a model is that it serves many useful purposes. On the one hand, the model can reveal information encoded in the data or underlying mechanisms from which the data were generated. For instance, we could discover important corelations that relate interesting physics interpretations. +

    -

    -In addition, it can simplify the representation of the given data set and help +

    In addition, it can simplify the representation of the given data set and help us in making predictions about future data samples. +

    -

    -A first important consideration to keep in mind is that inferring the correct model +

    A first important consideration to keep in mind is that inferring the correct model for a given data set is an elusive, if not impossible, task. The fundamental difficulty is that if we are not specific about what we mean by a correct model, there could easily be many different models that fit the given data set equally well. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs024.html b/doc/pub/week34/html/._week34-bs024.html index ef90cd140..745e53e90 100644 --- a/doc/pub/week34/html/._week34-bs024.html +++ b/doc/pub/week34/html/._week34-bs024.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    What is a good model? Can we define it?

    -

    -The central question is this: what leads us to say that a model is correct or +

    The central question is this: what leads us to say that a model is correct or optimal for a given data set? To make the model inference problem well posed, i.e., to guarantee that there is a unique optimal model for the given data, we need to impose additional assumptions or restrictions on the class of models considered. To @@ -381,17 +368,16 @@ with the simplest possible class of models that is just necessary to describe th or solve the problem at hand. More precisely, the model class should be rich enough to contain at least one model that can fit the data to a desired accuracy and yet be restricted enough that it is relatively simple to find the best model for the given data. +

    -

    -Thus, the most popular strategy is to start from the +

    Thus, the most popular strategy is to start from the simplest class of models and increase the complexity of the models only when the simpler models become inadequate. For instance, if we work with a regression problem to fit a set of sample points, one may first try the simplest class of models, namely linear models, followed obviously by more complex models. +

    -

    -How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures. +

    How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs025.html b/doc/pub/week34/html/._week34-bs025.html index 741df9dbe..7d93894f6 100644 --- a/doc/pub/week34/html/._week34-bs025.html +++ b/doc/pub/week34/html/._week34-bs025.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Software and needed installations

    -

    -We will make extensive use of Python as programming language and its +

    We will make extensive use of Python as programming language and its myriad of available libraries. You will find 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, Julia, Fortran etc if you prefer. The focus in these lectures will be on Python. +

    -

    -If you have Python installed (we strongly recommend Python3) and you feel +

    If you have Python installed (we strongly recommend Python3) and you feel pretty familiar with installing different packages, we recommend that you install the following Python packages via pip as +

    1. pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow
    +

    For Python3, replace pip with pip3.

    -For Python3, replace pip with pip3. - -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for pyhton2.7)
    +

    etc etc.

    -etc etc. - -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs026.html b/doc/pub/week34/html/._week34-bs026.html index bcd75fb81..405515819 100644 --- a/doc/pub/week34/html/._week34-bs026.html +++ b/doc/pub/week34/html/._week34-bs026.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Python installers

    -

    -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license. +

    -

    -Furthermore, Google's Colab is a free Jupyter notebook environment that requires +

    Furthermore, Google's Colab is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. Try it out! +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs027.html b/doc/pub/week34/html/._week34-bs027.html index d89241da8..7154383d6 100644 --- a/doc/pub/week34/html/._week34-bs027.html +++ b/doc/pub/week34/html/._week34-bs027.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Useful Python libraries

    -Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there) +

    Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs028.html b/doc/pub/week34/html/._week34-bs028.html index f061e80db..cba01d955 100644 --- a/doc/pub/week34/html/._week34-bs028.html +++ b/doc/pub/week34/html/._week34-bs028.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Installing R, C++, cython or Julia

    -

    -You will also find it convenient to utilize R. We will mainly +

    You will also find it convenient to utilize R. We will mainly use Python during our lectures and in various projects and exercises. Those of you already familiar with R should feel free to continue using R, keeping @@ -378,12 +365,12 @@ notebook allows you to run R codes interactively in your browser. The software library R is really tailored for statistical data analysis and allows for an easy usage of the tools and algorithms we will discuss in these lectures. +

    -

    -To install R with Jupyter notebook +

    To install R with Jupyter notebook follow the link here +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs029.html b/doc/pub/week34/html/._week34-bs029.html index a0a21c458..7bc0becfd 100644 --- a/doc/pub/week34/html/._week34-bs029.html +++ b/doc/pub/week34/html/._week34-bs029.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Installing R, C++, cython, Numba etc

    -

    -For the C++ aficionados, Jupyter/IPython notebook allows you also to +

    For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for either Python or C++ (or Fortran or other compiled languages) as programming languages. +

    -

    -To add more entropy, cython can also be used when running your +

    To add more entropy, cython can also be used when running your notebooks. It means that Python with the jupyter notebook setup allows you to integrate widely popular softwares and tools for scientific computing. Similarly, the @@ -384,22 +371,39 @@ capabilities with minimal rewrites of your codes. With its versatility, including symbolic operations, Python offers a unique computational environment. Your jupyter notebook can easily be converted into a nicely rendered PDF file or a Latex file for -further processing. For example, convert to latex as +further processing. For example, convert to latex as +

    -

    - -

    pycod jupyter nbconvert filename.ipynb --to latex 
    -
    -

    -And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. + +

    +
    +
    +
    +
    +
    pycod jupyter nbconvert filename.ipynb --to latex 
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    -Finally, if you wish to use the light mark-up language +

    And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python.

    + +

    Finally, if you wish to use the light mark-up language doconce you can convert a standard ascii text file into various HTML formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using doconce. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs030.html b/doc/pub/week34/html/._week34-bs030.html index ced6ad896..71571162a 100644 --- a/doc/pub/week34/html/._week34-bs030.html +++ b/doc/pub/week34/html/._week34-bs030.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Numpy examples and Important Matrix and vector handling packages

    -

    -There are several central software libraries for linear algebra and eigenvalue problems. Several of the more +

    There are several central software libraries for linear algebra and eigenvalue problems. Several of the more popular ones have been wrapped into ofter software packages like those from the widely used text Numerical Recipes. The original source codes in many of the available packages are often taken from the widely used software package LAPACK, which follows two other popular packages developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly here. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs031.html b/doc/pub/week34/html/._week34-bs031.html index cb513eadb..51dfd6fb5 100644 --- a/doc/pub/week34/html/._week34-bs031.html +++ b/doc/pub/week34/html/._week34-bs031.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Basic Matrix Features

    -

    -

    + $$ \mathbf{A} = \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ @@ -386,18 +373,16 @@ $$ \end{bmatrix} $$ -

    -The inverse of a matrix is defined by +

    The inverse of a matrix is defined by

    $$ \mathbf{A}^{-1} \cdot \mathbf{A} = I $$ -

    - +
    @@ -411,12 +396,10 @@ $$
    Relations Name matrix elements
    -

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs032.html b/doc/pub/week34/html/._week34-bs032.html index f00965c04..e565e738a 100644 --- a/doc/pub/week34/html/._week34-bs032.html +++ b/doc/pub/week34/html/._week34-bs032.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Some famous Matrices

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs033.html b/doc/pub/week34/html/._week34-bs033.html index cd42cfe65..a72e0ae5e 100644 --- a/doc/pub/week34/html/._week34-bs033.html +++ b/doc/pub/week34/html/._week34-bs033.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    More Basic Matrix Features

    -

    -

    -For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent + +

    For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent

    • If the inverse of \( \mathbf{A} \) exists, \( \mathbf{A} \) is nonsingular.
    • @@ -385,7 +372,6 @@ For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all
    -

      @@ -415,25 +401,18 @@ For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs034.html b/doc/pub/week34/html/._week34-bs034.html index 8c7e2149e..6f4ed5e73 100644 --- a/doc/pub/week34/html/._week34-bs034.html +++ b/doc/pub/week34/html/._week34-bs034.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Numpy and arrays

    -Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as +

    Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as

    -

    -

    import numpy as np
    -
    -

    -Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution, -

    +

    +
    +
    +
    +
    +
    import numpy as np
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution,

    -
    n = 10
    +
    +
    +
    +
    +
    +
    n = 10
     x = np.random.normal(size=n)
     print(x)
    -
    -

    -We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). Another alternative is to declare a vector as follows -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.array([1, 2, 3])
     print(x)
    -
    -

    -Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ start numbering array elements from \( 0 \) and on. This means that a vector with \( n \) elements has a sequence of entities \( x_0, x_1, x_2, \dots, x_{n-1} \). We could also let (recommended) Numpy to compute the logarithms of a specific array as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8]))
     print(x)
    -
    -

    -In the last example we used Numpy's unary function \( np.log \). This function is +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In the last example we used Numpy's unary function \( np.log \). This function is highly tuned to compute array elements since the code is vectorized and does not require looping. We normaly recommend that you use the Numpy intrinsic functions instead of the corresponding log function from Python's math module. The looping is done explicitely by the np.log function. The alternative, and slower way to compute the logarithms of a vector would be to write +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from math import log
     x = np.array([4, 7, 8])
     for i in range(0, len(x)):
         x[i] = log(x[i])
     print(x)
    -
    -

    -We note that our code is much longer already and we need to import the log function from the math module. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We note that our code is much longer already and we need to import the log function from the math module. The attentive reader will also notice that the output is \( [1, 1, 2] \). Python interprets automagically our numbers as integers (like the automatic keyword in C++). To change this we could define our array elements to be double precision numbers as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8], dtype = np.float64))
     print(x)
    -
    -

    -or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x)
    -
    -

    -To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x.itemsize)
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs035.html b/doc/pub/week34/html/._week34-bs035.html index 190e60cef..904bd965d 100644 --- a/doc/pub/week34/html/._week34-bs035.html +++ b/doc/pub/week34/html/._week34-bs035.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Matrices in Python

    -

    -Having defined vectors, we are now ready to try out matrices. We can +

    Having defined vectors, we are now ready to try out matrices. We can define a \( 3 \times 3 \) real matrix \( \boldsymbol{A} \) as (recall that we user lowercase letters for vectors and uppercase letters for matrices) +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     print(A)
    -
    -

    -If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[:,0]) 
    -
    -

    -We can continue this was by printing out other columns or rows. The example here prints out the second column -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can continue this was by printing out other columns or rows. The example here prints out the second column

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[1,:]) 
    -
    -

    -Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to zero
     A = np.zeros( (n, n) )
     print(A) 
    -
    -

    -or initializing all elements to -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or initializing all elements to

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to one
     A = np.ones( (n, n) )
     print(A) 
    -
    -

    -or as unitarily distributed random numbers (see the material on random number generators in the statistics part) -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or as unitarily distributed random numbers (see the material on random number generators in the statistics part)

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to random numbers with x \in [0, 1]
     A = np.random.rand(n, n)
     print(A) 
    -
    -

    -As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. As an example, consider the discussion of the covariance matrix. Suppose we have defined three vectors \( \boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z} \) with \( n \) elements each. The covariance matrix is defined as +

    $$ \boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ @@ -443,13 +534,14 @@ $$ \end{bmatrix}, $$ -where for example +

    where for example

    $$ \sigma_{xy} =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). $$ -The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. +

    The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. The following simple function uses the np.vstack function which takes each vector of dimension \( 1\times n \) and produces a \( 3\times n \) matrix \( \boldsymbol{W} \) +

    $$ \boldsymbol{W} = \begin{bmatrix} x_0 & x_1 & x_2 & \dots & x_{n-2} & x_{n-1} \\ y_0 & y_1 & y_2 & \dots & y_{n-2} & y_{n-1} \\ @@ -457,17 +549,21 @@ $$ \end{bmatrix}, $$ -

    -which in turn is converted into into the \( 3\times 3 \) covariance matrix +

    which in turn is converted into into the \( 3\times 3 \) covariance matrix \( \boldsymbol{\Sigma} \) via the Numpy function np.cov(). We note that we can also calculate the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy function np.mean(x). We can also extract the eigenvalues of the covariance matrix through the np.linalg.eig() function. +

    -

    -

    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     
     n = 100
    @@ -482,11 +578,26 @@ Sigma = np.print(Sigma)
     Eigvals, Eigvecs = np.linalg.eig(Sigma)
     print(Eigvals)
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from scipy import sparse
     eye = np.eye(4)
    @@ -497,8 +608,22 @@ x = np.l
     y = np.sin(x)
     plt.plot(x,y,marker='x')
     plt.show()
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs036.html b/doc/pub/week34/html/._week34-bs036.html index d8797b3ed..a5e61ece4 100644 --- a/doc/pub/week34/html/._week34-bs036.html +++ b/doc/pub/week34/html/._week34-bs036.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Meet the Pandas

    -

    -



    +

    +
    +

    +
    +

    -

    -Another useful Python package is +

    Another useful Python package is pandas, which is an open source library providing high-performance, easy-to-use data structures and data analysis tools for Python. pandas stands for panel data, a term borrowed from econometrics and is an efficient library for data analysis with an emphasis on tabular data. pandas has two major classes, the DataFrame class with two-dimensional data objects and tabular data organized in columns and the class Series with a focus on one-dimensional data objects. Both classes allow you to index data easily as we will see in the examples below. -pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +

    -

    -The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data. +

    The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data.

    -

    -

    import pandas as pd
    +
    +
    +
    +
    +
    +
    import pandas as pd
     from IPython.display import display
     data = {'First Name': ["Frodo", "Bilbo", "Aragorn II", "Samwise"],
             'Last Name': ["Baggins", "Baggins","Elessar","Gamgee"],
    @@ -393,45 +387,115 @@ data = {'Fi
             }
     data_pandas = pd.DataFrame(data)
     display(data_pandas)
    -
    -

    -In the above we have imported pandas with the shorthand pd, the latter has become the standard way we import pandas. We make then a list of various variables +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In the above we have imported pandas with the shorthand pd, the latter has become the standard way we import pandas. We make then a list of various variables and reorganize the aboves lists into a DataFrame and then print out a neat table with specific column labels as Name, place of birth and date of birth. Displaying these results, we see that the indices are given by the default numbers from zero to three. pandas is extremely flexible and we can easily change the above indices by defining a new type of indexing as -

    +

    -
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
    +
    +
    +
    +
    +
    +
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
     display(data_pandas)
    -
    -

    -Thereafter we display the content of the row which begins with the index Aragorn -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Thereafter we display the content of the row which begins with the index Aragorn

    -
    display(data_pandas.loc['Aragorn'])
    -
    -

    -We can easily append data to this, for example -

    +

    +
    +
    +
    +
    +
    display(data_pandas.loc['Aragorn'])
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily append data to this, for example

    -
    new_hobbit = {'First Name': ["Peregrin"],
    +
    +
    +
    +
    +
    +
    new_hobbit = {'First Name': ["Peregrin"],
                   'Last Name': ["Took"],
                   'Place of birth': ["Shire"],
                   'Date of Birth T.A.': [2990]
                   }
     data_pandas=data_pandas.append(pd.DataFrame(new_hobbit, index=['Pippin']))
     display(data_pandas)
    -
    -

    -Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix of dimensionality \( 10\times 5 \) and compute the mean value and standard deviation of each column. Similarly, we can perform mathematial operations like squaring the matrix elements and many other operations. -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     np.random.seed(100)
    @@ -444,13 +508,30 @@ display(df)
     print(df.mean())
     print(df.std())
     display(df**2)
    -
    -

    -Thereafter we can select specific columns only and plot final results -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Thereafter we can select specific columns only and plot final results

    -
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
    +
    +
    +
    +
    +
    +
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
     df.index = np.arange(10)
     
     display(df)
    @@ -468,29 +549,58 @@ plt.show()
     
     df.plot.bar(figsize=(10,6), rot=15)
     plt.show()
    -
    -

    -We can produce a \( 4\times 4 \) matrix -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can produce a \( 4\times 4 \) matrix

    -
    b = np.arange(16).reshape((4,4))
    +
    +
    +
    +
    +
    +
    b = np.arange(16).reshape((4,4))
     print(b)
     df1 = pd.DataFrame(b)
     print(df1)
    -
    -

    -and many other operations. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -The Series class is another important class included in +

    and many other operations.

    + +

    The Series class is another important class included in pandas. You can view it as a specialization of DataFrame but where we have just a single column of data. It shares many of the same features as _DataFrame. As with DataFrame, most operations are vectorized, achieving thereby a high performance when dealing with computations of arrays, in particular labeled arrays. As we will see below it leads also to a very concice code close to the mathematical operations we may be interested in. -For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +

    -

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs037.html b/doc/pub/week34/html/._week34-bs037.html index 637028baf..f26a487d1 100644 --- a/doc/pub/week34/html/._week34-bs037.html +++ b/doc/pub/week34/html/._week34-bs037.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Friday August 27

    -

    -"Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage

    -

    -Video of Lecture from fall 2020 and Handwritten notes +

    Video of Lecture from fall 2020 and Handwritten notes

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs038.html b/doc/pub/week34/html/._week34-bs038.html index e3e6109ac..9fe805d82 100644 --- a/doc/pub/week34/html/._week34-bs038.html +++ b/doc/pub/week34/html/._week34-bs038.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - +

    Simple linear regression model using scikit-learn

    -

    Simple linear regression model using scikit-learn

    +

    We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us.

    -

    -We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us. - -

    -What follows is a simple Python code where we have defined a function +

    What follows is a simple Python code where we have defined a function \( y \) in terms of the variable \( x \). Both are defined as vectors with \( 100 \) entries. The numbers in the vector \( \boldsymbol{x} \) are given by random numbers generated with a uniform distribution with entries @@ -379,9 +365,9 @@ by random numbers generated with a uniform distribution with entries later). These values are then used to define a function \( y(x) \) (tabulated again as a vector) with a linear dependence on \( x \) plus a random noise added via the normal distribution. +

    -

    -The Numpy functions are imported used the import numpy as np +

    The Numpy functions are imported used the import numpy as np statement and the random number generator for the uniform distribution is called using the function np.random.rand(), where we specificy that we want \( 100 \) random variables. Using Numpy we define @@ -390,13 +376,13 @@ our case. With the Numpy function randn() we can compute random numbers with the normal distribution (mean value \( \mu \) equal to zero and variance \( \sigma^2 \) set to one) and produce the values of \( y \) assuming a linear dependence as function of \( x \) +

    $$ y = 2x+N(0,1), $$ -

    -where \( N(0,1) \) represents random numbers generated by the normal +

    where \( N(0,1) \) represents random numbers generated by the normal distribution. From Scikit-Learn we import then the LinearRegression functionality and make a prediction \( \tilde{y} = \alpha + \beta x \) using the function fit(x,y). We call the set of @@ -404,22 +390,26 @@ data \( (\boldsymbol{x},\boldsymbol{y}) \) for our training data. The Python pac scikit-learn has also a functionality which extracts the above fitting parameters \( \alpha \) and \( \beta \) (see below). Later we will distinguish between training data and test data. +

    -

    -For plotting we use the Python package +

    For plotting we use the Python package matplotlib which produces publication quality figures. Feel free to explore the extensive gallery of examples. In this example we plot our original values of \( x \) and \( y \) as well as the prediction ypredict (\( \tilde{y} \)), which attempts at fitting our data with a straight line. +

    -

    -The Python code follows here. -

    +

    The Python code follows here.

    -
    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
    @@ -438,9 +428,22 @@ plt.xlabel(r
     plt.ylabel(r'$y$')
     plt.title(r'Simple Linear Regression')
     plt.show()
    -
    -

    -This example serves several aims. It allows us to demonstrate several +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    This example serves several aims. It allows us to demonstrate several aspects of data analysis and later machine learning algorithms. The immediate visualization shows that our linear fit is not impressive. It goes through the data points, but there are many @@ -448,38 +451,38 @@ outliers which are not reproduced by our linear regression. We could now play around with this small program and change for example the factor in front of \( x \) and the normal distribution. Try to change the function \( y \) to +

    $$ y = 10x+0.01 \times N(0,1), $$ -

    -where \( x \) is defined as before. Does the fit look better? Indeed, by +

    where \( x \) is defined as before. Does the fit look better? Indeed, by reducing the role of the noise given by the normal distribution we see immediately that our linear prediction seemingly reproduces better the training set. However, this testing 'by the eye' is obviouly not satisfactory in the long run. Here we have only defined the training data and our model, and have not discussed a more rigorous approach to the cost function. +

    -

    -We need more rigorous criteria in defining whether we have succeeded or +

    We need more rigorous criteria in defining whether we have succeeded or not in modeling our training data. You will be surprised to see that many scientists seldomly venture beyond this 'by the eye' approach. A standard approach for the cost function is the so-called \( \chi^2 \) function (a variant of the mean-squared error (MSE)) +

    $$ \chi^2 = \frac{1}{n} \sum_{i=0}^{n-1}\frac{(y_i-\tilde{y}_i)^2}{\sigma_i^2}, $$ -

    -where \( \sigma_i^2 \) is the variance (to be defined later) of the entry +

    where \( \sigma_i^2 \) is the variance (to be defined later) of the entry \( y_i \). We may not know the explicit value of \( \sigma_i^2 \), it serves however the aim of scaling the equations and make the cost function -dimensionless. +dimensionless. +

    -

    -Minimizing the cost function is a central aspect of +

    Minimizing the cost function is a central aspect of our discussions to come. Finding its minima as function of the model parameters (\( \alpha \) and \( \beta \) in our case) will be a recurring theme in these series of lectures. Essentially all machine learning @@ -492,30 +495,34 @@ employed are various variants of gradient methods. These will be discussed in more detail later. Again, you'll be surprised to hear that many practitioners minimize the above function ''by the eye', popularly dubbed as 'chi by the eye'. That is, change a parameter and see (visually and numerically) that -the \( \chi^2 \) function becomes smaller. +the \( \chi^2 \) function becomes smaller. +

    -

    -There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define +

    There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define the relative error (why would we prefer the MSE instead of the relative error?) as +

    $$ \epsilon_{\mathrm{relative}}= \frac{\vert \boldsymbol{y} -\boldsymbol{\tilde{y}}\vert}{\vert \boldsymbol{y}\vert}. $$ -

    -The squared cost function results in an arithmetic mean-unbiased +

    The squared cost function results in an arithmetic mean-unbiased estimator, and the absolute-value cost function results in a median-unbiased estimator (in the one-dimensional case, and a geometric median-unbiased estimator for the multi-dimensional case). The squared cost function has the disadvantage that it has the tendency to be dominated by outliers. +

    -

    -We can modify easily the above Python code and plot the relative error instead -

    +

    We can modify easily the above Python code and plot the relative error instead

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
     
    @@ -531,26 +538,44 @@ plt.xlabel(r
     plt.ylabel(r'$\epsilon_{\mathrm{relative}}$')
     plt.title(r'Relative error')
     plt.show()
    -
    -

    -Depending on the parameter in front of the normal distribution, we may +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Depending on the parameter in front of the normal distribution, we may have a small or larger relative error. Try to play around with different training data sets and study (graphically) the value of the relative error. +

    -

    -As mentioned above, Scikit-Learn has an impressive functionality. +

    As mentioned above, Scikit-Learn has an impressive functionality. We can for example extract the values of \( \alpha \) and \( \beta \) and their error estimates, or the variance and standard deviation and many -other properties from the statistical data analysis. +other properties from the statistical data analysis. +

    -

    -Here we show an +

    Here we show an example of the functionality of Scikit-Learn. -

    +

    -
    import numpy as np 
    +
    +
    +
    +
    +
    +
    import numpy as np 
     import matplotlib.pyplot as plt 
     from sklearn.linear_model import LinearRegression 
     from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error
    @@ -577,84 +602,101 @@ plt.xlabel(r
     plt.ylabel(r'$y$')
     plt.title(r'Linear Regression fit ')
     plt.show()
    -
    -

    -The function coef gives us the parameter \( \beta \) of our fit while intercept yields +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The function coef gives us the parameter \( \beta \) of our fit while intercept yields \( \alpha \). Depending on the constant in front of the normal distribution, we get values near or far from \( \alpha =2 \) and \( \beta =5 \). Try to play around with different parameters in front of the normal distribution. The function meansquarederror gives us the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error or loss defined as +

    $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -

    -The smaller the value, the better the fit. Ideally we would like to +

    The smaller the value, the better the fit. Ideally we would like to have an MSE equal zero. The attentive reader has probably recognized this function as being similar to the \( \chi^2 \) function defined above. +

    -

    -The r2score function computes \( R^2 \), the coefficient of +

    The r2score function computes \( R^2 \), the coefficient of determination. It provides a measure of how well future samples are likely to be predicted by the model. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of \( \boldsymbol{y} \), disregarding the input features, would get a \( R^2 \) score of \( 0.0 \). +

    -

    -If \( \tilde{\boldsymbol{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 +

    If \( \tilde{\boldsymbol{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

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -Another quantity taht we will meet again in our discussions of regression analysis is +

    Another quantity taht we will meet again in our discussions of regression analysis is the mean absolute error (MAE), a risk metric corresponding to the expected value of the absolute error loss or what we call the \( l1 \)-norm loss. In our discussion above we presented the relative error. The MAE is defined as follows +

    $$ \text{MAE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. $$ -We present the +

    We present the squared logarithmic (quadratic) error +

    $$ \text{MSLE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, $$ -

    -where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error +

    where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error estimate is best to use when targets having exponential growth, such as population counts, average sales of a commodity over a span of -years etc. +years etc. +

    -

    -Finally, another cost function is the Huber cost function used in robust regression. +

    Finally, another cost function is the Huber cost function used in robust regression.

    -

    -The rationale behind this possible cost function is its reduced +

    The rationale behind this possible cost function is its reduced sensitivity to outliers in the data set. In our discussions on dimensionality reduction and normalization of data we will meet other ways of dealing with outliers. +

    -

    -The Huber cost function is defined as +

    The Huber cost function is defined as

    $$ H_{\delta}(\boldsymbol{a})=\left\{\begin{array}{cc}\frac{1}{2} \boldsymbol{a}^{2}& \text{for }|\boldsymbol{a}|\leq \delta\\ \delta (|\boldsymbol{a}|-\frac{1}{2}\delta ),&\text{otherwise}.\end{array}\right. $$ -Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \). +

    Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \).

    -

    -We will discuss in more detail these and other functions in the +

    We will discuss in more detail these and other functions in the various lectures. We conclude this part with another example. Instead of a linear \( x \)-dependence we study now a cubic polynomial and use the polynomial regression analysis tools of scikit-learn. +

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     import random
     from sklearn.linear_model import Ridge
    @@ -684,74 +726,85 @@ plt.show()
         return abs(np.sum(err))/len(err)
     
     print (error(y))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    To our real data: nuclear binding energies. Brief reminder on masses and binding energies

    -

    -Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding +

    Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding energies. A basic quantity which can be measured for the ground states of nuclei is the atomic mass \( M(N, Z) \) of the neutral atom with -atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +

    -

    -Atomic masses are usually tabulated in terms of the mass excess defined by +

    Atomic masses are usually tabulated in terms of the mass excess defined by

    $$ \Delta M(N, Z) = M(N, Z) - uA, $$ -where \( u \) is the Atomic Mass Unit +

    where \( u \) is the Atomic Mass Unit

    $$ u = M(^{12}\mathrm{C})/12 = 931.4940954(57) \hspace{0.1cm} \mathrm{MeV}/c^2. $$ -The nucleon masses are +

    The nucleon masses are

    $$ m_p = 1.00727646693(9)u, $$ -and +

    and

    $$ m_n = 939.56536(8)\hspace{0.1cm} \mathrm{MeV}/c^2 = 1.0086649156(6)u. $$ -

    -In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu +

    In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu there are data on masses and decays of 3437 nuclei. +

    -

    -The nuclear binding energy is defined as the energy required to break +

    The nuclear binding energy is defined as the energy required to break up a given nucleus into its constituent parts of \( N \) neutrons and \( Z \) protons. In terms of the atomic masses \( M(N, Z) \) the binding energy is defined by +

    $$ BE(N, Z) = ZM_H c^2 + Nm_n c^2 - M(N, Z)c^2 , $$ -where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. +

    where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. In terms of the mass excess the binding energy is given by +

    $$ BE(N, Z) = Z\Delta_H c^2 + N\Delta_n c^2 -\Delta(N, Z)c^2 , $$ -where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV. +

    where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV.

    -

    -A popular and physically intuitive model which can be used to parametrize +

    A popular and physically intuitive model which can be used to parametrize the experimental binding energies as function of \( A \), is the so-called liquid drop model. The ansatz is based on the following expression +

    $$ BE(N,Z) = a_1A-a_2A^{2/3}-a_3\frac{Z^2}{A^{1/3}}-a_4\frac{(N-Z)^2}{A}, $$ -

    -where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit -to the experimental data. +

    where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit +to the experimental data. +

    -

    -To arrive at the above expression we have assumed that we can make the following assumptions: +

    To arrive at the above expression we have assumed that we can make the following assumptions:

    - -We could also add a so-called pairing term, which is a correction term that +

    We could also add a so-called pairing term, which is a correction term that arises from the tendency of proton pairs and neutron pairs to -occur. An even number of particles is more stable than an odd number. - +occur. An even number of particles is more stable than an odd number. +

    Organizing our data

    -

    -Let us start with reading and organizing our data. +

    Let us start with reading and organizing our data. We start with the compilation of masses and binding energies from 2016. After having downloaded this file to our own computer, we are now ready to read the file and start structuring our data. +

    -

    -We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn. -

    +

    We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -809,13 +864,30 @@ DATA_ID = "
         plt.savefig(image_path(fig_id) + ".png", format='png')
     
     infile = open(data_path("MassEval2016.dat"),'r')
    -
    -

    -Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function.

    -
    from pylab import plt, mpl
    +
    +
    +
    +
    +
    +
    from pylab import plt, mpl
     plt.style.use('seaborn')
     mpl.rcParams['font.family'] = 'serif'
     
    @@ -826,20 +898,37 @@ mpl.rcParams[&#
             plt.xlabel(axlabels[0])
             plt.ylabel(axlabels[1])
         plt.legend(loc=0)
    -
    -

    -Our next step is to read the data on experimental binding energies and +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Our next step is to read the data on experimental binding energies and reorganize them as functions of the mass number \( A \), the number of protons \( Z \) and neutrons \( N \) using pandas. Before we do this it is always useful (unless you have a binary file or other types of compressed data) to actually open the file and simply take a look at it! +

    -

    -In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information. -

    +

    In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information.

    -
    """                                                                                                                         
    +
    +
    +
    +
    +
    +
    """                                                                                                                         
     This is taken from the data file of the mass 2016 evaluation.                                                               
     All files are 3436 lines long with 124 character per line.                                                                  
            Headers are 39 lines long.                                                                                           
    @@ -849,17 +938,35 @@ In particular, the program that outputs the final nuclear masses is written in F
        widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),                                                            
        Pandas has also a variable header, with length 39 in this case.                                                          
     """
    -
    -

    -The data we are interested in are in columns 2, 3, 4 and 11, giving us +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The data we are interested in are in columns 2, 3, 4 and 11, giving us the number of neutrons, protons, mass numbers and binding energies, respectively. We add also for the sake of completeness the element name. The data are in fixed-width formatted lines and we will covert them into the pandas DataFrame structure. +

    -

    -

    # Read the experimental data with Pandas
    +
    +
    +
    +
    +
    +
    # Read the experimental data with Pandas
     Masses = pd.read_fwf(infile, usecols=(2,3,4,6,11),
                   names=('N', 'Z', 'A', 'Element', 'Ebinding'),
                   widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),
    @@ -877,58 +984,129 @@ Masses['Ebinding'] = Masses.groupby('A')
     # Find the rows of the grouped DataFrame with the maximum binding energy.
     Masses = Masses.apply(lambda t: t[t.Ebinding==t.Ebinding.max()])
    -
    -

    -We have now read in the data, grouped them according to the variables we are interested in. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We have now read in the data, grouped them according to the variables we are interested in. We see how easy it is to reorganize the data using pandas. If we were to do these operations in C/C++ or Fortran, we would have had to write various functions/subroutines which perform the above reorganizations for us. Having reorganized the data, we can now start to make some simple fits using both the functionalities in numpy and -Scikit-Learn afterwards. +Scikit-Learn afterwards. +

    -

    -Now we define five variables which contain +

    Now we define five variables which contain the number of nucleons \( A \), the number of protons \( Z \) and the number of neutrons \( N \), the element name and finally the energies themselves. -

    +

    -
    A = Masses['A']
    +
    +
    +
    +
    +
    +
    A = Masses['A']
     Z = Masses['Z']
     N = Masses['N']
     Element = Masses['Element']
     Energies = Masses['Ebinding']
     print(Masses)
    -
    -

    -The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). It has dimensionality \( p\times n \), where \( n \) is the number of data points and \( p \) are the so-called predictors. In our case here they are given by the number of polynomials in \( A \) we wish to include in the fit. -

    +

    -
    # Now we set up the design matrix X
    +
    +
    +
    +
    +
    +
    # Now we set up the design matrix X
     X = np.zeros((len(A),5))
     X[:,0] = 1
     X[:,1] = A
     X[:,2] = A**(2.0/3.0)
     X[:,3] = A**(-1.0/3.0)
     X[:,4] = A**(-1.0)
    -
    -

    -With scikitlearn we are now ready to use linear regression and fit our data. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With scikitlearn we are now ready to use linear regression and fit our data.

    -
    clf = skl.LinearRegression().fit(X, Energies)
    +
    +
    +
    +
    +
    +
    clf = skl.LinearRegression().fit(X, Energies)
     fity = clf.predict(X)
    -
    -

    -Pretty simple! +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Pretty simple! Now we can print measures of how our fit is doing, the coefficients from the fits and plot the final fit together with our data. -

    +

    -
    # The mean squared error                               
    +
    +
    +
    +
    +
    +
    # The mean squared error                               
     print("Mean squared error: %.2f" % mean_squared_error(Energies, fity))
     # Explained variance score: 1 is perfect prediction                                 
     print('Variance score: %.2f' % r2_score(Energies, fity))
    @@ -948,17 +1126,32 @@ ax.plot(Masses[
     ax.legend()
     save_fig("Masses2016")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    Seeing the wood for the trees

    -

    -As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests! +

    As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests!

    -

    -

    #Decision Tree Regression
    +
    +
    +
    +
    +
    +
    #Decision Tree Regression
     from sklearn.tree import DecisionTreeRegressor
     regr_1=DecisionTreeRegressor(max_depth=5)
     regr_2=DecisionTreeRegressor(max_depth=7)
    @@ -987,16 +1180,32 @@ save_fig("Masses2016Trees")
     plt.show()
     print(Masses)
     print(np.mean( (Energies-y_1)**2))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    And what about using neural networks?

    - -The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) +

    The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) functionality. -

    +

    -
    from sklearn.neural_network import MLPRegressor
    +
    +
    +
    +
    +
    +
    from sklearn.neural_network import MLPRegressor
     from sklearn.metrics import accuracy_score
     import seaborn as sns
     
    @@ -1025,23 +1234,34 @@ ax.set_title(&q
     ax.set_ylabel("$\eta$")
     ax.set_xlabel("$\lambda$")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    A first summary

    -

    -The aim behind these introductory words was to present to you various +

    The aim behind these introductory words was to present to you various Python libraries and their functionalities, in particular libraries like numpy, pandas, xarray and matplotlib and other that make our life much easier -in handling various data sets and visualizing data. +in handling various data sets and visualizing data. +

    -

    -Furthermore, +

    Furthermore, Scikit-Learn allows us with few lines of code to implement popular Machine Learning algorithms for supervised learning. Later we will meet Tensorflow, a powerful library for deep learning. Now it is time to dive more into the details of various methods. We will start with linear regression and try to take a deeper look at what it entails. +

    -

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs039.html b/doc/pub/week34/html/._week34-bs039.html index 38629b795..bfbed2761 100644 --- a/doc/pub/week34/html/._week34-bs039.html +++ b/doc/pub/week34/html/._week34-bs039.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Why Linear Regression (aka Ordinary Least Squares and family)

    -

    -Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \). - +

    Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).

    - -For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. +

    For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. Similarly, Mehta et al's article is also recommended. +

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs040.html b/doc/pub/week34/html/._week34-bs040.html index f219f314b..aa803551e 100644 --- a/doc/pub/week34/html/._week34-bs040.html +++ b/doc/pub/week34/html/._week34-bs040.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Regression analysis, overarching aims

    -

    + -

    -Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). -The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. - -

    -A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with +

    Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). +The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. +

    +

    A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with

    • \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)
    • Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)
    • \( p \) so-called explanatory (independent or predictor) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.
    - - The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things. +

    The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.

    -

    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs041.html b/doc/pub/week34/html/._week34-bs041.html index c32d013fd..dac785e3f 100644 --- a/doc/pub/week34/html/._week34-bs041.html +++ b/doc/pub/week34/html/._week34-bs041.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Regression analysis, overarching aims II

    -

    + -

    -Consider an experiment in which \( p \) characteristics of \( n \) samples are +

    Consider an experiment in which \( p \) characteristics of \( n \) samples are measured. The data from this experiment, for various explanatory variables \( p \) are normally represented by a matrix \( \mathbf{X} \). +

    -

    -The matrix \( \mathbf{X} \) is called the design +

    The matrix \( \mathbf{X} \) is called the design matrix. Additional information of the samples is available in the form of \( \boldsymbol{y} \) (also as above). The variable \( \boldsymbol{y} \) is generally referred to as the response variable. The aim of @@ -386,17 +373,14 @@ f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of \( f(\cdot) \) is available, it is common to assume a linear relationship between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to the linear regression model where \( \boldsymbol{\beta} = [\beta_0, \ldots, -\beta_{p-1}]^{T} \) are the regression parameters. +\beta_{p-1}]^{T} \) are the regression parameters. +

    -

    -Linear regression gives us a set of analytical equations for the parameters \( \beta_j \). - -

    +

    Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).

    -

      @@ -426,25 +410,18 @@ Linear regression gives us a set of analytical equations for the parameters \( \
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs042.html b/doc/pub/week34/html/._week34-bs042.html index 9b8aa7edf..bdfea39d0 100644 --- a/doc/pub/week34/html/._week34-bs042.html +++ b/doc/pub/week34/html/._week34-bs042.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Examples

    -

    -In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), -consider the model we discussed for describing nuclear binding energies. + +

    In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), +consider the model we discussed for describing nuclear binding energies. +

    -

    -There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. +

    There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. Assuming +

    $$ BE(A) = a_0+a_1A+a_2A^{2/3}+a_3A^{-1/3}+a_4A^{-1}, $$ -we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. +

    we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. This gives \( p=0,1,2,3,4 \). Furthermore we have \( n \) entries for each predictor. It means that our design matrix is a \( p\times n \) matrix \( \boldsymbol{X} \). +

    -

    -Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the -so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. - -

    +

    Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the +so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. +

    -

      @@ -422,25 +409,18 @@ so-called »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs043.html b/doc/pub/week34/html/._week34-bs043.html index 2e89cbcaf..b5347c89b 100644 --- a/doc/pub/week34/html/._week34-bs043.html +++ b/doc/pub/week34/html/._week34-bs043.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    General linear models

    -

    -Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function. + +

    Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function.

    -

    -Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is +

    Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is

    $$ y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i, $$ -where \( \epsilon_i \) is the error in our approximation. - -

    +

    where \( \epsilon_i \) is the error in our approximation.

    -

      @@ -414,25 +398,18 @@ where \( \epsilon_i \) is the error in our approximation.
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs044.html b/doc/pub/week34/html/._week34-bs044.html index 6fd784d16..f42350a19 100644 --- a/doc/pub/week34/html/._week34-bs044.html +++ b/doc/pub/week34/html/._week34-bs044.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Rewriting the fitting procedure as a linear algebra problem

    -

    -For every set of values \( y_i,x_i \) we have thus the corresponding set of equations + +

    For every set of values \( y_i,x_i \) we have thus the corresponding set of equations

    $$ \begin{align*} y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\ @@ -383,7 +371,6 @@ $$
    -

      @@ -413,25 +400,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs045.html b/doc/pub/week34/html/._week34-bs045.html index a59a14d5c..f1458b329 100644 --- a/doc/pub/week34/html/._week34-bs045.html +++ b/doc/pub/week34/html/._week34-bs045.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    Rewriting the fitting procedure as a linear algebra problem, more details

    -

    -Defining the vectors + +

    Defining the vectors

    $$ \boldsymbol{y} = [y_0,y_1, y_2,\dots, y_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\epsilon} = [\epsilon_0,\epsilon_1, \epsilon_2,\dots, \epsilon_{n-1}]^T, $$ -and the design matrix +

    and the design matrix

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -396,17 +384,16 @@ $$ \end{bmatrix} $$ -we can rewrite our equations as +

    we can rewrite our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The above design matrix is called a Vandermonde matrix. +

    The above design matrix is called a Vandermonde matrix.

    -

      @@ -436,25 +423,18 @@ The above design matrix is called a »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs046.html b/doc/pub/week34/html/._week34-bs046.html index 5b7e7f34e..554cc0651 100644 --- a/doc/pub/week34/html/._week34-bs046.html +++ b/doc/pub/week34/html/._week34-bs046.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Generalizing the fitting procedure as a linear algebra problem

    -

    + -

    -We are obviously not limited to the above polynomial expansions. We +

    We are obviously not limited to the above polynomial expansions. We could replace the various powers of \( x \) with elements of Fourier series or instead of \( x_i^j \) we could have \( \cos{(j x_i)} \) or \( \sin{(j x_i)} \), or time series or other orthogonal functions. For every set of values \( y_i,x_i \) we can then generalize the equations to +

    $$ \begin{align*} @@ -389,13 +377,12 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    + Note that we have \( p=n \) here. The matrix is symmetric. This is generally not the case!

    -

      @@ -425,25 +412,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs047.html b/doc/pub/week34/html/._week34-bs047.html index 716a17993..01c7d0179 100644 --- a/doc/pub/week34/html/._week34-bs047.html +++ b/doc/pub/week34/html/._week34-bs047.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Generalizing the fitting procedure as a linear algebra problem

    -

    -We redefine in turn the matrix \( \boldsymbol{X} \) as + +

    We redefine in turn the matrix \( \boldsymbol{X} \) as

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -381,17 +369,16 @@ x_{n-1,0}& x_{n-1,1} &x_{n-1,2}& \dots & \dots &x_{n-1,n-1}\\ \end{bmatrix} $$ -and without loss of generality we rewrite again our equations as +

    and without loss of generality we rewrite again our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? +

    The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values?

    -

      @@ -421,25 +408,18 @@ The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\e
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs048.html b/doc/pub/week34/html/._week34-bs048.html index 85b77e0e5..81f4e8937 100644 --- a/doc/pub/week34/html/._week34-bs048.html +++ b/doc/pub/week34/html/._week34-bs048.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Optimizing our parameters

    -

    -We have defined the matrix \( \boldsymbol{X} \) via the equations + +

    We have defined the matrix \( \boldsymbol{X} \) via the equations

    $$ \begin{align*} y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\ @@ -382,17 +370,14 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    -As we noted above, we stayed with a system with the design matrix +

    As we noted above, we stayed with a system with the design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times n} \), that is we have \( p=n \). For reasons to come later (algorithmic arguments) we will hereafter define our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors refering to the column numbers and the entries \( n \) being the row elements. - -

    +

    -

      @@ -422,25 +407,18 @@ our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predict
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs049.html b/doc/pub/week34/html/._week34-bs049.html index ee0cb5cc3..a2853801d 100644 --- a/doc/pub/week34/html/._week34-bs049.html +++ b/doc/pub/week34/html/._week34-bs049.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Our model for the nuclear binding energies

    -

    -In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code. +

    In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code.

    -

    -We restate the parts of the code we are most interested in. -

    +

    We restate the parts of the code we are most interested in.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -444,16 +434,28 @@ DesignMatrix = pd.index = A
     DesignMatrix.columns = ['1', 'A', 'A^(2/3)', 'A^(-1/3)', '1/A']
     display(DesignMatrix)
    -
    -

    -With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -throughout these lectures. +

    throughout these lectures.

    -

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs050.html b/doc/pub/week34/html/._week34-bs050.html index ea8a5eaa4..c928b64f4 100644 --- a/doc/pub/week34/html/._week34-bs050.html +++ b/doc/pub/week34/html/._week34-bs050.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Optimizing our parameters, more details

    -

    -With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as + +

    With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely +

    and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as +

    or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -This function is one possible way to define the so-called cost function. +

    This function is one possible way to define the so-called cost function.

    -

    -It is also common to define +

    It is also common to define the function \( C \) as +

    $$ C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2, $$ -since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. +

    since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out.

    -

      @@ -429,25 +416,18 @@ since when taking the first derivative with respect to the unknown parameters \(
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs051.html b/doc/pub/week34/html/._week34-bs051.html index df9fedcd3..c63a221ca 100644 --- a/doc/pub/week34/html/._week34-bs051.html +++ b/doc/pub/week34/html/._week34-bs051.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Interpretations and optimizing our parameters

    -

    + -

    -The function +

    The function

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}, $$ -can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. +

    can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value +

    $$ y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i, $$ -

    -where \( \langle y_i \rangle \) is the mean value. Keep in mind also that +

    where \( \langle y_i \rangle \) is the mean value. Keep in mind also that till now we have treated \( y_i \) as the exact value. Normally, the response (dependent or outcome) variable \( y_i \) the outcome of a numerical experiment or another type of experiment and is thus only an @@ -391,35 +378,32 @@ approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem

    $$ {\displaystyle \min_{\boldsymbol{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -In practical terms it means we will require +

    In practical terms it means we will require

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right). $$ - -

    -

      @@ -449,25 +433,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs052.html b/doc/pub/week34/html/._week34-bs052.html index 9a2307409..ba5fc44ff 100644 --- a/doc/pub/week34/html/._week34-bs052.html +++ b/doc/pub/week34/html/._week34-bs052.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Interpretations and optimizing our parameters

    -

    -We can rewrite + +

    We can rewrite

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$ -

    -We note also that since our design matrix is defined as \( \boldsymbol{X}\in +

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), the product \( \boldsymbol{X}^T\boldsymbol{X} \in {\mathbb{R}}^{p\times p} \). In the above case we have that \( p \ll n \), in our case \( p=5 \) meaning that we end up with inverting a small @@ -394,21 +381,20 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). +\( \boldsymbol{X}^T\boldsymbol{X} \). +

    -

    -

    -Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect? + +

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    -

      @@ -438,25 +424,18 @@ allow for the usage of direct linear algebra methods such as LU decomposi
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs053.html b/doc/pub/week34/html/._week34-bs053.html index a2df0c125..50e57ea0e 100644 --- a/doc/pub/week34/html/._week34-bs053.html +++ b/doc/pub/week34/html/._week34-bs053.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Some useful matrix and vector expressions

    -

    -The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and +

    The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and matrices as upper case boldfaced letters. +

    $$ \frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, @@ -416,25 +404,18 @@ $$
  • »
  • -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs054.html b/doc/pub/week34/html/._week34-bs054.html index 01d9fd676..2742315b5 100644 --- a/doc/pub/week34/html/._week34-bs054.html +++ b/doc/pub/week34/html/._week34-bs054.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Interpretations and optimizing our parameters

    -

    -The residuals \( \boldsymbol{\epsilon} \) are in turn given by + +

    The residuals \( \boldsymbol{\epsilon} \) are in turn given by

    $$ \boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}, $$ -and with +

    and with

    $$ \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -we have +

    we have

    $$ \boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach. - -

    +

    meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.

    -

    -Let us now return to our nuclear binding energies and simply code the above equations. +

    Let us now return to our nuclear binding energies and simply code the above equations.

    -

      @@ -424,25 +408,18 @@ Let us now return to our nuclear binding energies and simply code the above equa
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs055.html b/doc/pub/week34/html/._week34-bs055.html index c2cbb0de2..2e2e7e49f 100644 --- a/doc/pub/week34/html/._week34-bs055.html +++ b/doc/pub/week34/html/._week34-bs055.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Own code for Ordinary Least Squares

    -

    -It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to +

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to write -

    +

    -
    # matrix inversion to find beta
    +
    +
    +
    +
    +
    +
    # matrix inversion to find beta
     beta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Energies)
     # and then make the prediction
     ytilde = X @ beta
    -
    -

    -Alternatively, you can use the least squares functionality in Numpy as -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Alternatively, you can use the least squares functionality in Numpy as

    -
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
    +
    +
    +
    +
    +
    +
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
     ytildenp = np.dot(fit,X.T)
    -
    -

    -And finally we plot our fit with and compare with data -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    And finally we plot our fit with and compare with data

    -
    Masses['Eapprox']  = ytilde
    +
    +
    +
    +
    +
    +
    Masses['Eapprox']  = ytilde
     # Generate a plot comparing the experimental with the fitted values values.
     fig, ax = plt.subplots()
     ax.set_xlabel(r'$A = N + Z$')
    @@ -403,8 +429,22 @@ ax.plot(Masses[
     ax.legend()
     save_fig("Masses2016OLS")
     plt.show()
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs056.html b/doc/pub/week34/html/._week34-bs056.html index 22aefbc89..ba562cbd3 100644 --- a/doc/pub/week34/html/._week34-bs056.html +++ b/doc/pub/week34/html/._week34-bs056.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Adding error analysis and training set up

    -

    -We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. +

    We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. Since we are not using Scikit-Learn here we can define our own \( R2 \) function as -

    +

    -
    def R2(y_data, y_model):
    +
    +
    +
    +
    +
    +
    def R2(y_data, y_model):
         return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    -
    -

    -and we would be using it as -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and we would be using it as

    -
    print(R2(Energies,ytilde))
    -
    -

    -We can easily add our MSE score as -

    +

    +
    +
    +
    +
    +
    print(R2(Energies,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily add our MSE score as

    -
    def MSE(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def MSE(y_data,y_model):
         n = np.size(y_model)
         return np.sum((y_data-y_model)**2)/n
     
     print(MSE(Energies,ytilde))
    -
    -

    -and finally the relative error as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and finally the relative error as

    -
    def RelativeError(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def RelativeError(y_data,y_model):
         return abs((y_data-y_model)/y_data)
     print(RelativeError(Energies, ytilde))
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs057.html b/doc/pub/week34/html/._week34-bs057.html index f1c4d9a28..090db4663 100644 --- a/doc/pub/week34/html/._week34-bs057.html +++ b/doc/pub/week34/html/._week34-bs057.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    + -

    -Normally, the response (dependent or outcome) variable \( y_i \) is the +

    Normally, the response (dependent or outcome) variable \( y_i \) is the outcome of a numerical experiment or another type of experiment and is thus only an approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -Introducing the standard deviation \( \sigma_i \) for each measurement +

    Introducing the standard deviation \( \sigma_i \) for each measurement \( y_i \), we define now the \( \chi^2 \) function (omitting the \( 1/n \) term) as +

    $$ \chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. - -

    +

    where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements.

    -

      @@ -423,25 +408,18 @@ where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs058.html b/doc/pub/week34/html/._week34-bs058.html index 687481d4c..4905d159c 100644 --- a/doc/pub/week34/html/._week34-bs058.html +++ b/doc/pub/week34/html/._week34-bs058.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    + -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right). $$ -where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). +

    where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \).

    -

      @@ -418,25 +404,18 @@ where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs059.html b/doc/pub/week34/html/._week34-bs059.html index 2d27878b7..ea546ff3f 100644 --- a/doc/pub/week34/html/._week34-bs059.html +++ b/doc/pub/week34/html/._week34-bs059.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    + -

    -We can rewrite +

    We can rewrite

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}. $$ @@ -389,7 +376,6 @@ $$
    -

      @@ -415,25 +401,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs060.html b/doc/pub/week34/html/._week34-bs060.html index 89ed92a16..cf8f8636e 100644 --- a/doc/pub/week34/html/._week34-bs060.html +++ b/doc/pub/week34/html/._week34-bs060.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    + -

    -If we then introduce the matrix +

    If we then introduce the matrix

    $$ \boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}, $$ -we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \)) +

    we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))

    $$ \beta_j = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}\frac{y_i}{\sigma_i}\frac{x_{ik}}{\sigma_i} = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}b_ia_{ik} $$ -We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise) +

    We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)

    $$ \sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2, $$ -resulting in +

    resulting in

    $$ \sigma^2(\beta_j) = \left(\sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}a_{ik}\right)\left(\sum_{l=0}^{p-1}h_{jl}\sum_{m=0}^{n-1}a_{ml}\right) = h_{jj}! $$ @@ -394,7 +381,6 @@ $$
    -

      @@ -419,25 +405,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs061.html b/doc/pub/week34/html/._week34-bs061.html index a441e73aa..977c28b8e 100644 --- a/doc/pub/week34/html/._week34-bs061.html +++ b/doc/pub/week34/html/._week34-bs061.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    -The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write + +

    The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write

    $$ y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i. $$ -By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by +

    By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0, $$ -and +

    and

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0. $$ @@ -387,7 +375,6 @@ $$
    -

      @@ -411,25 +398,18 @@ $$
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs062.html b/doc/pub/week34/html/._week34-bs062.html index 59eb611c3..ed6ff4c81 100644 --- a/doc/pub/week34/html/._week34-bs062.html +++ b/doc/pub/week34/html/._week34-bs062.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - -
    -
    -

     

     

     

    - -

    The \( \chi^2 \) function

    -

    + -

    -For a linear fit (a first-order polynomial) we don't need to invert a matrix!! +

    For a linear fit (a first-order polynomial) we don't need to invert a matrix!! Defining +

    $$ \gamma = \sum_{i=0}^{n-1}\frac{1}{\sigma_i^2}, $$ @@ -397,8 +385,7 @@ $$ \gamma_{xy} = \sum_{i=0}^{n-1}\frac{y_ix_{i}}{\sigma_i^2}, $$ -

    -we obtain +

    we obtain

    $$ \beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}, @@ -409,18 +396,15 @@ $$ \beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}. $$ -

    -This approach (different linear and non-linear regression) suffers +

    This approach (different linear and non-linear regression) suffers often from both being underdetermined and overdetermined in the unknown coefficients \( \beta_i \). A better approach is to use the Singular Value Decomposition (SVD) method discussed next week. - -

    +

    -

      @@ -443,25 +427,18 @@ Singular Value Decomposition (SVD) method discussed next week.
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs063.html b/doc/pub/week34/html/._week34-bs063.html index 68d6518e8..b9fa86611 100644 --- a/doc/pub/week34/html/._week34-bs063.html +++ b/doc/pub/week34/html/._week34-bs063.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Fitting an Equation of State for Dense Nuclear Matter

    -

    -Before we continue, let us introduce yet another example. We are going to fit the +

    Before we continue, let us introduce yet another example. We are going to fit the nuclear equation of state using results from many-body calculations. The equation of state we have made available here, as function of density, has been derived using modern nucleon-nucleon potentials with the addition of three-body forces. This time the file is presented as a standard csv file. +

    -

    -The beginning of the Python code here is similar to what you have seen +

    The beginning of the Python code here is similar to what you have seen before, with the same initializations and declarations. We use also pandas again, rather extensively in order to organize our data. +

    -

    -The difference now is that we use Scikit-Learn's regression tools +

    The difference now is that we use Scikit-Learn's regression tools instead of our own matrix inversion implementation. Furthermore, we sneak in Ridge regression (to be discussed below) which includes a hyperparameter \( \lambda \), also to be explained below. +

    -

      @@ -409,25 +396,18 @@ hyperparameter \( \lambda \), also to be explained below.
    • »
    -
    - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs064.html b/doc/pub/week34/html/._week34-bs064.html index 5e17d02d8..fe2f6ba81 100644 --- a/doc/pub/week34/html/._week34-bs064.html +++ b/doc/pub/week34/html/._week34-bs064.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    The code

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -455,17 +447,30 @@ ax.plot(EoS[
     ax.legend()
     save_fig("EoSfitting")
     plt.show()
    -
    -

    -The above simple polynomial in density \( \rho \) gives an excellent fit -to the data. +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -We note also that there is a small deviation between the +

    The above simple polynomial in density \( \rho \) gives an excellent fit +to the data. +

    + +

    We note also that there is a small deviation between the standard OLS and the Ridge regression at higher densities. We discuss this in more detail below. +

    -

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs065.html b/doc/pub/week34/html/._week34-bs065.html index 1d03cd0e8..15c5fd644 100644 --- a/doc/pub/week34/html/._week34-bs065.html +++ b/doc/pub/week34/html/._week34-bs065.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Splitting our Data in Training and Test data

    -

    -It is normal in essentially all Machine Learning studies to split the +

    It is normal in essentially all Machine Learning studies to split the data in a training set and a test set (sometimes also an additional validation set). Scikit-Learn has an own function for this. There is no explicit recipe for how much data should be included as training @@ -378,11 +365,16 @@ postpone a discussion of this splitting to the end of these notes and our discussion of the so-called bias-variance tradeoff. Here we limit ourselves to repeat the above equation of state fitting example but now splitting the data into a training set and a test set. +

    -

    -

    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -446,8 +438,22 @@ ypredict = X_test print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    - - - -
    - - - diff --git a/doc/pub/week34/html/._week34-bs066.html b/doc/pub/week34/html/._week34-bs066.html index 931375977..3c0ddfddc 100644 --- a/doc/pub/week34/html/._week34-bs066.html +++ b/doc/pub/week34/html/._week34-bs066.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - -

    Exercises for week 35

    -Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1. +

    Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1.

    -

    -

    Exercise 1: Setting up various Python environments

    -

    -The first exercise here is of a mere technical art. We want you to have - +

    The first exercise here is of a mere technical art. We want you to have

    • 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.
    • Install various Python packages
    - -We will make extensive use of Python as programming language and its +

    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. +

    -

    -If you have Python installed (we recommend Python3) and you feel +

    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 +

    1. pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
    - -For Tensorflow, we recommend following the instructions in the text of +

    For Tensorflow, we recommend following the instructions in the text of Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly +

    -

    -We will come back to tensorflow later. +

    We will come back to tensorflow later.

    -

    -For Python3, replace pip with pip3. +

    For Python3, replace pip with pip3.

    -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for Python2.7)
    - -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    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 if you are not too familiar with setting paths in a terminal environment. +

    We recommend using Anaconda if you are not too familiar with setting paths in a terminal environment.

    -

    -

    -

    Exercise 2: making your own data and exploring scikit-learn

    -

    -We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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) \). +

    We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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). -

    +

    -
    x = np.random.rand(100,1)
    +
    +
    +
    +
    +
    +
    x = np.random.rand(100,1)
     y = 2.0+5*x*x+0.1*np.random.randn(100,1)
    -
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +
    1. Write your own code (following the examples under the regression notes) for computing the parametrization of the data set fitting a second-order polynomial.
    2. Use thereafter scikit-learn (see again the examples in the regression slides) and compare with your own code.
    3. Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as
    - $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -and the \( R^2 \) score function. +

    and the \( R^2 \) score function. If \( \tilde{\boldsymbol{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 +

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. +

    You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. 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. +

    -

    - +

    +

    Solution. +

    -

    -The code here is an example of where we define our own design matrix and fit parameters \( \beta \). -

    +

    The code here is an example of where we define our own design matrix and fit parameters \( \beta \).

    -
    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -548,31 +551,40 @@ ypredict = X_test print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    -

    -

    -

    -

    Exercise 3: Normalizing our data

    -

    -A much used approach before starting to train the data is to preprocess our +

    A much used approach before starting to train the data is to preprocess our data. Normally the data may need a rescaling and/or may be sensitive to extreme values. Scaling the data renders our inputs much more suitable for the algorithms we want to employ. +

    -

    -Scikit-Learn has several functions which allow us to rescale the +

    Scikit-Learn has several functions which allow us to rescale the data, normally resulting in much better results in terms of various accuracy scores. The StandardScaler function in Scikit-Learn ensures that for each feature/predictor we study the mean value is @@ -581,18 +593,18 @@ matrix). This scaling has the drawback that it does not ensure that we have a particular maximum or minimum in our data set. Another function included in Scikit-Learn is the MinMaxScaler which ensures that all features are exactly between \( 0 \) and \( 1 \). The +

    -

    -The Normalizer scales each data +

    The Normalizer scales each data point such that the feature vector has a euclidean length of one. In other words, it projects a data point on the circle (or sphere in the case of higher dimensions) with a radius of 1. This means every data point is scaled by a different number (by the inverse of it’s length). This normalization is often used when only the direction (or angle) of the data matters, not the length of the feature vector. +

    -

    -The RobustScaler works similarly to the StandardScaler in that it +

    The RobustScaler works similarly to the StandardScaler in that it ensures statistical properties for each feature that guarantee that they are on the same scale. However, the RobustScaler uses the median and quartiles, instead of mean and variance. This makes the @@ -600,65 +612,127 @@ RobustScaler ignore data points that are very different from the rest (like measurement errors). These odd data points are also called outliers, and might often lead to trouble for other scaling techniques. +

    -

    -It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest +

    It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest for testing. This can be done as follows with our design matrix \( \boldsymbol{X} \) and data \( \boldsymbol{y} \) (remember to import scikit-learn) -

    +

    -
    # split in training and test data
    +
    +
    +
    +
    +
    +
    # split in training and test data
     X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
    -
    -

    -Then we can use the standard scaler to scale our data as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Then we can use the standard scaler to scale our data as

    -
    scaler = StandardScaler()
    +
    +
    +
    +
    +
    +
    scaler = StandardScaler()
     scaler.fit(X_train)
     X_train_scaled = scaler.transform(X_train)
     X_test_scaled = scaler.transform(X_test)
    -
    -

    -In this exercise we want you to to compute the MSE for the training +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In this exercise we want you to to compute the MSE for the training data and the test data as function of the complexity of a polynomial, -that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +

    -

    -One of +

    One of the aims is to reproduce Figure 2.11 of Hastie et al. +

    -

    -Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points. -

    +

    Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points.

    -
    np.random.seed()
    +
    +
    +
    +
    +
    +
    np.random.seed()
     n = 100
     maxdegree = 14
     # Make data set.
     x = np.linspace(-3, 3, n).reshape(-1, 1)
     y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    -
    -

    -where \( y \) is the function we want to fit with a given polynomial. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + +

    where \( y \) is the function we want to fit with a given polynomial.

    + +

    a) Write a first code which sets up a design matrix \( X \) defined by a fifth-order polynomial. Scale your data and split it in training and test data. +

    + + +

    b) Perform an ordinary least squares and compute the means squared error and the \( R2 \) factor for the training data and the test data, with and without scaling. +

    + + +

    c) Add now a model which allows you to make polynomials up to degree \( 15 \). Perform a standard OLS fitting of the training data and compute the MSE and \( R2 \) for the training and test data and plot both test and training data MSE and \( R2 \) as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)? +

    + + -

    -

    - - - -
    - - - diff --git a/doc/pub/week34/html/week34-bs.html b/doc/pub/week34/html/week34-bs.html index 743aee240..6c35019c1 100644 --- a/doc/pub/week34/html/week34-bs.html +++ b/doc/pub/week34/html/week34-bs.html @@ -1,6 +1,7 @@ @@ -8,24 +9,20 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - + - - - -
    -

     

     

     

    - - - -
    -

    Week 34: Introduction to the course, Logistics and Practicalities

    +
    +

    Week 34: Introduction to the course, Logistics and Practicalities

    +
    -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Nov 13, 2021

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Oct 12, 2021

    -
    -

    Read »

    @@ -412,25 +400,18 @@ MathJax.Hub.Config({
  • »
  • -
    - - -
    © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week34/html/week34-reveal.html b/doc/pub/week34/html/week34-reveal.html index 8b78adb7a..a4a4913c9 100644 --- a/doc/pub/week34/html/week34-reveal.html +++ b/doc/pub/week34/html/week34-reveal.html @@ -1,18 +1,17 @@ + - + + - Week 34: Introduction to the course, Logistics and Practicalities - - - - - - @@ -55,36 +54,81 @@ document.getElementsByTagName( 'head' )[0].appendChild( link ); - - - +
    +

    Week 34: Introduction to the course, Logistics and Practicalities

    +
    - - -

    Week 34: Introduction to the course, Logistics and Practicalities

    - -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Nov 13, 2021

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Oct 12, 2021

    -
    -











    -

    Overview of first week

    -

    -

    • Wednesday August 25: Introduction to software and repetition of Python Programming
    • Thursday August 26: First lecture: Presentation of the course, aims and content
    • @@ -322,59 +318,44 @@ MathJax.Hub.Config({
    -











    -

    Reading Recommendations

    -

    -For the reading assignments we use the following abbreviations: - +

    For the reading assignments we use the following abbreviations:

    • GBC: Goodfellow, Bengio, and Courville, Deep Learning
    • CMB: Christopher M. Bishop, Pattern Recognition and Machine Learning
    • HTF: Hastie, Tibshirani, and Friedman, The Elements of Statistical Learning
    • AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow
    - -Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html +

    Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html

    -











    -

    Thursday August 26

    -

    -The lectures will be recorded and updated videos will be posted after the lectures. +

    The lectures will be recorded and updated videos will be posted after the lectures.

    -

    -"Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage

    -

    -Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09 +

    Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09

    • Meeting ID: 933 1152 9525
    • Passcode: 646102
    +

    Video of Lecture from Fall Semester 2020.

    -Video of Lecture from Fall Semester 2020. - -











    -

    Lectures and ComputerLab

    -

    -

    • Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).
    • Weekly reading assignments and videos needed to solve projects and exercises.
    • @@ -386,17 +367,12 @@ The lectures will be recorded and updated videos will be posted after the lectur
    -











    -

    Announcement

    -

    -NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html +

    NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html

    -











    -

    Communication channels

    -









    -

    Course Format

    -

    -

    • Three compulsory projects. Electronic reports only using Canvas to hand in projects and git as version control software and GitHub for repository (or GitLab) of all your material.
    • Evaluation and grading: The three projects are graded and each counts 1/3 of the final mark. No final written or oral exam. -
      1. For the last project each group/participant submits a proposal or works with suggested (by us) proposals for the project.
      2. If possible, we would like to organize the last project as a workshop where each group makes a poster and presents this to all other participants of the course
      3. Poster session where all participants can study and discuss the other proposals.
      4. Based on feedback etc, each group finalizes the report and submits for grading.
      -
    • Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and github address of the course.
    -











    -

    Teachers

    -

    -

    Teachers : -

    • Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no
    • -
      • Phone: +47-48257387
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ470
      • Office hours: Anytime! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning.
      -
    • Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ452
      -
    • Stian Dysthe Bilek stian.bilek@fys.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ450
      -
    • Linus Ekstrøm, linueks@gmail.com, linus.ekstrom@fys.uio.no
    • Nicholas Karlsen, nicholaskarlsen1102@gmail.com, nicholas.karlsen@fys.uio.no
    • Bendik Steinsvåg Dalen, b.s.dalen@fys.uio.no
    • @@ -472,57 +431,44 @@ The lectures will be recorded and updated videos will be posted after the lectur
    -











    -

    Deadlines for projects (tentative)

    -

    1. Project 1: October 11 (available September 10) graded with feedback)
    2. -
    3. Project 2: November 15 (available October 12, graded with feedback)
    4. -
    5. Project 3: December 13 (available November 8, graded with feedback)
    6. +
    7. Project 2: November 20 (available October 12, graded with feedback)
    8. +
    9. Project 3: December 17 (available November 13, graded with feedback)
    - -Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas. - - +

    Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas.

    -











    -

    1. The lecture notes are collected as a jupyter-book at https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html.
    - -In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below. +

    In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below.

    1. Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, https://www.springer.com/gp/book/9780387310732.
    2. Ian Goodfellow, Yoshua Bengio, and Aaron Courville. The different chapters are available for free at https://www.deeplearningbook.org/. Chapters 2-14 are highly recommended. The lectures follow to a larg extent this text. The weekly plans will include reading suggestions from these two textbooks.
    - -Additional textbooks: +

    Additional textbooks:

    1. Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, https://www.springer.com/gp/book/9780387848570. This is a well-known text and serves as additional literature.
    2. Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/. This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course.
    -









    -

    Prerequisites

    -

    -Basic knowledge in programming and mathematics, with an emphasis on +

    Basic knowledge in programming and mathematics, with an emphasis on linear algebra. Knowledge of Python or/and C++ as programming languages is strongly recommended and experience with Jupiter notebook is recommended. Required courses are the equivalents to the University @@ -531,19 +477,16 @@ of the corresponding computing and programming courses INF1000/INF1110 or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1100. Most universities offer nowadays a basic programming course (often compulsory) where Python is the recurring programming language. +

    -











    -

    Learning outcomes

    -

    -

    -This course aims at giving you insights and knowledge about many of +

    This course aims at giving you insights and knowledge about many of the central algorithms used in Data Analysis and Machine Learning. The course is project based and through various numerical projects, normally three, you will be exposed to fundamental research problems @@ -556,6 +499,7 @@ Learning is applied to, get acquainted with computing facilities and learn to handle large scientific projects. A good scientific and ethical conduct is emphasized throughout the course. More specifically, after this course you will +

    • Learn about basic data analysis, statistical analysis, Bayesian statistics, Monte Carlo sampling, data optimization and machine learning;
    • @@ -572,29 +516,22 @@ specifically, after this course you will
    -











    -

    Topics covered in this course: Statistical analysis and optimization of data

    -

    -The course has two central parts +

    The course has two central parts

    1. Statistical analysis and optimization of data
    2. Machine learning
    +

    These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms

    -These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms - -

    Statistical analysis and optimization of data

    -

    -We plan to cover the following topics: - +

    We plan to cover the following topics:

    • Basic concepts, expectation values, variance, covariance, correlation functions and errors;
    • Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions;
    • @@ -607,17 +544,13 @@ We plan to cover the following topics:
    -











    -

    Topics covered in this course: Machine Learning

    -

    -The following topics will be covered - +

    The following topics will be covered

    • Linear Regression and Logistic Regression;
    • Neural networks and deep learning, including convolutional and recurrent neural networks
    • @@ -627,23 +560,16 @@ The following topics will be covered
    • Boltzmann Machines
    • Unsupervised learning Dimensionality reduction, from PCA to clustering
    - -Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics. - - +

    Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics.

    -











    -

    -

    and discussed at the lab sessions

    -

    • GIT for version control, and GitHub or GitLab as repositories, highly recommended. This will be discussed during the first exercise session
    • Anaconda and other Python environments, see intro slides and links to programming resources at https://computationalscienceuio.github.io/RefreshProgrammingSkills/intro.html
    • @@ -651,13 +577,10 @@ Hands-on demonstrations, exercises and projects aim at deepening your understand
    -











    -

    Other courses on Data science and Machine Learning at UiO

    -

    -The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO. +

    The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO.

    1. STK2100 Machine learning and statistical methods for prediction and classification.
    2. @@ -672,18 +595,15 @@ The link here STK4051 Computational Statistics
    3. STK4021 Applied Bayesian Analysis and Numerical Methods
    -









    -

    Introduction

    -

    -Our emphasis throughout this series of lectures +

    Our emphasis throughout this series of lectures is on understanding the mathematical aspects of -different algorithms used in the fields of data analysis and machine learning. +different algorithms used in the fields of data analysis and machine learning. +

    -

    -However, where possible we will emphasize the +

    However, where possible we will emphasize the importance of using available software. We start thus with a hands-on and top-down approach to machine learning. The aim is thus to start with relevant data or data we have produced @@ -697,40 +617,38 @@ the data and predictions. We move thereafter to more interesting cases such as data from say experiments (below we will look at experimental nuclear binding energies as an example). These are examples where we can easily set up the data and then use machine learning algorithms included in for example -Scikit-Learn. +Scikit-Learn. +

    -

    -These examples will serve us the purpose of getting +

    These examples will serve us the purpose of getting started. Furthermore, they allow us to catch more than two birds with a stone. They will allow us to bring in some programming specific topics and tools as well as showing the power of various Python -libraries for machine learning and statistical data analysis. +libraries for machine learning and statistical data analysis. +

    -

    -Here, we will mainly focus on two +

    Here, we will mainly focus on two specific Python packages for Machine Learning, Scikit-Learn and Tensorflow (see below for links etc). Moreover, the examples we introduce will serve as inputs to many of our discussions later, as well as allowing you to set up models and produce your own data and get started with programming. +

    -











    -

    What is Machine Learning?

    -

    -Statistics, data science and machine learning form important fields of +

    Statistics, data science and machine learning form important fields of research in modern science. They describe how to learn and make predictions from data, as well as allowing us to extract important correlations about physical process and the underlying laws of motion in large data sets. The latter, big data sets, appear frequently in essentially all disciplines, from the traditional Science, Technology, Mathematics and Engineering fields to Life Science, Law, education -research, the Humanities and the Social Sciences. +research, the Humanities and the Social Sciences. +

    -

    -It has become more +

    It has become more and more common to see research projects on big data in for example the Social Sciences where extracting patterns from complicated survey data is one of many research directions. Having a solid grasp of data @@ -745,17 +663,17 @@ in the private or the public sector. This author has had several students or met students who have been hired recently based on their skills and competences in scientific computing and data science, often with marginal knowledge of machine learning. +

    -

    -Machine learning is a subfield of computer science, and is closely +

    Machine learning is a subfield of computer science, and is closely related to computational statistics. It evolved from the study of pattern recognition in artificial intelligence (AI) research, and has made contributions to AI tasks like computer vision, natural language processing and speech recognition. Many of the methods we will study are also -strongly rooted in basic mathematics and physics research. +strongly rooted in basic mathematics and physics research. +

    -

    -Ideally, machine learning represents the science of giving computers +

    Ideally, machine learning represents the science of giving computers the ability to learn without being explicitly programmed. The idea is that there exist generic algorithms which can be used to find patterns in a broad class of data sets without having to write code @@ -763,10 +681,10 @@ specifically for each problem. The algorithm will build its own logic based on the data. You should however always keep in mind that machines and algorithms are to a large extent developed by humans. The insights and knowledge we have about a specific system, play a central -role when we develop a specific machine learning algorithm. +role when we develop a specific machine learning algorithm. +

    -

    -Machine learning is an extremely rich field, in spite of its young +

    Machine learning is an extremely rich field, in spite of its young age. The increases we have seen during the last three decades in computational capabilities have been followed by developments of methods and techniques for analyzing and handling large date sets, @@ -786,14 +704,12 @@ solid command of linear algebra, multivariate theory, probability theory, statistical data analysis, understanding errors and Monte Carlo methods are central elements in a proper understanding of many of algorithms and methods we will discuss. +

    -











    -

    Types of Machine Learning

    -

    -The approaches to machine learning are many, but are often split into +

    The approaches to machine learning are many, but are often split into two main categories. In supervised learning we know the answer to a problem, and let the computer deduce the logic behind it. On the other hand, unsupervised learning is a method for finding patterns and @@ -802,49 +718,40 @@ Some authours also operate with a third category, namely reinforcement learning. This is a paradigm of learning inspired by behavioral psychology, where learning is achieved by trial-and-error, solely from rewards and punishment. +

    -

    -Another way to categorize machine learning tasks is to consider the +

    Another way to categorize machine learning tasks is to consider the desired output of a system. Some of the most common tasks are: +

    • Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.
    • Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.
    • Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.
    -









    -

    Essential elements of ML

    -

    -The methods we cover have three main topics in common, irrespective of +

    The methods we cover have three main topics in common, irrespective of whether we deal with supervised or unsupervised learning. +

    -
    • The first ingredient is normally our data set (which can be subdivided into training, validation and test data). Many find the most difficult part of using Machine Learning to be the set up of your data in a meaningful way.
    • The second item is a model which is normally a function of some parameters. The model reflects our knowledge of the system (or lack thereof). As an example, if we know that our data show a behavior similar to what would be predicted by a polynomial, fitting our data to a polynomial of some degree would then determin our model.
    • The last ingredient is a so-called cost/loss function (or error or risk function) which allows us to present an estimate on how good our model is in reproducing the data it is supposed to train.
    - -











    -

    An optimization/minimization problem

    -

    -At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods. +

    At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods.

    -











    -

    A Frequentist approach to data analysis

    -

    -When you hear phrases like predictions and estimations and +

    When you hear phrases like predictions and estimations and correlations and causations, what do you think of? May be you think of the difference between classifying new data points and generating new data points. @@ -852,9 +759,9 @@ Or perhaps you consider that correlations represent some kind of symmetric state if \( A \) is correlated with \( B \), then \( B \) is correlated with \( A \). Causation on the other hand is directional, that is if \( A \) causes \( B \), \( B \) does not necessarily cause \( A \). +

    -

    -These concepts are in some sense the difference between machine +

    These concepts are in some sense the difference between machine learning and statistics. In machine learning and prediction based tasks, we are often interested in developing algorithms that are capable of learning patterns from given data in an automated fashion, @@ -863,51 +770,47 @@ assessments of newly given data. In many cases, our primary concern is the quality of the predictions or assessments, and we are less concerned about the underlying patterns that were learned in order to make these predictions. +

    -

    -In machine learning we normally use a so-called frequentist approach, +

    In machine learning we normally use a so-called frequentist approach, where the aim is to make predictions and find correlations. We focus less on for example extracting a probability distribution function (PDF). The PDF can be used in turn to make estimations and find causations such as given \( A \) what is the likelihood of finding \( B \). +

    -











    -

    What is a good model?

    -

    -In science and engineering we often end up in situations where we want to infer (or learn) a +

    In science and engineering we often end up in situations where we want to infer (or learn) a quantitative model \( M \) for a given set of sample points \( \boldsymbol{X} \in [x_1, x_2,\dots x_N] \). +

    -

    -As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a +

    As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a straight line, or if we wish to be more sophisticated to a more complex function. +

    -

    -The reason for inferring such a model is that it +

    The reason for inferring such a model is that it serves many useful purposes. On the one hand, the model can reveal information encoded in the data or underlying mechanisms from which the data were generated. For instance, we could discover important corelations that relate interesting physics interpretations. +

    -

    -In addition, it can simplify the representation of the given data set and help +

    In addition, it can simplify the representation of the given data set and help us in making predictions about future data samples. +

    -

    -A first important consideration to keep in mind is that inferring the correct model +

    A first important consideration to keep in mind is that inferring the correct model for a given data set is an elusive, if not impossible, task. The fundamental difficulty is that if we are not specific about what we mean by a correct model, there could easily be many different models that fit the given data set equally well. +

    -











    -

    What is a good model? Can we define it?

    -

    -The central question is this: what leads us to say that a model is correct or +

    The central question is this: what leads us to say that a model is correct or optimal for a given data set? To make the model inference problem well posed, i.e., to guarantee that there is a unique optimal model for the given data, we need to impose additional assumptions or restrictions on the class of models considered. To @@ -920,98 +823,90 @@ with the simplest possible class of models that is just necessary to describe th or solve the problem at hand. More precisely, the model class should be rich enough to contain at least one model that can fit the data to a desired accuracy and yet be restricted enough that it is relatively simple to find the best model for the given data. +

    -

    -Thus, the most popular strategy is to start from the +

    Thus, the most popular strategy is to start from the simplest class of models and increase the complexity of the models only when the simpler models become inadequate. For instance, if we work with a regression problem to fit a set of sample points, one may first try the simplest class of models, namely linear models, followed obviously by more complex models. +

    -

    -How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures. +

    How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures.

    -











    -

    Software and needed installations

    -

    -We will make extensive use of Python as programming language and its +

    We will make extensive use of Python as programming language and its myriad of available libraries. You will find 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, Julia, Fortran etc if you prefer. The focus in these lectures will be on Python. +

    -

    -If you have Python installed (we strongly recommend Python3) and you feel +

    If you have Python installed (we strongly recommend Python3) and you feel pretty familiar with installing different packages, we recommend that you install the following Python packages via pip as +

    1. pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow
    +

    For Python3, replace pip with pip3.

    -For Python3, replace pip with pip3. - -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for pyhton2.7)
    +

    etc etc.

    -etc etc. - -











    -

    Python installers

    -

    -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license. +

    -

    -Furthermore, Google's Colab is a free Jupyter notebook environment that requires +

    Furthermore, Google's Colab is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. Try it out! +

    -











    -

    Useful Python libraries

    -Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there) +

    Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)

    • NumPy is a highly popular library for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays
    • @@ -1026,13 +921,10 @@ Here we list several useful Python libraries we strongly recommend (if you use a
    • Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano
    • And many more such as pytorch, Theano etc
    -









    -

    Installing R, C++, cython or Julia

    -

    -You will also find it convenient to utilize R. We will mainly +

    You will also find it convenient to utilize R. We will mainly use Python during our lectures and in various projects and exercises. Those of you already familiar with R should feel free to continue using R, keeping @@ -1042,25 +934,23 @@ notebook allows you to run R codes interactively in your browser. The software library R is really tailored for statistical data analysis and allows for an easy usage of the tools and algorithms we will discuss in these lectures. +

    -

    -To install R with Jupyter notebook +

    To install R with Jupyter notebook follow the link here +

    -











    -

    Installing R, C++, cython, Numba etc

    -

    -For the C++ aficionados, Jupyter/IPython notebook allows you also to +

    For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for either Python or C++ (or Fortran or other compiled languages) as programming languages. +

    -

    -To add more entropy, cython can also be used when running your +

    To add more entropy, cython can also be used when running your notebooks. It means that Python with the jupyter notebook setup allows you to integrate widely popular softwares and tools for scientific computing. Similarly, the @@ -1069,43 +959,56 @@ capabilities with minimal rewrites of your codes. With its versatility, including symbolic operations, Python offers a unique computational environment. Your jupyter notebook can easily be converted into a nicely rendered PDF file or a Latex file for -further processing. For example, convert to latex as +further processing. For example, convert to latex as +

    -

    - -

    pycod jupyter nbconvert filename.ipynb --to latex 
    -
    -

    -And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. + +

    +
    +
    +
    +
    +
    pycod jupyter nbconvert filename.ipynb --to latex 
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    -Finally, if you wish to use the light mark-up language +

    And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python.

    + +

    Finally, if you wish to use the light mark-up language doconce you can convert a standard ascii text file into various HTML formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using doconce. +

    -











    -

    Numpy examples and Important Matrix and vector handling packages

    -

    -There are several central software libraries for linear algebra and eigenvalue problems. Several of the more +

    There are several central software libraries for linear algebra and eigenvalue problems. Several of the more popular ones have been wrapped into ofter software packages like those from the widely used text Numerical Recipes. The original source codes in many of the available packages are often taken from the widely used software package LAPACK, which follows two other popular packages developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly here. +

    • LINPACK: package for linear equations and least square problems.
    • LAPACK:package for solving symmetric, unsymmetric and generalized eigenvalue problems. From LAPACK's website http://www.netlib.org it is possible to download for free all source codes from this library. Both C/C++ and Fortran versions are available.
    • BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from http://www.netlib.org.
    -









    -

    Basic Matrix Features

    -

    Matrix properties reminder

    @@ -1124,15 +1027,14 @@ $$ \end{bmatrix} $$ -

    -The inverse of a matrix is defined by +

    The inverse of a matrix is defined by

    $$ \mathbf{A}^{-1} \cdot \mathbf{A} = I $$ -

    - + +
    @@ -1144,13 +1046,10 @@ $$
    Relations Name matrix elements
    \( A=\left(A^{\dagger}\right )^{-1} \) unitary \( \sum_k a_{ik}a_{jk}^{ < em>}=\sum_k a_{ki}^{ < /em> } a_{kj}=\delta_{ij} \)
    -

    -











    -

    Some famous Matrices

      @@ -1164,16 +1063,13 @@ $$
    • Upper banded with bandwidth \( p \): \( a_{ij}=0 \) for \( i < j+p \)
    • Banded, block upper triangular, block lower triangular....
    -









    -

    More Basic Matrix Features

    -

    Some Equivalent Statements

    -For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent +

    For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent

    • If the inverse of \( \mathbf{A} \) exists, \( \mathbf{A} \) is nonsingular.
    • @@ -1186,167 +1082,408 @@ For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all
    -











    -

    Numpy and arrays

    -Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as +

    Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as

    -

    -

    import numpy as np
    -
    -

    -Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution, -

    +

    +
    +
    +
    +
    +
    import numpy as np
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution,

    -
    n = 10
    +
    +
    +
    +
    +
    +
    n = 10
     x = np.random.normal(size=n)
     print(x)
    -
    -

    -We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). +

    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). Another alternative is to declare a vector as follows -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.array([1, 2, 3])
     print(x)
    -
    -

    -Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ start numbering array elements from \( 0 \) and on. This means that a vector with \( n \) elements has a sequence of entities \( x_0, x_1, x_2, \dots, x_{n-1} \). We could also let (recommended) Numpy to compute the logarithms of a specific array as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8]))
     print(x)
    -
    -

    -In the last example we used Numpy's unary function \( np.log \). This function is +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In the last example we used Numpy's unary function \( np.log \). This function is highly tuned to compute array elements since the code is vectorized and does not require looping. We normaly recommend that you use the Numpy intrinsic functions instead of the corresponding log function from Python's math module. The looping is done explicitely by the np.log function. The alternative, and slower way to compute the logarithms of a vector would be to write +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from math import log
     x = np.array([4, 7, 8])
     for i in range(0, len(x)):
         x[i] = log(x[i])
     print(x)
    -
    -

    -We note that our code is much longer already and we need to import the log function from the math module. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We note that our code is much longer already and we need to import the log function from the math module. The attentive reader will also notice that the output is \( [1, 1, 2] \). Python interprets automagically our numbers as integers (like the automatic keyword in C++). To change this we could define our array elements to be double precision numbers as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8], dtype = np.float64))
     print(x)
    -
    -

    -or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x)
    -
    -

    -To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x.itemsize)
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Matrices in Python

    -

    -Having defined vectors, we are now ready to try out matrices. We can +

    Having defined vectors, we are now ready to try out matrices. We can define a \( 3 \times 3 \) real matrix \( \boldsymbol{A} \) as (recall that we user lowercase letters for vectors and uppercase letters for matrices) +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     print(A)
    -
    -

    -If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[:,0]) 
    -
    -

    -We can continue this was by printing out other columns or rows. The example here prints out the second column -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can continue this was by printing out other columns or rows. The example here prints out the second column

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[1,:]) 
    -
    -

    -Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to zero
     A = np.zeros( (n, n) )
     print(A) 
    -
    -

    -or initializing all elements to -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or initializing all elements to

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to one
     A = np.ones( (n, n) )
     print(A) 
    -
    -

    -or as unitarily distributed random numbers (see the material on random number generators in the statistics part) -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or as unitarily distributed random numbers (see the material on random number generators in the statistics part)

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to random numbers with x \in [0, 1]
     A = np.random.rand(n, n)
     print(A) 
    -
    -

    -As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. As an example, consider the discussion of the covariance matrix. Suppose we have defined three vectors \( \boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z} \) with \( n \) elements each. The covariance matrix is defined as +

    $$ \boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ @@ -1354,13 +1491,14 @@ $$ \end{bmatrix}, $$ -where for example +

    where for example

    $$ \sigma_{xy} =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). $$ -The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. +

    The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. The following simple function uses the np.vstack function which takes each vector of dimension \( 1\times n \) and produces a \( 3\times n \) matrix \( \boldsymbol{W} \) +

    $$ \boldsymbol{W} = \begin{bmatrix} x_0 & x_1 & x_2 & \dots & x_{n-2} & x_{n-1} \\ y_0 & y_1 & y_2 & \dots & y_{n-2} & y_{n-1} \\ @@ -1368,17 +1506,21 @@ $$ \end{bmatrix}, $$ -

    -which in turn is converted into into the \( 3\times 3 \) covariance matrix +

    which in turn is converted into into the \( 3\times 3 \) covariance matrix \( \boldsymbol{\Sigma} \) via the Numpy function np.cov(). We note that we can also calculate the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy function np.mean(x). We can also extract the eigenvalues of the covariance matrix through the np.linalg.eig() function. +

    -

    -

    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     
     n = 100
    @@ -1393,11 +1535,26 @@ Sigma = np.cov(W)
     print(Sigma)
     Eigvals, Eigvecs = np.linalg.eig(Sigma)
     print(Eigvals)
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from scipy import sparse
     eye = np.eye(4)
    @@ -1408,30 +1565,49 @@ x = np.linspace(-10,'x')
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Meet the Pandas

    -

    -



    +

    +
    +

    +
    +

    -

    -Another useful Python package is +

    Another useful Python package is pandas, which is an open source library providing high-performance, easy-to-use data structures and data analysis tools for Python. pandas stands for panel data, a term borrowed from econometrics and is an efficient library for data analysis with an emphasis on tabular data. pandas has two major classes, the DataFrame class with two-dimensional data objects and tabular data organized in columns and the class Series with a focus on one-dimensional data objects. Both classes allow you to index data easily as we will see in the examples below. -pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +

    -

    -The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data. +

    The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data.

    -

    -

    import pandas as pd
    +
    +
    +
    +
    +
    +
    import pandas as pd
     from IPython.display import display
     data = {'First Name': ["Frodo", "Bilbo", "Aragorn II", "Samwise"],
             'Last Name': ["Baggins", "Baggins","Elessar","Gamgee"],
    @@ -1440,45 +1616,115 @@ data = {'First Name': [
    +    
    +
    +
    +
    +
    +
    +
    +
    + +

    In the above we have imported pandas with the shorthand pd, the latter has become the standard way we import pandas. We make then a list of various variables and reorganize the aboves lists into a DataFrame and then print out a neat table with specific column labels as Name, place of birth and date of birth. Displaying these results, we see that the indices are given by the default numbers from zero to three. pandas is extremely flexible and we can easily change the above indices by defining a new type of indexing as -

    +

    -
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
    +
    +
    +
    +
    +
    +
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
     display(data_pandas)
    -
    -

    -Thereafter we display the content of the row which begins with the index Aragorn -

    +

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Thereafter we display the content of the row which begins with the index Aragorn

    -
    display(data_pandas.loc['Aragorn'])
    -
    -

    -We can easily append data to this, for example -

    +

    +
    +
    +
    +
    +
    display(data_pandas.loc['Aragorn'])
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily append data to this, for example

    -
    new_hobbit = {'First Name': ["Peregrin"],
    +
    +
    +
    +
    +
    +
    new_hobbit = {'First Name': ["Peregrin"],
                   'Last Name': ["Took"],
                   'Place of birth': ["Shire"],
                   'Date of Birth T.A.': [2990]
                   }
     data_pandas=data_pandas.append(pd.DataFrame(new_hobbit, index=['Pippin']))
     display(data_pandas)
    -
    -

    -Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix of dimensionality \( 10\times 5 \) and compute the mean value and standard deviation of each column. Similarly, we can perform mathematial operations like squaring the matrix elements and many other operations. -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     np.random.seed(100)
    @@ -1491,13 +1737,30 @@ display(df)
     print(df.mean())
     print(df.std())
     display(df**2)
    -
    -

    -Thereafter we can select specific columns only and plot final results -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Thereafter we can select specific columns only and plot final results

    -
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
    +
    +
    +
    +
    +
    +
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
     df.index = np.arange(10)
     
     display(df)
    @@ -1515,49 +1778,71 @@ plt.show()
     
     df.plot.bar(figsize=(10,6), rot=15)
     plt.show()
    -
    -

    -We can produce a \( 4\times 4 \) matrix -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can produce a \( 4\times 4 \) matrix

    -
    b = np.arange(16).reshape((4,4))
    +
    +
    +
    +
    +
    +
    b = np.arange(16).reshape((4,4))
     print(b)
     df1 = pd.DataFrame(b)
     print(df1)
    -
    -

    -and many other operations. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -The Series class is another important class included in +

    and many other operations.

    + +

    The Series class is another important class included in pandas. You can view it as a specialization of DataFrame but where we have just a single column of data. It shares many of the same features as _DataFrame. As with DataFrame, most operations are vectorized, achieving thereby a high performance when dealing with computations of arrays, in particular labeled arrays. As we will see below it leads also to a very concice code close to the mathematical operations we may be interested in. -For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +

    -











    -

    Friday August 27

    -

    -"Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage

    -

    -Video of Lecture from fall 2020 and Handwritten notes +

    Video of Lecture from fall 2020 and Handwritten notes

    -











    +

    Simple linear regression model using scikit-learn

    -

    Simple linear regression model using scikit-learn

    +

    We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us.

    -

    -We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us. - -

    -What follows is a simple Python code where we have defined a function +

    What follows is a simple Python code where we have defined a function \( y \) in terms of the variable \( x \). Both are defined as vectors with \( 100 \) entries. The numbers in the vector \( \boldsymbol{x} \) are given by random numbers generated with a uniform distribution with entries @@ -1565,9 +1850,9 @@ by random numbers generated with a uniform distribution with entries later). These values are then used to define a function \( y(x) \) (tabulated again as a vector) with a linear dependence on \( x \) plus a random noise added via the normal distribution. +

    -

    -The Numpy functions are imported used the import numpy as np +

    The Numpy functions are imported used the import numpy as np statement and the random number generator for the uniform distribution is called using the function np.random.rand(), where we specificy that we want \( 100 \) random variables. Using Numpy we define @@ -1576,13 +1861,13 @@ our case. With the Numpy function randn() we can compute random numbers with the normal distribution (mean value \( \mu \) equal to zero and variance \( \sigma^2 \) set to one) and produce the values of \( y \) assuming a linear dependence as function of \( x \) +

    $$ y = 2x+N(0,1), $$ -

    -where \( N(0,1) \) represents random numbers generated by the normal +

    where \( N(0,1) \) represents random numbers generated by the normal distribution. From Scikit-Learn we import then the LinearRegression functionality and make a prediction \( \tilde{y} = \alpha + \beta x \) using the function fit(x,y). We call the set of @@ -1590,22 +1875,26 @@ data \( (\boldsymbol{x},\boldsymbol{y}) \) for our training data. The Python pac scikit-learn has also a functionality which extracts the above fitting parameters \( \alpha \) and \( \beta \) (see below). Later we will distinguish between training data and test data. +

    -

    -For plotting we use the Python package +

    For plotting we use the Python package matplotlib which produces publication quality figures. Feel free to explore the extensive gallery of examples. In this example we plot our original values of \( x \) and \( y \) as well as the prediction ypredict (\( \tilde{y} \)), which attempts at fitting our data with a straight line. +

    -

    -The Python code follows here. -

    +

    The Python code follows here.

    -
    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
    @@ -1624,9 +1913,22 @@ plt.xlabel(r'$x$')
     plt.ylabel(r'$y$')
     plt.title(r'Simple Linear Regression')
     plt.show()
    -
    -

    -This example serves several aims. It allows us to demonstrate several +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    This example serves several aims. It allows us to demonstrate several aspects of data analysis and later machine learning algorithms. The immediate visualization shows that our linear fit is not impressive. It goes through the data points, but there are many @@ -1634,38 +1936,38 @@ outliers which are not reproduced by our linear regression. We could now play around with this small program and change for example the factor in front of \( x \) and the normal distribution. Try to change the function \( y \) to +

    $$ y = 10x+0.01 \times N(0,1), $$ -

    -where \( x \) is defined as before. Does the fit look better? Indeed, by +

    where \( x \) is defined as before. Does the fit look better? Indeed, by reducing the role of the noise given by the normal distribution we see immediately that our linear prediction seemingly reproduces better the training set. However, this testing 'by the eye' is obviouly not satisfactory in the long run. Here we have only defined the training data and our model, and have not discussed a more rigorous approach to the cost function. +

    -

    -We need more rigorous criteria in defining whether we have succeeded or +

    We need more rigorous criteria in defining whether we have succeeded or not in modeling our training data. You will be surprised to see that many scientists seldomly venture beyond this 'by the eye' approach. A standard approach for the cost function is the so-called \( \chi^2 \) function (a variant of the mean-squared error (MSE)) +

    $$ \chi^2 = \frac{1}{n} \sum_{i=0}^{n-1}\frac{(y_i-\tilde{y}_i)^2}{\sigma_i^2}, $$ -

    -where \( \sigma_i^2 \) is the variance (to be defined later) of the entry +

    where \( \sigma_i^2 \) is the variance (to be defined later) of the entry \( y_i \). We may not know the explicit value of \( \sigma_i^2 \), it serves however the aim of scaling the equations and make the cost function -dimensionless. +dimensionless. +

    -

    -Minimizing the cost function is a central aspect of +

    Minimizing the cost function is a central aspect of our discussions to come. Finding its minima as function of the model parameters (\( \alpha \) and \( \beta \) in our case) will be a recurring theme in these series of lectures. Essentially all machine learning @@ -1678,30 +1980,34 @@ employed are various variants of gradient methods. These will be discussed in more detail later. Again, you'll be surprised to hear that many practitioners minimize the above function ''by the eye', popularly dubbed as 'chi by the eye'. That is, change a parameter and see (visually and numerically) that -the \( \chi^2 \) function becomes smaller. +the \( \chi^2 \) function becomes smaller. +

    -

    -There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define +

    There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define the relative error (why would we prefer the MSE instead of the relative error?) as +

    $$ \epsilon_{\mathrm{relative}}= \frac{\vert \boldsymbol{y} -\boldsymbol{\tilde{y}}\vert}{\vert \boldsymbol{y}\vert}. $$ -

    -The squared cost function results in an arithmetic mean-unbiased +

    The squared cost function results in an arithmetic mean-unbiased estimator, and the absolute-value cost function results in a median-unbiased estimator (in the one-dimensional case, and a geometric median-unbiased estimator for the multi-dimensional case). The squared cost function has the disadvantage that it has the tendency to be dominated by outliers. +

    -

    -We can modify easily the above Python code and plot the relative error instead -

    +

    We can modify easily the above Python code and plot the relative error instead

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
     
    @@ -1717,26 +2023,44 @@ plt.xlabel(r'$x$')
     plt.ylabel(r'$\epsilon_{\mathrm{relative}}$')
     plt.title(r'Relative error')
     plt.show()
    -
    -

    -Depending on the parameter in front of the normal distribution, we may +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Depending on the parameter in front of the normal distribution, we may have a small or larger relative error. Try to play around with different training data sets and study (graphically) the value of the relative error. +

    -

    -As mentioned above, Scikit-Learn has an impressive functionality. +

    As mentioned above, Scikit-Learn has an impressive functionality. We can for example extract the values of \( \alpha \) and \( \beta \) and their error estimates, or the variance and standard deviation and many -other properties from the statistical data analysis. +other properties from the statistical data analysis. +

    -

    -Here we show an +

    Here we show an example of the functionality of Scikit-Learn. -

    +

    -
    import numpy as np 
    +
    +
    +
    +
    +
    +
    import numpy as np 
     import matplotlib.pyplot as plt 
     from sklearn.linear_model import LinearRegression 
     from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error
    @@ -1763,84 +2087,101 @@ plt.xlabel(r'$x$')
     plt.ylabel(r'$y$')
     plt.title(r'Linear Regression fit ')
     plt.show()
    -
    -

    -The function coef gives us the parameter \( \beta \) of our fit while intercept yields +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The function coef gives us the parameter \( \beta \) of our fit while intercept yields \( \alpha \). Depending on the constant in front of the normal distribution, we get values near or far from \( \alpha =2 \) and \( \beta =5 \). Try to play around with different parameters in front of the normal distribution. The function meansquarederror gives us the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error or loss defined as +

    $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -

    -The smaller the value, the better the fit. Ideally we would like to +

    The smaller the value, the better the fit. Ideally we would like to have an MSE equal zero. The attentive reader has probably recognized this function as being similar to the \( \chi^2 \) function defined above. +

    -

    -The r2score function computes \( R^2 \), the coefficient of +

    The r2score function computes \( R^2 \), the coefficient of determination. It provides a measure of how well future samples are likely to be predicted by the model. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of \( \boldsymbol{y} \), disregarding the input features, would get a \( R^2 \) score of \( 0.0 \). +

    -

    -If \( \tilde{\boldsymbol{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 +

    If \( \tilde{\boldsymbol{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

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -Another quantity taht we will meet again in our discussions of regression analysis is +

    Another quantity taht we will meet again in our discussions of regression analysis is the mean absolute error (MAE), a risk metric corresponding to the expected value of the absolute error loss or what we call the \( l1 \)-norm loss. In our discussion above we presented the relative error. The MAE is defined as follows +

    $$ \text{MAE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. $$ -We present the +

    We present the squared logarithmic (quadratic) error +

    $$ \text{MSLE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, $$ -

    -where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error +

    where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error estimate is best to use when targets having exponential growth, such as population counts, average sales of a commodity over a span of -years etc. +years etc. +

    -

    -Finally, another cost function is the Huber cost function used in robust regression. +

    Finally, another cost function is the Huber cost function used in robust regression.

    -

    -The rationale behind this possible cost function is its reduced +

    The rationale behind this possible cost function is its reduced sensitivity to outliers in the data set. In our discussions on dimensionality reduction and normalization of data we will meet other ways of dealing with outliers. +

    -

    -The Huber cost function is defined as +

    The Huber cost function is defined as

    $$ H_{\delta}(\boldsymbol{a})=\left\{\begin{array}{cc}\frac{1}{2} \boldsymbol{a}^{2}& \text{for }|\boldsymbol{a}|\leq \delta\\ \delta (|\boldsymbol{a}|-\frac{1}{2}\delta ),&\text{otherwise}.\end{array}\right. $$ -Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \). +

    Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \).

    -

    -We will discuss in more detail these and other functions in the +

    We will discuss in more detail these and other functions in the various lectures. We conclude this part with another example. Instead of a linear \( x \)-dependence we study now a cubic polynomial and use the polynomial regression analysis tools of scikit-learn. +

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     import random
     from sklearn.linear_model import Ridge
    @@ -1870,74 +2211,85 @@ plt.show()
         return abs(np.sum(err))/len(err)
     
     print (error(y))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    To our real data: nuclear binding energies. Brief reminder on masses and binding energies

    -

    -Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding +

    Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding energies. A basic quantity which can be measured for the ground states of nuclei is the atomic mass \( M(N, Z) \) of the neutral atom with -atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +

    -

    -Atomic masses are usually tabulated in terms of the mass excess defined by +

    Atomic masses are usually tabulated in terms of the mass excess defined by

    $$ \Delta M(N, Z) = M(N, Z) - uA, $$ -where \( u \) is the Atomic Mass Unit +

    where \( u \) is the Atomic Mass Unit

    $$ u = M(^{12}\mathrm{C})/12 = 931.4940954(57) \hspace{0.1cm} \mathrm{MeV}/c^2. $$ -The nucleon masses are +

    The nucleon masses are

    $$ m_p = 1.00727646693(9)u, $$ -and +

    and

    $$ m_n = 939.56536(8)\hspace{0.1cm} \mathrm{MeV}/c^2 = 1.0086649156(6)u. $$ -

    -In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu +

    In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu there are data on masses and decays of 3437 nuclei. +

    -

    -The nuclear binding energy is defined as the energy required to break +

    The nuclear binding energy is defined as the energy required to break up a given nucleus into its constituent parts of \( N \) neutrons and \( Z \) protons. In terms of the atomic masses \( M(N, Z) \) the binding energy is defined by +

    $$ BE(N, Z) = ZM_H c^2 + Nm_n c^2 - M(N, Z)c^2 , $$ -where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. +

    where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. In terms of the mass excess the binding energy is given by +

    $$ BE(N, Z) = Z\Delta_H c^2 + N\Delta_n c^2 -\Delta(N, Z)c^2 , $$ -where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV. +

    where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV.

    -

    -A popular and physically intuitive model which can be used to parametrize +

    A popular and physically intuitive model which can be used to parametrize the experimental binding energies as function of \( A \), is the so-called liquid drop model. The ansatz is based on the following expression +

    $$ BE(N,Z) = a_1A-a_2A^{2/3}-a_3\frac{Z^2}{A^{1/3}}-a_4\frac{(N-Z)^2}{A}, $$ -

    -where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit -to the experimental data. +

    where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit +to the experimental data. +

    -

    -To arrive at the above expression we have assumed that we can make the following assumptions: +

    To arrive at the above expression we have assumed that we can make the following assumptions:

    - -We could also add a so-called pairing term, which is a correction term that +

    We could also add a so-called pairing term, which is a correction term that arises from the tendency of proton pairs and neutron pairs to -occur. An even number of particles is more stable than an odd number. - +occur. An even number of particles is more stable than an odd number. +

    Organizing our data

    -

    -Let us start with reading and organizing our data. +

    Let us start with reading and organizing our data. We start with the compilation of masses and binding energies from 2016. After having downloaded this file to our own computer, we are now ready to read the file and start structuring our data. +

    -

    -We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn. -

    +

    We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -1995,13 +2349,30 @@ DATA_ID = "DataFiles/"
         plt.savefig(image_path(fig_id) + ".png", format='png')
     
     infile = open(data_path("MassEval2016.dat"),'r')
    -
    -

    -Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function.

    -
    from pylab import plt, mpl
    +
    +
    +
    +
    +
    +
    from pylab import plt, mpl
     plt.style.use('seaborn')
     mpl.rcParams['font.family'] = 'serif'
     
    @@ -2012,20 +2383,37 @@ mpl.rcParams['font.family'] = 0])
             plt.ylabel(axlabels[1])
         plt.legend(loc=0)
    -
    -

    -Our next step is to read the data on experimental binding energies and +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Our next step is to read the data on experimental binding energies and reorganize them as functions of the mass number \( A \), the number of protons \( Z \) and neutrons \( N \) using pandas. Before we do this it is always useful (unless you have a binary file or other types of compressed data) to actually open the file and simply take a look at it! +

    -

    -In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information. -

    +

    In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information.

    -
    """                                                                                                                         
    +
    +
    +
    +
    +
    +
    """                                                                                                                         
     This is taken from the data file of the mass 2016 evaluation.                                                               
     All files are 3436 lines long with 124 character per line.                                                                  
            Headers are 39 lines long.                                                                                           
    @@ -2035,17 +2423,35 @@ In particular, the program that outputs the final nuclear masses is written in F
        widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),                                                            
        Pandas has also a variable header, with length 39 in this case.                                                          
     """
    -
    -

    -The data we are interested in are in columns 2, 3, 4 and 11, giving us +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The data we are interested in are in columns 2, 3, 4 and 11, giving us the number of neutrons, protons, mass numbers and binding energies, respectively. We add also for the sake of completeness the element name. The data are in fixed-width formatted lines and we will covert them into the pandas DataFrame structure. +

    -

    -

    # Read the experimental data with Pandas
    +
    +
    +
    +
    +
    +
    # Read the experimental data with Pandas
     Masses = pd.read_fwf(infile, usecols=(2,3,4,6,11),
                   names=('N', 'Z', 'A', 'Element', 'Ebinding'),
                   widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),
    @@ -2063,58 +2469,129 @@ Masses['Ebinding'] /= 'A')
     # Find the rows of the grouped DataFrame with the maximum binding energy.
     Masses = Masses.apply(lambda t: t[t.Ebinding==t.Ebinding.max()])
    -
    -

    -We have now read in the data, grouped them according to the variables we are interested in. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We have now read in the data, grouped them according to the variables we are interested in. We see how easy it is to reorganize the data using pandas. If we were to do these operations in C/C++ or Fortran, we would have had to write various functions/subroutines which perform the above reorganizations for us. Having reorganized the data, we can now start to make some simple fits using both the functionalities in numpy and -Scikit-Learn afterwards. +Scikit-Learn afterwards. +

    -

    -Now we define five variables which contain +

    Now we define five variables which contain the number of nucleons \( A \), the number of protons \( Z \) and the number of neutrons \( N \), the element name and finally the energies themselves. -

    +

    -
    A = Masses['A']
    +
    +
    +
    +
    +
    +
    A = Masses['A']
     Z = Masses['Z']
     N = Masses['N']
     Element = Masses['Element']
     Energies = Masses['Ebinding']
     print(Masses)
    -
    -

    -The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). It has dimensionality \( p\times n \), where \( n \) is the number of data points and \( p \) are the so-called predictors. In our case here they are given by the number of polynomials in \( A \) we wish to include in the fit. -

    +

    -
    # Now we set up the design matrix X
    +
    +
    +
    +
    +
    +
    # Now we set up the design matrix X
     X = np.zeros((len(A),5))
     X[:,0] = 1
     X[:,1] = A
     X[:,2] = A**(2.0/3.0)
     X[:,3] = A**(-1.0/3.0)
     X[:,4] = A**(-1.0)
    -
    -

    -With scikitlearn we are now ready to use linear regression and fit our data. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With scikitlearn we are now ready to use linear regression and fit our data.

    -
    clf = skl.LinearRegression().fit(X, Energies)
    +
    +
    +
    +
    +
    +
    clf = skl.LinearRegression().fit(X, Energies)
     fity = clf.predict(X)
    -
    -

    -Pretty simple! +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Pretty simple! Now we can print measures of how our fit is doing, the coefficients from the fits and plot the final fit together with our data. -

    +

    -
    # The mean squared error                               
    +
    +
    +
    +
    +
    +
    # The mean squared error                               
     print("Mean squared error: %.2f" % mean_squared_error(Energies, fity))
     # Explained variance score: 1 is perfect prediction                                 
     print('Variance score: %.2f' % r2_score(Energies, fity))
    @@ -2134,17 +2611,32 @@ ax.plot(Masses['A'], Masses["Masses2016")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    Seeing the wood for the trees

    -

    -As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests! +

    As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests!

    -

    -

    #Decision Tree Regression
    +
    +
    +
    +
    +
    +
    #Decision Tree Regression
     from sklearn.tree import DecisionTreeRegressor
     regr_1=DecisionTreeRegressor(max_depth=5)
     regr_2=DecisionTreeRegressor(max_depth=7)
    @@ -2173,16 +2665,32 @@ save_fig("Masses2016Trees")
     plt.show()
     print(Masses)
     print(np.mean( (Energies-y_1)**2))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    And what about using neural networks?

    - -The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) +

    The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) functionality. -

    +

    -
    from sklearn.neural_network import MLPRegressor
    +
    +
    +
    +
    +
    +
    from sklearn.neural_network import MLPRegressor
     from sklearn.metrics import accuracy_score
     import seaborn as sns
     
    @@ -2211,30 +2719,38 @@ ax.set_title("Training Accuracy")
     ax.set_ylabel("$\eta$")
     ax.set_xlabel("$\lambda$")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    A first summary

    -

    -The aim behind these introductory words was to present to you various +

    The aim behind these introductory words was to present to you various Python libraries and their functionalities, in particular libraries like numpy, pandas, xarray and matplotlib and other that make our life much easier -in handling various data sets and visualizing data. +in handling various data sets and visualizing data. +

    -

    -Furthermore, +

    Furthermore, Scikit-Learn allows us with few lines of code to implement popular Machine Learning algorithms for supervised learning. Later we will meet Tensorflow, a powerful library for deep learning. Now it is time to dive more into the details of various methods. We will start with linear regression and try to take a deeper look at what it entails. +

    -











    -

    Why Linear Regression (aka Ordinary Least Squares and family)

    -

    -Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \). - +

    Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).

    - -For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. +

    For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. Similarly, Mehta et al's article is also recommended. +

    -











    -

    Regression analysis, overarching aims

    -

    -Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). -The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. - -

    -A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with +

    Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). +The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. +

    +

    A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with

    • \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)
    • Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)
    • \( p \) so-called explanatory (independent or predictor) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.
    - - The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things. +

    The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.

    -











    -

    Regression analysis, overarching aims II

    -

    -Consider an experiment in which \( p \) characteristics of \( n \) samples are +

    Consider an experiment in which \( p \) characteristics of \( n \) samples are measured. The data from this experiment, for various explanatory variables \( p \) are normally represented by a matrix \( \mathbf{X} \). +

    -

    -The matrix \( \mathbf{X} \) is called the design +

    The matrix \( \mathbf{X} \) is called the design matrix. Additional information of the samples is available in the form of \( \boldsymbol{y} \) (also as above). The variable \( \boldsymbol{y} \) is generally referred to as the response variable. The aim of @@ -2299,73 +2807,62 @@ f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of \( f(\cdot) \) is available, it is common to assume a linear relationship between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to the linear regression model where \( \boldsymbol{\beta} = [\beta_0, \ldots, -\beta_{p-1}]^{T} \) are the regression parameters. - -

    -Linear regression gives us a set of analytical equations for the parameters \( \beta_j \). - +\beta_{p-1}]^{T} \) are the regression parameters. +

    +

    Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).

    -











    -

    Examples

    -In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), -consider the model we discussed for describing nuclear binding energies. +

    In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), +consider the model we discussed for describing nuclear binding energies. +

    -

    -There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. +

    There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. Assuming +

    $$ BE(A) = a_0+a_1A+a_2A^{2/3}+a_3A^{-1/3}+a_4A^{-1}, $$ -we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. +

    we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. This gives \( p=0,1,2,3,4 \). Furthermore we have \( n \) entries for each predictor. It means that our design matrix is a \( p\times n \) matrix \( \boldsymbol{X} \). +

    -

    -Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the -so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. - - +

    Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the +so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. +

    -











    -

    General linear models

    -Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function. +

    Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function.

    -

    -Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is +

    Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is

    $$ y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i, $$ -where \( \epsilon_i \) is the error in our approximation. - - +

    where \( \epsilon_i \) is the error in our approximation.

    -











    -

    Rewriting the fitting procedure as a linear algebra problem

    -For every set of values \( y_i,x_i \) we have thus the corresponding set of equations +

    For every set of values \( y_i,x_i \) we have thus the corresponding set of equations

    $$ \begin{align*} y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\ @@ -2378,29 +2875,27 @@ $$
    -











    -

    Rewriting the fitting procedure as a linear algebra problem, more details

    -Defining the vectors +

    Defining the vectors

    $$ \boldsymbol{y} = [y_0,y_1, y_2,\dots, y_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\epsilon} = [\epsilon_0,\epsilon_1, \epsilon_2,\dots, \epsilon_{n-1}]^T, $$ -and the design matrix +

    and the design matrix

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -2412,29 +2907,27 @@ $$ \end{bmatrix} $$ -we can rewrite our equations as +

    we can rewrite our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The above design matrix is called a Vandermonde matrix. +

    The above design matrix is called a Vandermonde matrix.

    -











    -

    Generalizing the fitting procedure as a linear algebra problem

    -

    -We are obviously not limited to the above polynomial expansions. We +

    We are obviously not limited to the above polynomial expansions. We could replace the various powers of \( x \) with elements of Fourier series or instead of \( x_i^j \) we could have \( \cos{(j x_i)} \) or \( \sin{(j x_i)} \), or time series or other orthogonal functions. For every set of values \( y_i,x_i \) we can then generalize the equations to +

    $$ \begin{align*} @@ -2448,19 +2941,17 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    + Note that we have \( p=n \) here. The matrix is symmetric. This is generally not the case!

    -











    -

    Generalizing the fitting procedure as a linear algebra problem

    -We redefine in turn the matrix \( \boldsymbol{X} \) as +

    We redefine in turn the matrix \( \boldsymbol{X} \) as

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -2472,23 +2963,21 @@ x_{n-1,0}& x_{n-1,1} &x_{n-1,2}& \dots & \dots &x_{n-1,n-1}\\ \end{bmatrix} $$ -and without loss of generality we rewrite again our equations as +

    and without loss of generality we rewrite again our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? +

    The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values?

    -











    -

    Optimizing our parameters

    -We have defined the matrix \( \boldsymbol{X} \) via the equations +

    We have defined the matrix \( \boldsymbol{X} \) via the equations

    $$ \begin{align*} y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\ @@ -2501,29 +2990,27 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    -As we noted above, we stayed with a system with the design matrix +

    As we noted above, we stayed with a system with the design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times n} \), that is we have \( p=n \). For reasons to come later (algorithmic arguments) we will hereafter define our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors refering to the column numbers and the entries \( n \) being the row elements. - - +

    -











    -

    Our model for the nuclear binding energies

    -

    -In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code. +

    In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code.

    -

    -We restate the parts of the code we are most interested in. -

    +

    We restate the parts of the code we are most interested in.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -2592,73 +3079,81 @@ DesignMatrix = pd.DataFrame(X)
     DesignMatrix.index = A
     DesignMatrix.columns = ['1', 'A', 'A^(2/3)', 'A^(-1/3)', '1/A']
     display(DesignMatrix)
    -
    -

    -With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -throughout these lectures. +

    throughout these lectures.

    -











    -

    Optimizing our parameters, more details

    -With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as +

    With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely +

    and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as +

    or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -This function is one possible way to define the so-called cost function. +

    This function is one possible way to define the so-called cost function.

    -

    -It is also common to define +

    It is also common to define the function \( C \) as +

    $$ C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2, $$ -since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. +

    since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out.

    -











    -

    Interpretations and optimizing our parameters

    -

    -The function +

    The function

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}, $$ -can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. +

    can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value +

    $$ y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i, $$ -

    -where \( \langle y_i \rangle \) is the mean value. Keep in mind also that +

    where \( \langle y_i \rangle \) is the mean value. Keep in mind also that till now we have treated \( y_i \) as the exact value. Normally, the response (dependent or outcome) variable \( y_i \) the outcome of a numerical experiment or another type of experiment and is thus only an @@ -2666,57 +3161,52 @@ approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem

    $$ {\displaystyle \min_{\boldsymbol{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -In practical terms it means we will require +

    In practical terms it means we will require

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right). $$ - -
    -











    -

    Interpretations and optimizing our parameters

    -We can rewrite +

    We can rewrite

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$ -

    -We note also that since our design matrix is defined as \( \boldsymbol{X}\in +

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), the product \( \boldsymbol{X}^T\boldsymbol{X} \in {\mathbb{R}}^{p\times p} \). In the above case we have that \( p \ll n \), in our case \( p=5 \) meaning that we end up with inverting a small @@ -2725,26 +3215,24 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). +\( \boldsymbol{X}^T\boldsymbol{X} \). +

    -

    -Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect? +

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    -











    -

    Some useful matrix and vector expressions

    -

    -The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and +

    The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and matrices as upper case boldfaced letters. +

    $$ \frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, @@ -2763,65 +3251,97 @@ $$ $$









    -

    Interpretations and optimizing our parameters

    -The residuals \( \boldsymbol{\epsilon} \) are in turn given by +

    The residuals \( \boldsymbol{\epsilon} \) are in turn given by

    $$ \boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}, $$ -and with +

    and with

    $$ \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -we have +

    we have

    $$ \boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach. - - +

    meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.

    -

    -Let us now return to our nuclear binding energies and simply code the above equations. +

    Let us now return to our nuclear binding energies and simply code the above equations.

    -











    -

    Own code for Ordinary Least Squares

    -

    -It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to +

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to write -

    +

    -
    # matrix inversion to find beta
    +
    +
    +
    +
    +
    +
    # matrix inversion to find beta
     beta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Energies)
     # and then make the prediction
     ytilde = X @ beta
    -
    -

    -Alternatively, you can use the least squares functionality in Numpy as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Alternatively, you can use the least squares functionality in Numpy as

    -
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
    +
    +
    +
    +
    +
    +
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
     ytildenp = np.dot(fit,X.T)
    -
    -

    -And finally we plot our fit with and compare with data -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    And finally we plot our fit with and compare with data

    -
    Masses['Eapprox']  = ytilde
    +
    +
    +
    +
    +
    +
    Masses['Eapprox']  = ytilde
     # Generate a plot comparing the experimental with the fitted values values.
     fig, ax = plt.subplots()
     ax.set_xlabel(r'$A = N + Z$')
    @@ -2833,200 +3353,266 @@ ax.plot(Masses['A'], Masses["Masses2016OLS")
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Adding error analysis and training set up

    -

    -We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. +

    We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. Since we are not using Scikit-Learn here we can define our own \( R2 \) function as -

    +

    -
    def R2(y_data, y_model):
    +
    +
    +
    +
    +
    +
    def R2(y_data, y_model):
         return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    -
    -

    -and we would be using it as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and we would be using it as

    -
    print(R2(Energies,ytilde))
    -
    -

    -We can easily add our MSE score as -

    +

    +
    +
    +
    +
    +
    print(R2(Energies,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily add our MSE score as

    -
    def MSE(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def MSE(y_data,y_model):
         n = np.size(y_model)
         return np.sum((y_data-y_model)**2)/n
     
     print(MSE(Energies,ytilde))
    -
    -

    -and finally the relative error as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and finally the relative error as

    -
    def RelativeError(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def RelativeError(y_data,y_model):
         return abs((y_data-y_model)/y_data)
     print(RelativeError(Energies, ytilde))
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    The \( \chi^2 \) function

    -

    -Normally, the response (dependent or outcome) variable \( y_i \) is the +

    Normally, the response (dependent or outcome) variable \( y_i \) is the outcome of a numerical experiment or another type of experiment and is thus only an approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -Introducing the standard deviation \( \sigma_i \) for each measurement +

    Introducing the standard deviation \( \sigma_i \) for each measurement \( y_i \), we define now the \( \chi^2 \) function (omitting the \( 1/n \) term) as +

    $$ \chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. - - +

    where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements.

    -











    -

    The \( \chi^2 \) function

    -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right). $$ -where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). +

    where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \).

    -











    -

    The \( \chi^2 \) function

    -

    -We can rewrite +

    We can rewrite

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}. $$
    -











    -

    The \( \chi^2 \) function

    -

    -If we then introduce the matrix +

    If we then introduce the matrix

    $$ \boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}, $$ -we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \)) +

    we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))

    $$ \beta_j = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}\frac{y_i}{\sigma_i}\frac{x_{ik}}{\sigma_i} = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}b_ia_{ik} $$ -We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise) +

    We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)

    $$ \sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2, $$ -resulting in +

    resulting in

    $$ \sigma^2(\beta_j) = \left(\sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}a_{ik}\right)\left(\sum_{l=0}^{p-1}h_{jl}\sum_{m=0}^{n-1}a_{ml}\right) = h_{jj}! $$
    -











    -

    The \( \chi^2 \) function

    -The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write +

    The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write

    $$ y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i. $$ -By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by +

    By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0, $$ -and +

    and

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0. $$
    -











    -

    The \( \chi^2 \) function

    -

    -For a linear fit (a first-order polynomial) we don't need to invert a matrix!! +

    For a linear fit (a first-order polynomial) we don't need to invert a matrix!! Defining +

    $$ \gamma = \sum_{i=0}^{n-1}\frac{1}{\sigma_i^2}, $$ @@ -3051,8 +3637,7 @@ $$ \gamma_{xy} = \sum_{i=0}^{n-1}\frac{y_ix_{i}}{\sigma_i^2}, $$ -

    -we obtain +

    we obtain

    $$ \beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}, @@ -3063,50 +3648,48 @@ $$ \beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}. $$ -

    -This approach (different linear and non-linear regression) suffers +

    This approach (different linear and non-linear regression) suffers often from both being underdetermined and overdetermined in the unknown coefficients \( \beta_i \). A better approach is to use the Singular Value Decomposition (SVD) method discussed next week. - - +

    -











    -

    Fitting an Equation of State for Dense Nuclear Matter

    -

    -Before we continue, let us introduce yet another example. We are going to fit the +

    Before we continue, let us introduce yet another example. We are going to fit the nuclear equation of state using results from many-body calculations. The equation of state we have made available here, as function of density, has been derived using modern nucleon-nucleon potentials with the addition of three-body forces. This time the file is presented as a standard csv file. +

    -

    -The beginning of the Python code here is similar to what you have seen +

    The beginning of the Python code here is similar to what you have seen before, with the same initializations and declarations. We use also pandas again, rather extensively in order to organize our data. +

    -

    -The difference now is that we use Scikit-Learn's regression tools +

    The difference now is that we use Scikit-Learn's regression tools instead of our own matrix inversion implementation. Furthermore, we sneak in Ridge regression (to be discussed below) which includes a hyperparameter \( \lambda \), also to be explained below. +

    -











    -

    The code

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -3191,23 +3774,34 @@ ax.plot(EoS['Density'], EoS["EoSfitting")
     plt.show()
    -
    -

    -The above simple polynomial in density \( \rho \) gives an excellent fit -to the data. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -We note also that there is a small deviation between the +

    The above simple polynomial in density \( \rho \) gives an excellent fit +to the data. +

    + +

    We note also that there is a small deviation between the standard OLS and the Ridge regression at higher densities. We discuss this in more detail below. +

    -











    -

    Splitting our Data in Training and Test data

    -

    -It is normal in essentially all Machine Learning studies to split the +

    It is normal in essentially all Machine Learning studies to split the data in a training set and a test set (sometimes also an additional validation set). Scikit-Learn has an own function for this. There is no explicit recipe for how much data should be included as training @@ -3217,11 +3811,16 @@ postpone a discussion of this splitting to the end of these notes and our discussion of the so-called bias-variance tradeoff. Here we limit ourselves to repeat the above equation of state fitting example but now splitting the data into a training set and a test set. +

    -

    -

    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -3285,144 +3884,172 @@ ypredict = X_test @ beta
     print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    -

    Exercises for week 35

    -Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1. +

    Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1.

    -

    -

    Exercise 1: Setting up various Python environments

    -

    -The first exercise here is of a mere technical art. We want you to have - +

    The first exercise here is of a mere technical art. We want you to have

    • 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.
    • Install various Python packages
    - -We will make extensive use of Python as programming language and its +

    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. +

    -

    -If you have Python installed (we recommend Python3) and you feel +

    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 +

    1. pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
    - -For Tensorflow, we recommend following the instructions in the text of +

    For Tensorflow, we recommend following the instructions in the text of Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly +

    -

    -We will come back to tensorflow later. +

    We will come back to tensorflow later.

    -

    -For Python3, replace pip with pip3. +

    For Python3, replace pip with pip3.

    -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for Python2.7)
    - -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    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 if you are not too familiar with setting paths in a terminal environment. +

    We recommend using Anaconda if you are not too familiar with setting paths in a terminal environment.

    -

    -

    -

    Exercise 2: making your own data and exploring scikit-learn

    -

    -We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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) \). +

    We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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). -

    +

    -
    x = np.random.rand(100,1)
    +
    +
    +
    +
    +
    +
    x = np.random.rand(100,1)
     y = 2.0+5*x*x+0.1*np.random.randn(100,1)
    -
    +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +
    1. Write your own code (following the examples under the regression notes) for computing the parametrization of the data set fitting a second-order polynomial.
    2. Use thereafter scikit-learn (see again the examples in the regression slides) and compare with your own code.
    3. Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as
    - $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -and the \( R^2 \) score function. +

    and the \( R^2 \) score function. If \( \tilde{\boldsymbol{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 +

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. +

    You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. 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. +

    -

    +

    Solution. The code here is an example of where we define our own design matrix and fit parameters \( \beta \). -

    +

    -
    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -3462,26 +4089,36 @@ ypredict = X_test @ beta
     print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + + -

    -

    -

    Exercise 3: Normalizing our data

    -

    -A much used approach before starting to train the data is to preprocess our +

    A much used approach before starting to train the data is to preprocess our data. Normally the data may need a rescaling and/or may be sensitive to extreme values. Scaling the data renders our inputs much more suitable for the algorithms we want to employ. +

    -

    -Scikit-Learn has several functions which allow us to rescale the +

    Scikit-Learn has several functions which allow us to rescale the data, normally resulting in much better results in terms of various accuracy scores. The StandardScaler function in Scikit-Learn ensures that for each feature/predictor we study the mean value is @@ -3490,18 +4127,18 @@ matrix). This scaling has the drawback that it does not ensure that we have a particular maximum or minimum in our data set. Another function included in Scikit-Learn is the MinMaxScaler which ensures that all features are exactly between \( 0 \) and \( 1 \). The +

    -

    -The Normalizer scales each data +

    The Normalizer scales each data point such that the feature vector has a euclidean length of one. In other words, it projects a data point on the circle (or sphere in the case of higher dimensions) with a radius of 1. This means every data point is scaled by a different number (by the inverse of it’s length). This normalization is often used when only the direction (or angle) of the data matters, not the length of the feature vector. +

    -

    -The RobustScaler works similarly to the StandardScaler in that it +

    The RobustScaler works similarly to the StandardScaler in that it ensures statistical properties for each feature that guarantee that they are on the same scale. However, the RobustScaler uses the median and quartiles, instead of mean and variance. This makes the @@ -3509,74 +4146,131 @@ RobustScaler ignore data points that are very different from the rest (like measurement errors). These odd data points are also called outliers, and might often lead to trouble for other scaling techniques. +

    -

    -It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest +

    It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest for testing. This can be done as follows with our design matrix \( \boldsymbol{X} \) and data \( \boldsymbol{y} \) (remember to import scikit-learn) -

    +

    -
    # split in training and test data
    +
    +
    +
    +
    +
    +
    # split in training and test data
     X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
    -
    -

    -Then we can use the standard scaler to scale our data as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Then we can use the standard scaler to scale our data as

    -
    scaler = StandardScaler()
    +
    +
    +
    +
    +
    +
    scaler = StandardScaler()
     scaler.fit(X_train)
     X_train_scaled = scaler.transform(X_train)
     X_test_scaled = scaler.transform(X_test)
    -
    -

    -In this exercise we want you to to compute the MSE for the training +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In this exercise we want you to to compute the MSE for the training data and the test data as function of the complexity of a polynomial, -that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +

    -

    -One of +

    One of the aims is to reproduce Figure 2.11 of Hastie et al. +

    -

    -Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points. -

    +

    Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points.

    -
    np.random.seed()
    +
    +
    +
    +
    +
    +
    np.random.seed()
     n = 100
     maxdegree = 14
     # Make data set.
     x = np.linspace(-3, 3, n).reshape(-1, 1)
     y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    -
    -

    -where \( y \) is the function we want to fit with a given polynomial. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + +

    where \( y \) is the function we want to fit with a given polynomial.

    + +

    a) Write a first code which sets up a design matrix \( X \) defined by a fifth-order polynomial. Scale your data and split it in training and test data. +

    + + +

    b) Perform an ordinary least squares and compute the means squared error and the \( R2 \) factor for the training data and the test data, with and without scaling. +

    + + +

    c) Add now a model which allows you to make polynomials up to degree \( 15 \). Perform a standard OLS fitting of the training data and compute the MSE and \( R2 \) for the training and test data and plot both test and training data MSE and \( R2 \) as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)? +

    + + -

    - - -

    © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week34/html/week34.html b/doc/pub/week34/html/week34.html index 56bc5348d..ba58ee8f7 100644 --- a/doc/pub/week34/html/week34.html +++ b/doc/pub/week34/html/week34.html @@ -1,6 +1,7 @@ @@ -8,29 +9,97 @@ Automatically generated HTML file from DocOnce source - Week 34: Introduction to the course, Logistics and Practicalities - - - - +
    +

    Week 34: Introduction to the course, Logistics and Practicalities

    +
    - - -

    Week 34: Introduction to the course, Logistics and Practicalities

    - -

    -

    Morten Hjorth-Jensen [1, 2]
    - -

    +

    +[1] Department of Physics, University of Oslo +
    +
    +[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +
    +
    +
    +

    Nov 13, 2021

    +
    +
    -
    [1] Department of Physics, University of Oslo
    -
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
    -
    -

    -

    Oct 12, 2021

    -
    -











    -

    Overview of first week

    -

    -

    • Wednesday August 25: Introduction to software and repetition of Python Programming
    • Thursday August 26: First lecture: Presentation of the course, aims and content
    • @@ -327,59 +395,44 @@ MathJax.Hub.Config({
    -











    -

    Reading Recommendations

    -

    -For the reading assignments we use the following abbreviations: - +

    For the reading assignments we use the following abbreviations:

    • GBC: Goodfellow, Bengio, and Courville, Deep Learning
    • CMB: Christopher M. Bishop, Pattern Recognition and Machine Learning
    • HTF: Hastie, Tibshirani, and Friedman, The Elements of Statistical Learning
    • AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow
    - -Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html +

    Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html

    -











    -

    Thursday August 26

    -

    -The lectures will be recorded and updated videos will be posted after the lectures. +

    The lectures will be recorded and updated videos will be posted after the lectures.

    -

    -"Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage

    -

    -Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09 +

    Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09

    • Meeting ID: 933 1152 9525
    • Passcode: 646102
    +

    Video of Lecture from Fall Semester 2020.

    -Video of Lecture from Fall Semester 2020. - -











    -

    Lectures and ComputerLab

    -

    -

    • Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).
    • Weekly reading assignments and videos needed to solve projects and exercises.
    • @@ -391,17 +444,12 @@ The lectures will be recorded and updated videos will be posted after the lectur
    -











    -

    Announcement

    -

    -NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html +

    NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html

    -











    -

    Communication channels

    -









    -

    Course Format

    -

    -

    • Three compulsory projects. Electronic reports only using Canvas to hand in projects and git as version control software and GitHub for repository (or GitLab) of all your material.
    • Evaluation and grading: The three projects are graded and each counts 1/3 of the final mark. No final written or oral exam. -
      1. For the last project each group/participant submits a proposal or works with suggested (by us) proposals for the project.
      2. If possible, we would like to organize the last project as a workshop where each group makes a poster and presents this to all other participants of the course
      3. Poster session where all participants can study and discuss the other proposals.
      4. Based on feedback etc, each group finalizes the report and submits for grading.
      -
    • Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and github address of the course.
    -











    -

    Teachers

    -

    -

    Teachers : -

    • Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no
    • -
      • Phone: +47-48257387
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ470
      • Office hours: Anytime! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning.
      -
    • Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ452
      -
    • Stian Dysthe Bilek stian.bilek@fys.uio.no
    • -
      • Office: Department of Physics, University of Oslo, Eastern wing, room FØ450
      -
    • Linus Ekstrøm, linueks@gmail.com, linus.ekstrom@fys.uio.no
    • Nicholas Karlsen, nicholaskarlsen1102@gmail.com, nicholas.karlsen@fys.uio.no
    • Bendik Steinsvåg Dalen, b.s.dalen@fys.uio.no
    • @@ -477,57 +508,44 @@ The lectures will be recorded and updated videos will be posted after the lectur
    -











    -

    Deadlines for projects (tentative)

    -

    1. Project 1: October 11 (available September 10) graded with feedback)
    2. -
    3. Project 2: November 15 (available October 12, graded with feedback)
    4. -
    5. Project 3: December 13 (available November 8, graded with feedback)
    6. +
    7. Project 2: November 20 (available October 12, graded with feedback)
    8. +
    9. Project 3: December 17 (available November 13, graded with feedback)
    - -Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas. - - +

    Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas.

    -











    -

    1. The lecture notes are collected as a jupyter-book at https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html.
    - -In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below. +

    In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below.

    1. Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, https://www.springer.com/gp/book/9780387310732.
    2. Ian Goodfellow, Yoshua Bengio, and Aaron Courville. The different chapters are available for free at https://www.deeplearningbook.org/. Chapters 2-14 are highly recommended. The lectures follow to a larg extent this text. The weekly plans will include reading suggestions from these two textbooks.
    - -Additional textbooks: +

    Additional textbooks:

    1. Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, https://www.springer.com/gp/book/9780387848570. This is a well-known text and serves as additional literature.
    2. Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/. This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course.
    -









    -

    Prerequisites

    -

    -Basic knowledge in programming and mathematics, with an emphasis on +

    Basic knowledge in programming and mathematics, with an emphasis on linear algebra. Knowledge of Python or/and C++ as programming languages is strongly recommended and experience with Jupiter notebook is recommended. Required courses are the equivalents to the University @@ -536,19 +554,16 @@ of the corresponding computing and programming courses INF1000/INF1110 or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1100. Most universities offer nowadays a basic programming course (often compulsory) where Python is the recurring programming language. +

    -











    -

    Learning outcomes

    -

    -

    -This course aims at giving you insights and knowledge about many of +

    This course aims at giving you insights and knowledge about many of the central algorithms used in Data Analysis and Machine Learning. The course is project based and through various numerical projects, normally three, you will be exposed to fundamental research problems @@ -561,6 +576,7 @@ Learning is applied to, get acquainted with computing facilities and learn to handle large scientific projects. A good scientific and ethical conduct is emphasized throughout the course. More specifically, after this course you will +

    • Learn about basic data analysis, statistical analysis, Bayesian statistics, Monte Carlo sampling, data optimization and machine learning;
    • @@ -577,29 +593,22 @@ specifically, after this course you will
    -











    -

    Topics covered in this course: Statistical analysis and optimization of data

    -

    -The course has two central parts +

    The course has two central parts

    1. Statistical analysis and optimization of data
    2. Machine learning
    +

    These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms

    -These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms - -

    Statistical analysis and optimization of data

    -

    -We plan to cover the following topics: - +

    We plan to cover the following topics:

    • Basic concepts, expectation values, variance, covariance, correlation functions and errors;
    • Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions;
    • @@ -612,17 +621,13 @@ We plan to cover the following topics:
    -











    -

    Topics covered in this course: Machine Learning

    -

    -The following topics will be covered - +

    The following topics will be covered

    • Linear Regression and Logistic Regression;
    • Neural networks and deep learning, including convolutional and recurrent neural networks
    • @@ -632,23 +637,16 @@ The following topics will be covered
    • Boltzmann Machines
    • Unsupervised learning Dimensionality reduction, from PCA to clustering
    - -Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics. - - +

    Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics.

    -











    -

    -

    and discussed at the lab sessions

    -

    • GIT for version control, and GitHub or GitLab as repositories, highly recommended. This will be discussed during the first exercise session
    • Anaconda and other Python environments, see intro slides and links to programming resources at https://computationalscienceuio.github.io/RefreshProgrammingSkills/intro.html
    • @@ -656,13 +654,10 @@ Hands-on demonstrations, exercises and projects aim at deepening your understand
    -











    -

    Other courses on Data science and Machine Learning at UiO

    -

    -The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO. +

    The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO.

    1. STK2100 Machine learning and statistical methods for prediction and classification.
    2. @@ -677,18 +672,15 @@ The link here STK4051 Computational Statistics
    3. STK4021 Applied Bayesian Analysis and Numerical Methods
    -









    -

    Introduction

    -

    -Our emphasis throughout this series of lectures +

    Our emphasis throughout this series of lectures is on understanding the mathematical aspects of -different algorithms used in the fields of data analysis and machine learning. +different algorithms used in the fields of data analysis and machine learning. +

    -

    -However, where possible we will emphasize the +

    However, where possible we will emphasize the importance of using available software. We start thus with a hands-on and top-down approach to machine learning. The aim is thus to start with relevant data or data we have produced @@ -702,40 +694,38 @@ the data and predictions. We move thereafter to more interesting cases such as data from say experiments (below we will look at experimental nuclear binding energies as an example). These are examples where we can easily set up the data and then use machine learning algorithms included in for example -Scikit-Learn. +Scikit-Learn. +

    -

    -These examples will serve us the purpose of getting +

    These examples will serve us the purpose of getting started. Furthermore, they allow us to catch more than two birds with a stone. They will allow us to bring in some programming specific topics and tools as well as showing the power of various Python -libraries for machine learning and statistical data analysis. +libraries for machine learning and statistical data analysis. +

    -

    -Here, we will mainly focus on two +

    Here, we will mainly focus on two specific Python packages for Machine Learning, Scikit-Learn and Tensorflow (see below for links etc). Moreover, the examples we introduce will serve as inputs to many of our discussions later, as well as allowing you to set up models and produce your own data and get started with programming. +

    -











    -

    What is Machine Learning?

    -

    -Statistics, data science and machine learning form important fields of +

    Statistics, data science and machine learning form important fields of research in modern science. They describe how to learn and make predictions from data, as well as allowing us to extract important correlations about physical process and the underlying laws of motion in large data sets. The latter, big data sets, appear frequently in essentially all disciplines, from the traditional Science, Technology, Mathematics and Engineering fields to Life Science, Law, education -research, the Humanities and the Social Sciences. +research, the Humanities and the Social Sciences. +

    -

    -It has become more +

    It has become more and more common to see research projects on big data in for example the Social Sciences where extracting patterns from complicated survey data is one of many research directions. Having a solid grasp of data @@ -750,17 +740,17 @@ in the private or the public sector. This author has had several students or met students who have been hired recently based on their skills and competences in scientific computing and data science, often with marginal knowledge of machine learning. +

    -

    -Machine learning is a subfield of computer science, and is closely +

    Machine learning is a subfield of computer science, and is closely related to computational statistics. It evolved from the study of pattern recognition in artificial intelligence (AI) research, and has made contributions to AI tasks like computer vision, natural language processing and speech recognition. Many of the methods we will study are also -strongly rooted in basic mathematics and physics research. +strongly rooted in basic mathematics and physics research. +

    -

    -Ideally, machine learning represents the science of giving computers +

    Ideally, machine learning represents the science of giving computers the ability to learn without being explicitly programmed. The idea is that there exist generic algorithms which can be used to find patterns in a broad class of data sets without having to write code @@ -768,10 +758,10 @@ specifically for each problem. The algorithm will build its own logic based on the data. You should however always keep in mind that machines and algorithms are to a large extent developed by humans. The insights and knowledge we have about a specific system, play a central -role when we develop a specific machine learning algorithm. +role when we develop a specific machine learning algorithm. +

    -

    -Machine learning is an extremely rich field, in spite of its young +

    Machine learning is an extremely rich field, in spite of its young age. The increases we have seen during the last three decades in computational capabilities have been followed by developments of methods and techniques for analyzing and handling large date sets, @@ -791,14 +781,12 @@ solid command of linear algebra, multivariate theory, probability theory, statistical data analysis, understanding errors and Monte Carlo methods are central elements in a proper understanding of many of algorithms and methods we will discuss. +

    -











    -

    Types of Machine Learning

    -

    -The approaches to machine learning are many, but are often split into +

    The approaches to machine learning are many, but are often split into two main categories. In supervised learning we know the answer to a problem, and let the computer deduce the logic behind it. On the other hand, unsupervised learning is a method for finding patterns and @@ -807,49 +795,40 @@ Some authours also operate with a third category, namely reinforcement learning. This is a paradigm of learning inspired by behavioral psychology, where learning is achieved by trial-and-error, solely from rewards and punishment. +

    -

    -Another way to categorize machine learning tasks is to consider the +

    Another way to categorize machine learning tasks is to consider the desired output of a system. Some of the most common tasks are: +

    • Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.
    • Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.
    • Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.
    -









    -

    Essential elements of ML

    -

    -The methods we cover have three main topics in common, irrespective of +

    The methods we cover have three main topics in common, irrespective of whether we deal with supervised or unsupervised learning. +

    -
    • The first ingredient is normally our data set (which can be subdivided into training, validation and test data). Many find the most difficult part of using Machine Learning to be the set up of your data in a meaningful way.
    • The second item is a model which is normally a function of some parameters. The model reflects our knowledge of the system (or lack thereof). As an example, if we know that our data show a behavior similar to what would be predicted by a polynomial, fitting our data to a polynomial of some degree would then determin our model.
    • The last ingredient is a so-called cost/loss function (or error or risk function) which allows us to present an estimate on how good our model is in reproducing the data it is supposed to train.
    - -











    -

    An optimization/minimization problem

    -

    -At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods. +

    At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods.

    -











    -

    A Frequentist approach to data analysis

    -

    -When you hear phrases like predictions and estimations and +

    When you hear phrases like predictions and estimations and correlations and causations, what do you think of? May be you think of the difference between classifying new data points and generating new data points. @@ -857,9 +836,9 @@ Or perhaps you consider that correlations represent some kind of symmetric state if \( A \) is correlated with \( B \), then \( B \) is correlated with \( A \). Causation on the other hand is directional, that is if \( A \) causes \( B \), \( B \) does not necessarily cause \( A \). +

    -

    -These concepts are in some sense the difference between machine +

    These concepts are in some sense the difference between machine learning and statistics. In machine learning and prediction based tasks, we are often interested in developing algorithms that are capable of learning patterns from given data in an automated fashion, @@ -868,51 +847,47 @@ assessments of newly given data. In many cases, our primary concern is the quality of the predictions or assessments, and we are less concerned about the underlying patterns that were learned in order to make these predictions. +

    -

    -In machine learning we normally use a so-called frequentist approach, +

    In machine learning we normally use a so-called frequentist approach, where the aim is to make predictions and find correlations. We focus less on for example extracting a probability distribution function (PDF). The PDF can be used in turn to make estimations and find causations such as given \( A \) what is the likelihood of finding \( B \). +

    -











    -

    What is a good model?

    -

    -In science and engineering we often end up in situations where we want to infer (or learn) a +

    In science and engineering we often end up in situations where we want to infer (or learn) a quantitative model \( M \) for a given set of sample points \( \boldsymbol{X} \in [x_1, x_2,\dots x_N] \). +

    -

    -As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a +

    As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a straight line, or if we wish to be more sophisticated to a more complex function. +

    -

    -The reason for inferring such a model is that it +

    The reason for inferring such a model is that it serves many useful purposes. On the one hand, the model can reveal information encoded in the data or underlying mechanisms from which the data were generated. For instance, we could discover important corelations that relate interesting physics interpretations. +

    -

    -In addition, it can simplify the representation of the given data set and help +

    In addition, it can simplify the representation of the given data set and help us in making predictions about future data samples. +

    -

    -A first important consideration to keep in mind is that inferring the correct model +

    A first important consideration to keep in mind is that inferring the correct model for a given data set is an elusive, if not impossible, task. The fundamental difficulty is that if we are not specific about what we mean by a correct model, there could easily be many different models that fit the given data set equally well. +

    -











    -

    What is a good model? Can we define it?

    -

    -The central question is this: what leads us to say that a model is correct or +

    The central question is this: what leads us to say that a model is correct or optimal for a given data set? To make the model inference problem well posed, i.e., to guarantee that there is a unique optimal model for the given data, we need to impose additional assumptions or restrictions on the class of models considered. To @@ -925,98 +900,90 @@ with the simplest possible class of models that is just necessary to describe th or solve the problem at hand. More precisely, the model class should be rich enough to contain at least one model that can fit the data to a desired accuracy and yet be restricted enough that it is relatively simple to find the best model for the given data. +

    -

    -Thus, the most popular strategy is to start from the +

    Thus, the most popular strategy is to start from the simplest class of models and increase the complexity of the models only when the simpler models become inadequate. For instance, if we work with a regression problem to fit a set of sample points, one may first try the simplest class of models, namely linear models, followed obviously by more complex models. +

    -

    -How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures. +

    How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures.

    -











    -

    Software and needed installations

    -

    -We will make extensive use of Python as programming language and its +

    We will make extensive use of Python as programming language and its myriad of available libraries. You will find 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, Julia, Fortran etc if you prefer. The focus in these lectures will be on Python. +

    -

    -If you have Python installed (we strongly recommend Python3) and you feel +

    If you have Python installed (we strongly recommend Python3) and you feel pretty familiar with installing different packages, we recommend that you install the following Python packages via pip as +

    1. pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow
    +

    For Python3, replace pip with pip3.

    -For Python3, replace pip with pip3. - -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for pyhton2.7)
    +

    etc etc.

    -etc etc. - -











    -

    Python installers

    -

    -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license. +

    -

    -Furthermore, Google's Colab is a free Jupyter notebook environment that requires +

    Furthermore, Google's Colab is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. Try it out! +

    -











    -

    Useful Python libraries

    -Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there) +

    Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)

    • NumPy is a highly popular library for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays
    • @@ -1031,13 +998,10 @@ Here we list several useful Python libraries we strongly recommend (if you use a
    • Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano
    • And many more such as pytorch, Theano etc
    -









    -

    Installing R, C++, cython or Julia

    -

    -You will also find it convenient to utilize R. We will mainly +

    You will also find it convenient to utilize R. We will mainly use Python during our lectures and in various projects and exercises. Those of you already familiar with R should feel free to continue using R, keeping @@ -1047,25 +1011,23 @@ notebook allows you to run R codes interactively in your browser. The software library R is really tailored for statistical data analysis and allows for an easy usage of the tools and algorithms we will discuss in these lectures. +

    -

    -To install R with Jupyter notebook +

    To install R with Jupyter notebook follow the link here +

    -











    -

    Installing R, C++, cython, Numba etc

    -

    -For the C++ aficionados, Jupyter/IPython notebook allows you also to +

    For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for either Python or C++ (or Fortran or other compiled languages) as programming languages. +

    -

    -To add more entropy, cython can also be used when running your +

    To add more entropy, cython can also be used when running your notebooks. It means that Python with the jupyter notebook setup allows you to integrate widely popular softwares and tools for scientific computing. Similarly, the @@ -1074,43 +1036,56 @@ capabilities with minimal rewrites of your codes. With its versatility, including symbolic operations, Python offers a unique computational environment. Your jupyter notebook can easily be converted into a nicely rendered PDF file or a Latex file for -further processing. For example, convert to latex as +further processing. For example, convert to latex as +

    -

    - -

    pycod jupyter nbconvert filename.ipynb --to latex 
    -
    -

    -And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. + +

    +
    +
    +
    +
    +
    pycod jupyter nbconvert filename.ipynb --to latex 
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    -Finally, if you wish to use the light mark-up language +

    And to add more versatility, the Python package SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python.

    + +

    Finally, if you wish to use the light mark-up language doconce you can convert a standard ascii text file into various HTML formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using doconce. +

    -











    -

    Numpy examples and Important Matrix and vector handling packages

    -

    -There are several central software libraries for linear algebra and eigenvalue problems. Several of the more +

    There are several central software libraries for linear algebra and eigenvalue problems. Several of the more popular ones have been wrapped into ofter software packages like those from the widely used text Numerical Recipes. The original source codes in many of the available packages are often taken from the widely used software package LAPACK, which follows two other popular packages developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly here. +

    • LINPACK: package for linear equations and least square problems.
    • LAPACK:package for solving symmetric, unsymmetric and generalized eigenvalue problems. From LAPACK's website http://www.netlib.org it is possible to download for free all source codes from this library. Both C/C++ and Fortran versions are available.
    • BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from http://www.netlib.org.
    -









    -

    Basic Matrix Features

    -

    Matrix properties reminder

    @@ -1129,15 +1104,14 @@ $$ \end{bmatrix} $$ -

    -The inverse of a matrix is defined by +

    The inverse of a matrix is defined by

    $$ \mathbf{A}^{-1} \cdot \mathbf{A} = I $$ -

    - + +
    @@ -1149,13 +1123,10 @@ $$
    Relations Name matrix elements
    \( A=\left(A^{\dagger}\right )^{-1} \) unitary \( \sum_k a_{ik}a_{jk}^{ < em>}=\sum_k a_{ki}^{ < /em> } a_{kj}=\delta_{ij} \)
    -

    -











    -

    Some famous Matrices

      @@ -1169,16 +1140,13 @@ $$
    • Upper banded with bandwidth \( p \): \( a_{ij}=0 \) for \( i < j+p \)
    • Banded, block upper triangular, block lower triangular....
    -









    -

    More Basic Matrix Features

    -

    Some Equivalent Statements

    -For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent +

    For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent

    • If the inverse of \( \mathbf{A} \) exists, \( \mathbf{A} \) is nonsingular.
    • @@ -1191,167 +1159,408 @@ For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all
    -











    -

    Numpy and arrays

    -Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as +

    Numpy provides an easy way to handle arrays in Python. The standard way to import this library is as

    -

    -

    import numpy as np
    -
    -

    -Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution, -

    +

    +
    +
    +
    +
    +
    import numpy as np
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution,

    -
    n = 10
    +
    +
    +
    +
    +
    +
    n = 10
     x = np.random.normal(size=n)
     print(x)
    -
    -

    -We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \). Another alternative is to declare a vector as follows -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.array([1, 2, 3])
     print(x)
    -
    -

    -Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++ start numbering array elements from \( 0 \) and on. This means that a vector with \( n \) elements has a sequence of entities \( x_0, x_1, x_2, \dots, x_{n-1} \). We could also let (recommended) Numpy to compute the logarithms of a specific array as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8]))
     print(x)
    -
    -

    -In the last example we used Numpy's unary function \( np.log \). This function is +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In the last example we used Numpy's unary function \( np.log \). This function is highly tuned to compute array elements since the code is vectorized and does not require looping. We normaly recommend that you use the Numpy intrinsic functions instead of the corresponding log function from Python's math module. The looping is done explicitely by the np.log function. The alternative, and slower way to compute the logarithms of a vector would be to write +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     from math import log
     x = np.array([4, 7, 8])
     for i in range(0, len(x)):
         x[i] = log(x[i])
     print(x)
    -
    -

    -We note that our code is much longer already and we need to import the log function from the math module. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We note that our code is much longer already and we need to import the log function from the math module. The attentive reader will also notice that the output is \( [1, 1, 2] \). Python interprets automagically our numbers as integers (like the automatic keyword in C++). To change this we could define our array elements to be double precision numbers as -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4, 7, 8], dtype = np.float64))
     print(x)
    -
    -

    -or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x)
    -
    -

    -To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the itemsize functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     x = np.log(np.array([4.0, 7.0, 8.0]))
     print(x.itemsize)
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Matrices in Python

    -

    -Having defined vectors, we are now ready to try out matrices. We can +

    Having defined vectors, we are now ready to try out matrices. We can define a \( 3 \times 3 \) real matrix \( \boldsymbol{A} \) as (recall that we user lowercase letters for vectors and uppercase letters for matrices) +

    -

    -

    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     print(A)
    -
    -

    -If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    If we use the shape function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[:,0]) 
    -
    -

    -We can continue this was by printing out other columns or rows. The example here prints out the second column -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can continue this was by printing out other columns or rows. The example here prints out the second column

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
     # print the first column, row-major order and elements start with 0
     print(A[1,:]) 
    -
    -

    -Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the Numpy website for more details. Useful functions when defining a matrix are the np.zeros function which declares a matrix of a given dimension and sets all elements to zero

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to zero
     A = np.zeros( (n, n) )
     print(A) 
    -
    -

    -or initializing all elements to -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or initializing all elements to

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to one
     A = np.ones( (n, n) )
     print(A) 
    -
    -

    -or as unitarily distributed random numbers (see the material on random number generators in the statistics part) -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    or as unitarily distributed random numbers (see the material on random number generators in the statistics part)

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     n = 10
     # define a matrix of dimension 10 x 10 and set all elements to random numbers with x \in [0, 1]
     A = np.random.rand(n, n)
     print(A) 
    -
    -

    -As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    As we will see throughout these lectures, there are several extremely useful functionalities in Numpy. As an example, consider the discussion of the covariance matrix. Suppose we have defined three vectors \( \boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z} \) with \( n \) elements each. The covariance matrix is defined as +

    $$ \boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ @@ -1359,13 +1568,14 @@ $$ \end{bmatrix}, $$ -where for example +

    where for example

    $$ \sigma_{xy} =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}). $$ -The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. +

    The Numpy function np.cov calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values. The following simple function uses the np.vstack function which takes each vector of dimension \( 1\times n \) and produces a \( 3\times n \) matrix \( \boldsymbol{W} \) +

    $$ \boldsymbol{W} = \begin{bmatrix} x_0 & x_1 & x_2 & \dots & x_{n-2} & x_{n-1} \\ y_0 & y_1 & y_2 & \dots & y_{n-2} & y_{n-1} \\ @@ -1373,17 +1583,21 @@ $$ \end{bmatrix}, $$ -

    -which in turn is converted into into the \( 3\times 3 \) covariance matrix +

    which in turn is converted into into the \( 3\times 3 \) covariance matrix \( \boldsymbol{\Sigma} \) via the Numpy function np.cov(). We note that we can also calculate the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy function np.mean(x). We can also extract the eigenvalues of the covariance matrix through the np.linalg.eig() function. +

    -

    -

    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     
     n = 100
    @@ -1398,11 +1612,26 @@ Sigma = np.print(Sigma)
     Eigvals, Eigvecs = np.linalg.eig(Sigma)
     print(Eigvals)
    -
    -

    - +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from scipy import sparse
     eye = np.eye(4)
    @@ -1413,30 +1642,49 @@ x = np.l
     y = np.sin(x)
     plt.plot(x,y,marker='x')
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Meet the Pandas

    -

    -



    +

    +
    +

    +
    +

    -

    -Another useful Python package is +

    Another useful Python package is pandas, which is an open source library providing high-performance, easy-to-use data structures and data analysis tools for Python. pandas stands for panel data, a term borrowed from econometrics and is an efficient library for data analysis with an emphasis on tabular data. pandas has two major classes, the DataFrame class with two-dimensional data objects and tabular data organized in columns and the class Series with a focus on one-dimensional data objects. Both classes allow you to index data easily as we will see in the examples below. -pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +pandas allows you also to perform mathematical operations on the data, spanning from simple reshapings of vectors and matrices to statistical operations. +

    -

    -The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data. +

    The following simple example shows how we can, in an easy way make tables of our data. Here we define a data set which includes names, place of birth and date of birth, and displays the data in an easy to read way. We will see repeated use of pandas, in particular in connection with classification of data.

    -

    -

    import pandas as pd
    +
    +
    +
    +
    +
    +
    import pandas as pd
     from IPython.display import display
     data = {'First Name': ["Frodo", "Bilbo", "Aragorn II", "Samwise"],
             'Last Name': ["Baggins", "Baggins","Elessar","Gamgee"],
    @@ -1445,45 +1693,115 @@ data = {'Fi
             }
     data_pandas = pd.DataFrame(data)
     display(data_pandas)
    -
    -

    -In the above we have imported pandas with the shorthand pd, the latter has become the standard way we import pandas. We make then a list of various variables +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In the above we have imported pandas with the shorthand pd, the latter has become the standard way we import pandas. We make then a list of various variables and reorganize the aboves lists into a DataFrame and then print out a neat table with specific column labels as Name, place of birth and date of birth. Displaying these results, we see that the indices are given by the default numbers from zero to three. pandas is extremely flexible and we can easily change the above indices by defining a new type of indexing as -

    +

    -
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
    +
    +
    +
    +
    +
    +
    data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
     display(data_pandas)
    -
    -

    -Thereafter we display the content of the row which begins with the index Aragorn -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Thereafter we display the content of the row which begins with the index Aragorn

    -
    display(data_pandas.loc['Aragorn'])
    -
    -

    -We can easily append data to this, for example -

    +

    +
    +
    +
    +
    +
    display(data_pandas.loc['Aragorn'])
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily append data to this, for example

    -
    new_hobbit = {'First Name': ["Peregrin"],
    +
    +
    +
    +
    +
    +
    new_hobbit = {'First Name': ["Peregrin"],
                   'Last Name': ["Took"],
                   'Place of birth': ["Shire"],
                   'Date of Birth T.A.': [2990]
                   }
     data_pandas=data_pandas.append(pd.DataFrame(new_hobbit, index=['Pippin']))
     display(data_pandas)
    -
    -

    -Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Here are other examples where we use the DataFrame functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix of dimensionality \( 10\times 5 \) and compute the mean value and standard deviation of each column. Similarly, we can perform mathematial operations like squaring the matrix elements and many other operations. -

    +

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import pandas as pd
     from IPython.display import display
     np.random.seed(100)
    @@ -1496,13 +1814,30 @@ display(df)
     print(df.mean())
     print(df.std())
     display(df**2)
    -
    -

    -Thereafter we can select specific columns only and plot final results -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Thereafter we can select specific columns only and plot final results

    -
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
    +
    +
    +
    +
    +
    +
    df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
     df.index = np.arange(10)
     
     display(df)
    @@ -1520,49 +1855,71 @@ plt.show()
     
     df.plot.bar(figsize=(10,6), rot=15)
     plt.show()
    -
    -

    -We can produce a \( 4\times 4 \) matrix -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We can produce a \( 4\times 4 \) matrix

    -
    b = np.arange(16).reshape((4,4))
    +
    +
    +
    +
    +
    +
    b = np.arange(16).reshape((4,4))
     print(b)
     df1 = pd.DataFrame(b)
     print(df1)
    -
    -

    -and many other operations. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -The Series class is another important class included in +

    and many other operations.

    + +

    The Series class is another important class included in pandas. You can view it as a specialization of DataFrame but where we have just a single column of data. It shares many of the same features as _DataFrame. As with DataFrame, most operations are vectorized, achieving thereby a high performance when dealing with computations of arrays, in particular labeled arrays. As we will see below it leads also to a very concice code close to the mathematical operations we may be interested in. -For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +For multidimensional arrays, we recommend strongly xarray. xarray has much of the same flexibility as pandas, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both pandas and xarray. +

    -











    -

    Friday August 27

    -

    -"Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage +

    "Video of Lecture August 27, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage

    -

    -Video of Lecture from fall 2020 and Handwritten notes +

    Video of Lecture from fall 2020 and Handwritten notes

    -











    +

    Simple linear regression model using scikit-learn

    -

    Simple linear regression model using scikit-learn

    +

    We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us.

    -

    -We start with perhaps our simplest possible example, using Scikit-Learn to perform linear regression analysis on a data set produced by us. - -

    -What follows is a simple Python code where we have defined a function +

    What follows is a simple Python code where we have defined a function \( y \) in terms of the variable \( x \). Both are defined as vectors with \( 100 \) entries. The numbers in the vector \( \boldsymbol{x} \) are given by random numbers generated with a uniform distribution with entries @@ -1570,9 +1927,9 @@ by random numbers generated with a uniform distribution with entries later). These values are then used to define a function \( y(x) \) (tabulated again as a vector) with a linear dependence on \( x \) plus a random noise added via the normal distribution. +

    -

    -The Numpy functions are imported used the import numpy as np +

    The Numpy functions are imported used the import numpy as np statement and the random number generator for the uniform distribution is called using the function np.random.rand(), where we specificy that we want \( 100 \) random variables. Using Numpy we define @@ -1581,13 +1938,13 @@ our case. With the Numpy function randn() we can compute random numbers with the normal distribution (mean value \( \mu \) equal to zero and variance \( \sigma^2 \) set to one) and produce the values of \( y \) assuming a linear dependence as function of \( x \) +

    $$ y = 2x+N(0,1), $$ -

    -where \( N(0,1) \) represents random numbers generated by the normal +

    where \( N(0,1) \) represents random numbers generated by the normal distribution. From Scikit-Learn we import then the LinearRegression functionality and make a prediction \( \tilde{y} = \alpha + \beta x \) using the function fit(x,y). We call the set of @@ -1595,22 +1952,26 @@ data \( (\boldsymbol{x},\boldsymbol{y}) \) for our training data. The Python pac scikit-learn has also a functionality which extracts the above fitting parameters \( \alpha \) and \( \beta \) (see below). Later we will distinguish between training data and test data. +

    -

    -For plotting we use the Python package +

    For plotting we use the Python package matplotlib which produces publication quality figures. Feel free to explore the extensive gallery of examples. In this example we plot our original values of \( x \) and \( y \) as well as the prediction ypredict (\( \tilde{y} \)), which attempts at fitting our data with a straight line. +

    -

    -The Python code follows here. -

    +

    The Python code follows here.

    -
    # Importing various packages
    +
    +
    +
    +
    +
    +
    # Importing various packages
     import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
    @@ -1629,9 +1990,22 @@ plt.xlabel(r
     plt.ylabel(r'$y$')
     plt.title(r'Simple Linear Regression')
     plt.show()
    -
    -

    -This example serves several aims. It allows us to demonstrate several +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    This example serves several aims. It allows us to demonstrate several aspects of data analysis and later machine learning algorithms. The immediate visualization shows that our linear fit is not impressive. It goes through the data points, but there are many @@ -1639,38 +2013,38 @@ outliers which are not reproduced by our linear regression. We could now play around with this small program and change for example the factor in front of \( x \) and the normal distribution. Try to change the function \( y \) to +

    $$ y = 10x+0.01 \times N(0,1), $$ -

    -where \( x \) is defined as before. Does the fit look better? Indeed, by +

    where \( x \) is defined as before. Does the fit look better? Indeed, by reducing the role of the noise given by the normal distribution we see immediately that our linear prediction seemingly reproduces better the training set. However, this testing 'by the eye' is obviouly not satisfactory in the long run. Here we have only defined the training data and our model, and have not discussed a more rigorous approach to the cost function. +

    -

    -We need more rigorous criteria in defining whether we have succeeded or +

    We need more rigorous criteria in defining whether we have succeeded or not in modeling our training data. You will be surprised to see that many scientists seldomly venture beyond this 'by the eye' approach. A standard approach for the cost function is the so-called \( \chi^2 \) function (a variant of the mean-squared error (MSE)) +

    $$ \chi^2 = \frac{1}{n} \sum_{i=0}^{n-1}\frac{(y_i-\tilde{y}_i)^2}{\sigma_i^2}, $$ -

    -where \( \sigma_i^2 \) is the variance (to be defined later) of the entry +

    where \( \sigma_i^2 \) is the variance (to be defined later) of the entry \( y_i \). We may not know the explicit value of \( \sigma_i^2 \), it serves however the aim of scaling the equations and make the cost function -dimensionless. +dimensionless. +

    -

    -Minimizing the cost function is a central aspect of +

    Minimizing the cost function is a central aspect of our discussions to come. Finding its minima as function of the model parameters (\( \alpha \) and \( \beta \) in our case) will be a recurring theme in these series of lectures. Essentially all machine learning @@ -1683,30 +2057,34 @@ employed are various variants of gradient methods. These will be discussed in more detail later. Again, you'll be surprised to hear that many practitioners minimize the above function ''by the eye', popularly dubbed as 'chi by the eye'. That is, change a parameter and see (visually and numerically) that -the \( \chi^2 \) function becomes smaller. +the \( \chi^2 \) function becomes smaller. +

    -

    -There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define +

    There are many ways to define the cost function. A simpler approach is to look at the relative difference between the training data and the predicted data, that is we define the relative error (why would we prefer the MSE instead of the relative error?) as +

    $$ \epsilon_{\mathrm{relative}}= \frac{\vert \boldsymbol{y} -\boldsymbol{\tilde{y}}\vert}{\vert \boldsymbol{y}\vert}. $$ -

    -The squared cost function results in an arithmetic mean-unbiased +

    The squared cost function results in an arithmetic mean-unbiased estimator, and the absolute-value cost function results in a median-unbiased estimator (in the one-dimensional case, and a geometric median-unbiased estimator for the multi-dimensional case). The squared cost function has the disadvantage that it has the tendency to be dominated by outliers. +

    -

    -We can modify easily the above Python code and plot the relative error instead -

    +

    We can modify easily the above Python code and plot the relative error instead

    -
    import numpy as np
    +
    +
    +
    +
    +
    +
    import numpy as np
     import matplotlib.pyplot as plt
     from sklearn.linear_model import LinearRegression
     
    @@ -1722,26 +2100,44 @@ plt.xlabel(r
     plt.ylabel(r'$\epsilon_{\mathrm{relative}}$')
     plt.title(r'Relative error')
     plt.show()
    -
    -

    -Depending on the parameter in front of the normal distribution, we may +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Depending on the parameter in front of the normal distribution, we may have a small or larger relative error. Try to play around with different training data sets and study (graphically) the value of the relative error. +

    -

    -As mentioned above, Scikit-Learn has an impressive functionality. +

    As mentioned above, Scikit-Learn has an impressive functionality. We can for example extract the values of \( \alpha \) and \( \beta \) and their error estimates, or the variance and standard deviation and many -other properties from the statistical data analysis. +other properties from the statistical data analysis. +

    -

    -Here we show an +

    Here we show an example of the functionality of Scikit-Learn. -

    +

    -
    import numpy as np 
    +
    +
    +
    +
    +
    +
    import numpy as np 
     import matplotlib.pyplot as plt 
     from sklearn.linear_model import LinearRegression 
     from sklearn.metrics import mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error
    @@ -1768,84 +2164,101 @@ plt.xlabel(r
     plt.ylabel(r'$y$')
     plt.title(r'Linear Regression fit ')
     plt.show()
    -
    -

    -The function coef gives us the parameter \( \beta \) of our fit while intercept yields +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The function coef gives us the parameter \( \beta \) of our fit while intercept yields \( \alpha \). Depending on the constant in front of the normal distribution, we get values near or far from \( \alpha =2 \) and \( \beta =5 \). Try to play around with different parameters in front of the normal distribution. The function meansquarederror gives us the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error or loss defined as +

    $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -

    -The smaller the value, the better the fit. Ideally we would like to +

    The smaller the value, the better the fit. Ideally we would like to have an MSE equal zero. The attentive reader has probably recognized this function as being similar to the \( \chi^2 \) function defined above. +

    -

    -The r2score function computes \( R^2 \), the coefficient of +

    The r2score function computes \( R^2 \), the coefficient of determination. It provides a measure of how well future samples are likely to be predicted by the model. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of \( \boldsymbol{y} \), disregarding the input features, would get a \( R^2 \) score of \( 0.0 \). +

    -

    -If \( \tilde{\boldsymbol{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 +

    If \( \tilde{\boldsymbol{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

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -Another quantity taht we will meet again in our discussions of regression analysis is +

    Another quantity taht we will meet again in our discussions of regression analysis is the mean absolute error (MAE), a risk metric corresponding to the expected value of the absolute error loss or what we call the \( l1 \)-norm loss. In our discussion above we presented the relative error. The MAE is defined as follows +

    $$ \text{MAE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. $$ -We present the +

    We present the squared logarithmic (quadratic) error +

    $$ \text{MSLE}(\boldsymbol{y}, \boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, $$ -

    -where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error +

    where \( \log_e (x) \) stands for the natural logarithm of \( x \). This error estimate is best to use when targets having exponential growth, such as population counts, average sales of a commodity over a span of -years etc. +years etc. +

    -

    -Finally, another cost function is the Huber cost function used in robust regression. +

    Finally, another cost function is the Huber cost function used in robust regression.

    -

    -The rationale behind this possible cost function is its reduced +

    The rationale behind this possible cost function is its reduced sensitivity to outliers in the data set. In our discussions on dimensionality reduction and normalization of data we will meet other ways of dealing with outliers. +

    -

    -The Huber cost function is defined as +

    The Huber cost function is defined as

    $$ H_{\delta}(\boldsymbol{a})=\left\{\begin{array}{cc}\frac{1}{2} \boldsymbol{a}^{2}& \text{for }|\boldsymbol{a}|\leq \delta\\ \delta (|\boldsymbol{a}|-\frac{1}{2}\delta ),&\text{otherwise}.\end{array}\right. $$ -Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \). +

    Here \( \boldsymbol{a}=\boldsymbol{y} - \boldsymbol{\tilde{y}} \).

    -

    -We will discuss in more detail these and other functions in the +

    We will discuss in more detail these and other functions in the various lectures. We conclude this part with another example. Instead of a linear \( x \)-dependence we study now a cubic polynomial and use the polynomial regression analysis tools of scikit-learn. +

    -

    -

    import matplotlib.pyplot as plt
    +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
     import numpy as np
     import random
     from sklearn.linear_model import Ridge
    @@ -1875,74 +2288,85 @@ plt.show()
         return abs(np.sum(err))/len(err)
     
     print (error(y))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    To our real data: nuclear binding energies. Brief reminder on masses and binding energies

    -

    -Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding +

    Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding energies. A basic quantity which can be measured for the ground states of nuclei is the atomic mass \( M(N, Z) \) of the neutral atom with -atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +atomic mass number \( A \) and charge \( Z \). The number of neutrons is \( N \). There are indeed several sophisticated experiments worldwide which allow us to measure this quantity to high precision (parts per million even). +

    -

    -Atomic masses are usually tabulated in terms of the mass excess defined by +

    Atomic masses are usually tabulated in terms of the mass excess defined by

    $$ \Delta M(N, Z) = M(N, Z) - uA, $$ -where \( u \) is the Atomic Mass Unit +

    where \( u \) is the Atomic Mass Unit

    $$ u = M(^{12}\mathrm{C})/12 = 931.4940954(57) \hspace{0.1cm} \mathrm{MeV}/c^2. $$ -The nucleon masses are +

    The nucleon masses are

    $$ m_p = 1.00727646693(9)u, $$ -and +

    and

    $$ m_n = 939.56536(8)\hspace{0.1cm} \mathrm{MeV}/c^2 = 1.0086649156(6)u. $$ -

    -In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu +

    In the 2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu there are data on masses and decays of 3437 nuclei. +

    -

    -The nuclear binding energy is defined as the energy required to break +

    The nuclear binding energy is defined as the energy required to break up a given nucleus into its constituent parts of \( N \) neutrons and \( Z \) protons. In terms of the atomic masses \( M(N, Z) \) the binding energy is defined by +

    $$ BE(N, Z) = ZM_H c^2 + Nm_n c^2 - M(N, Z)c^2 , $$ -where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. +

    where \( M_H \) is the mass of the hydrogen atom and \( m_n \) is the mass of the neutron. In terms of the mass excess the binding energy is given by +

    $$ BE(N, Z) = Z\Delta_H c^2 + N\Delta_n c^2 -\Delta(N, Z)c^2 , $$ -where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV. +

    where \( \Delta_H c^2 = 7.2890 \) MeV and \( \Delta_n c^2 = 8.0713 \) MeV.

    -

    -A popular and physically intuitive model which can be used to parametrize +

    A popular and physically intuitive model which can be used to parametrize the experimental binding energies as function of \( A \), is the so-called liquid drop model. The ansatz is based on the following expression +

    $$ BE(N,Z) = a_1A-a_2A^{2/3}-a_3\frac{Z^2}{A^{1/3}}-a_4\frac{(N-Z)^2}{A}, $$ -

    -where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit -to the experimental data. +

    where \( A \) stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit +to the experimental data. +

    -

    -To arrive at the above expression we have assumed that we can make the following assumptions: +

    To arrive at the above expression we have assumed that we can make the following assumptions:

    • There is a volume term \( a_1A \) proportional with the number of nucleons (the energy is also an extensive quantity). When an assembly of nucleons of the same size is packed together into the smallest volume, each interior nucleon has a certain number of other nucleons in contact with it. This contribution is proportional to the volume.
    • @@ -1950,24 +2374,26 @@ To arrive at the above expression we have assumed that we can make the following
    • There is a Coulomb energy term \( a_3\frac{Z^2}{A^{1/3}} \). The electric repulsion between each pair of protons in a nucleus yields less binding.
    • There is an asymmetry term \( a_4\frac{(N-Z)^2}{A} \). This term is associated with the Pauli exclusion principle and reflects the fact that the proton-neutron interaction is more attractive on the average than the neutron-neutron and proton-proton interactions.
    - -We could also add a so-called pairing term, which is a correction term that +

    We could also add a so-called pairing term, which is a correction term that arises from the tendency of proton pairs and neutron pairs to -occur. An even number of particles is more stable than an odd number. - +occur. An even number of particles is more stable than an odd number. +

    Organizing our data

    -

    -Let us start with reading and organizing our data. +

    Let us start with reading and organizing our data. We start with the compilation of masses and binding energies from 2016. After having downloaded this file to our own computer, we are now ready to read the file and start structuring our data. +

    -

    -We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn. -

    +

    We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of scikit-learn.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -2000,13 +2426,30 @@ DATA_ID = "
         plt.savefig(image_path(fig_id) + ".png", format='png')
     
     infile = open(data_path("MassEval2016.dat"),'r')
    -
    -

    -Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various matplotlib commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function.

    -
    from pylab import plt, mpl
    +
    +
    +
    +
    +
    +
    from pylab import plt, mpl
     plt.style.use('seaborn')
     mpl.rcParams['font.family'] = 'serif'
     
    @@ -2017,20 +2460,37 @@ mpl.rcParams[&#
             plt.xlabel(axlabels[0])
             plt.ylabel(axlabels[1])
         plt.legend(loc=0)
    -
    -

    -Our next step is to read the data on experimental binding energies and +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Our next step is to read the data on experimental binding energies and reorganize them as functions of the mass number \( A \), the number of protons \( Z \) and neutrons \( N \) using pandas. Before we do this it is always useful (unless you have a binary file or other types of compressed data) to actually open the file and simply take a look at it! +

    -

    -In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information. -

    +

    In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with pandas. The file begins with some basic format information.

    -
    """                                                                                                                         
    +
    +
    +
    +
    +
    +
    """                                                                                                                         
     This is taken from the data file of the mass 2016 evaluation.                                                               
     All files are 3436 lines long with 124 character per line.                                                                  
            Headers are 39 lines long.                                                                                           
    @@ -2040,17 +2500,35 @@ In particular, the program that outputs the final nuclear masses is written in F
        widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),                                                            
        Pandas has also a variable header, with length 39 in this case.                                                          
     """
    -
    -

    -The data we are interested in are in columns 2, 3, 4 and 11, giving us +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The data we are interested in are in columns 2, 3, 4 and 11, giving us the number of neutrons, protons, mass numbers and binding energies, respectively. We add also for the sake of completeness the element name. The data are in fixed-width formatted lines and we will covert them into the pandas DataFrame structure. +

    -

    -

    # Read the experimental data with Pandas
    +
    +
    +
    +
    +
    +
    # Read the experimental data with Pandas
     Masses = pd.read_fwf(infile, usecols=(2,3,4,6,11),
                   names=('N', 'Z', 'A', 'Element', 'Ebinding'),
                   widths=(1,3,5,5,5,1,3,4,1,13,11,11,9,1,2,11,9,1,3,1,12,11,1),
    @@ -2068,58 +2546,129 @@ Masses['Ebinding'] = Masses.groupby('A')
     # Find the rows of the grouped DataFrame with the maximum binding energy.
     Masses = Masses.apply(lambda t: t[t.Ebinding==t.Ebinding.max()])
    -
    -

    -We have now read in the data, grouped them according to the variables we are interested in. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    We have now read in the data, grouped them according to the variables we are interested in. We see how easy it is to reorganize the data using pandas. If we were to do these operations in C/C++ or Fortran, we would have had to write various functions/subroutines which perform the above reorganizations for us. Having reorganized the data, we can now start to make some simple fits using both the functionalities in numpy and -Scikit-Learn afterwards. +Scikit-Learn afterwards. +

    -

    -Now we define five variables which contain +

    Now we define five variables which contain the number of nucleons \( A \), the number of protons \( Z \) and the number of neutrons \( N \), the element name and finally the energies themselves. -

    +

    -
    A = Masses['A']
    +
    +
    +
    +
    +
    +
    A = Masses['A']
     Z = Masses['Z']
     N = Masses['N']
     Element = Masses['Element']
     Energies = Masses['Ebinding']
     print(Masses)
    -
    -

    -The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    The next step, and we will define this mathematically later, is to set up the so-called design matrix. We will throughout call this matrix \( \boldsymbol{X} \). It has dimensionality \( p\times n \), where \( n \) is the number of data points and \( p \) are the so-called predictors. In our case here they are given by the number of polynomials in \( A \) we wish to include in the fit. -

    +

    -
    # Now we set up the design matrix X
    +
    +
    +
    +
    +
    +
    # Now we set up the design matrix X
     X = np.zeros((len(A),5))
     X[:,0] = 1
     X[:,1] = A
     X[:,2] = A**(2.0/3.0)
     X[:,3] = A**(-1.0/3.0)
     X[:,4] = A**(-1.0)
    -
    -

    -With scikitlearn we are now ready to use linear regression and fit our data. -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With scikitlearn we are now ready to use linear regression and fit our data.

    -
    clf = skl.LinearRegression().fit(X, Energies)
    +
    +
    +
    +
    +
    +
    clf = skl.LinearRegression().fit(X, Energies)
     fity = clf.predict(X)
    -
    -

    -Pretty simple! +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Pretty simple! Now we can print measures of how our fit is doing, the coefficients from the fits and plot the final fit together with our data. -

    +

    -
    # The mean squared error                               
    +
    +
    +
    +
    +
    +
    # The mean squared error                               
     print("Mean squared error: %.2f" % mean_squared_error(Energies, fity))
     # Explained variance score: 1 is perfect prediction                                 
     print('Variance score: %.2f' % r2_score(Energies, fity))
    @@ -2139,17 +2688,32 @@ ax.plot(Masses[
     ax.legend()
     save_fig("Masses2016")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    Seeing the wood for the trees

    -

    -As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests! +

    As a teaser, let us now see how we can do this with decision trees using scikit-learn. Later we will switch to so-called random forests!

    -

    -

    #Decision Tree Regression
    +
    +
    +
    +
    +
    +
    #Decision Tree Regression
     from sklearn.tree import DecisionTreeRegressor
     regr_1=DecisionTreeRegressor(max_depth=5)
     regr_2=DecisionTreeRegressor(max_depth=7)
    @@ -2178,16 +2742,32 @@ save_fig("Masses2016Trees")
     plt.show()
     print(Masses)
     print(np.mean( (Energies-y_1)**2))
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    And what about using neural networks?

    - -The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) +

    The seaborn package allows us to visualize data in an efficient way. Note that we use scikit-learn's multi-layer perceptron (or feed forward neural network) functionality. -

    +

    -
    from sklearn.neural_network import MLPRegressor
    +
    +
    +
    +
    +
    +
    from sklearn.neural_network import MLPRegressor
     from sklearn.metrics import accuracy_score
     import seaborn as sns
     
    @@ -2216,30 +2796,38 @@ ax.set_title(&q
     ax.set_ylabel("$\eta$")
     ax.set_xlabel("$\lambda$")
     plt.show()
    -
    - +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +

    A first summary

    -

    -The aim behind these introductory words was to present to you various +

    The aim behind these introductory words was to present to you various Python libraries and their functionalities, in particular libraries like numpy, pandas, xarray and matplotlib and other that make our life much easier -in handling various data sets and visualizing data. +in handling various data sets and visualizing data. +

    -

    -Furthermore, +

    Furthermore, Scikit-Learn allows us with few lines of code to implement popular Machine Learning algorithms for supervised learning. Later we will meet Tensorflow, a powerful library for deep learning. Now it is time to dive more into the details of various methods. We will start with linear regression and try to take a deeper look at what it entails. +

    -











    -

    Why Linear Regression (aka Ordinary Least Squares and family)

    -

    -Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \). - +

    Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).

    • Method of choice for fitting a continuous function!
    • Gives an excellent introduction to central Machine Learning features with understandable pedagogical links to other methods like Neural Networks, Support Vector Machines etc
    • @@ -2251,50 +2839,42 @@ Fitting a continuous function with linear parameterization in terms of the param
    • Allows for easy hands-on understanding of gradient descent methods
    • and many more features
    - -For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. +

    For more discussions of Ridge and Lasso regression, Wessel van Wieringen's article is highly recommended. Similarly, Mehta et al's article is also recommended. +

    -











    -

    Regression analysis, overarching aims

    -

    -Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). -The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. - -

    -A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with +

    Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \). +The first variable is called the dependent, the outcome or the response variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable. +

    +

    A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with

    • \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)
    • Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)
    • \( p \) so-called explanatory (independent or predictor) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.
    - - The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things. +

    The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.

    -











    -

    Regression analysis, overarching aims II

    -

    -Consider an experiment in which \( p \) characteristics of \( n \) samples are +

    Consider an experiment in which \( p \) characteristics of \( n \) samples are measured. The data from this experiment, for various explanatory variables \( p \) are normally represented by a matrix \( \mathbf{X} \). +

    -

    -The matrix \( \mathbf{X} \) is called the design +

    The matrix \( \mathbf{X} \) is called the design matrix. Additional information of the samples is available in the form of \( \boldsymbol{y} \) (also as above). The variable \( \boldsymbol{y} \) is generally referred to as the response variable. The aim of @@ -2304,73 +2884,62 @@ f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of \( f(\cdot) \) is available, it is common to assume a linear relationship between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to the linear regression model where \( \boldsymbol{\beta} = [\beta_0, \ldots, -\beta_{p-1}]^{T} \) are the regression parameters. - -

    -Linear regression gives us a set of analytical equations for the parameters \( \beta_j \). - +\beta_{p-1}]^{T} \) are the regression parameters. +

    +

    Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).

    -











    -

    Examples

    -In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), -consider the model we discussed for describing nuclear binding energies. +

    In order to understand the relation among the predictors \( p \), the set of data \( n \) and the target (outcome, output etc) \( \boldsymbol{y} \), +consider the model we discussed for describing nuclear binding energies. +

    -

    -There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. +

    There we assumed that we could parametrize the data using a polynomial approximation based on the liquid drop model. Assuming +

    $$ BE(A) = a_0+a_1A+a_2A^{2/3}+a_3A^{-1/3}+a_4A^{-1}, $$ -we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. +

    we have five predictors, that is the intercept, the \( A \) dependent term, the \( A^{2/3} \) term and the \( A^{-1/3} \) and \( A^{-1} \) terms. This gives \( p=0,1,2,3,4 \). Furthermore we have \( n \) entries for each predictor. It means that our design matrix is a \( p\times n \) matrix \( \boldsymbol{X} \). +

    -

    -Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the -so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. - - +

    Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the +so-called credit card default data from Taiwan. The data set contains data on \( n=30000 \) credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are \( 24 \) such predictors or attributes leading to a design matrix of dimensionality \( 24 \times 30000 \). This is however a classification problem and we will come back to it when we discuss Logistic Regression. +

    -











    -

    General linear models

    -Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function. +

    Before we proceed let us study a case from linear algebra where we aim at fitting a set of data \( \boldsymbol{y}=[y_0,y_1,\dots,y_{n-1}] \). We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables \( \boldsymbol{x}=[x_0,x_1,\dots,x_{n-1}] \), that is \( y_i = y(x_i) \) with \( i=0,1,2,\dots,n-1 \). The variables \( x_i \) could represent physical quantities like time, temperature, position etc. We assume that \( y(x) \) is a smooth function.

    -

    -Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is +

    Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is

    $$ y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i, $$ -where \( \epsilon_i \) is the error in our approximation. - - +

    where \( \epsilon_i \) is the error in our approximation.

    -











    -

    Rewriting the fitting procedure as a linear algebra problem

    -For every set of values \( y_i,x_i \) we have thus the corresponding set of equations +

    For every set of values \( y_i,x_i \) we have thus the corresponding set of equations

    $$ \begin{align*} y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\ @@ -2383,29 +2952,27 @@ $$
    -











    -

    Rewriting the fitting procedure as a linear algebra problem, more details

    -Defining the vectors +

    Defining the vectors

    $$ \boldsymbol{y} = [y_0,y_1, y_2,\dots, y_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T, $$ -and +

    and

    $$ \boldsymbol{\epsilon} = [\epsilon_0,\epsilon_1, \epsilon_2,\dots, \epsilon_{n-1}]^T, $$ -and the design matrix +

    and the design matrix

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -2417,29 +2984,27 @@ $$ \end{bmatrix} $$ -we can rewrite our equations as +

    we can rewrite our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The above design matrix is called a Vandermonde matrix. +

    The above design matrix is called a Vandermonde matrix.

    -











    -

    Generalizing the fitting procedure as a linear algebra problem

    -

    -We are obviously not limited to the above polynomial expansions. We +

    We are obviously not limited to the above polynomial expansions. We could replace the various powers of \( x \) with elements of Fourier series or instead of \( x_i^j \) we could have \( \cos{(j x_i)} \) or \( \sin{(j x_i)} \), or time series or other orthogonal functions. For every set of values \( y_i,x_i \) we can then generalize the equations to +

    $$ \begin{align*} @@ -2453,19 +3018,17 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    + Note that we have \( p=n \) here. The matrix is symmetric. This is generally not the case!

    -











    -

    Generalizing the fitting procedure as a linear algebra problem

    -We redefine in turn the matrix \( \boldsymbol{X} \) as +

    We redefine in turn the matrix \( \boldsymbol{X} \) as

    $$ \boldsymbol{X}= \begin{bmatrix} @@ -2477,23 +3040,21 @@ x_{n-1,0}& x_{n-1,1} &x_{n-1,2}& \dots & \dots &x_{n-1,n-1}\\ \end{bmatrix} $$ -and without loss of generality we rewrite again our equations as +

    and without loss of generality we rewrite again our equations as

    $$ \boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}. $$ -The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? +

    The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values?

    -











    -

    Optimizing our parameters

    -We have defined the matrix \( \boldsymbol{X} \) via the equations +

    We have defined the matrix \( \boldsymbol{X} \) via the equations

    $$ \begin{align*} y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\ @@ -2506,29 +3067,27 @@ y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{ \end{align*} $$ -

    -As we noted above, we stayed with a system with the design matrix +

    As we noted above, we stayed with a system with the design matrix \( \boldsymbol{X}\in {\mathbb{R}}^{n\times n} \), that is we have \( p=n \). For reasons to come later (algorithmic arguments) we will hereafter define our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predictors refering to the column numbers and the entries \( n \) being the row elements. - - +

    -











    -

    Our model for the nuclear binding energies

    -

    -In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code. +

    In our introductory notes we looked at the so-called liquid drop model. Let us remind ourselves about what we did by looking at the code.

    -

    -We restate the parts of the code we are most interested in. -

    +

    We restate the parts of the code we are most interested in.

    -
    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -2597,73 +3156,81 @@ DesignMatrix = pd.index = A
     DesignMatrix.columns = ['1', 'A', 'A^(2/3)', 'A^(-1/3)', '1/A']
     display(DesignMatrix)
    -
    -

    -With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -throughout these lectures. +

    throughout these lectures.

    -











    -

    Optimizing our parameters, more details

    -With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as +

    With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as

    $$ \boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta}, $$ -and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely +

    and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as +

    or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -This function is one possible way to define the so-called cost function. +

    This function is one possible way to define the so-called cost function.

    -

    -It is also common to define +

    It is also common to define the function \( C \) as +

    $$ C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2, $$ -since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. +

    since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out.

    -











    -

    Interpretations and optimizing our parameters

    -

    -The function +

    The function

    $$ C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}, $$ -can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. +

    can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value. When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value +

    $$ y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i, $$ -

    -where \( \langle y_i \rangle \) is the mean value. Keep in mind also that +

    where \( \langle y_i \rangle \) is the mean value. Keep in mind also that till now we have treated \( y_i \) as the exact value. Normally, the response (dependent or outcome) variable \( y_i \) the outcome of a numerical experiment or another type of experiment and is thus only an @@ -2671,57 +3238,52 @@ approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem

    $$ {\displaystyle \min_{\boldsymbol{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}. $$ -In practical terms it means we will require +

    In practical terms it means we will require

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right). $$ - -
    -











    -

    Interpretations and optimizing our parameters

    -We can rewrite +

    We can rewrite

    $$ \frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}. $$ -

    -We note also that since our design matrix is defined as \( \boldsymbol{X}\in +

    We note also that since our design matrix is defined as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), the product \( \boldsymbol{X}^T\boldsymbol{X} \in {\mathbb{R}}^{p\times p} \). In the above case we have that \( p \ll n \), in our case \( p=5 \) meaning that we end up with inverting a small @@ -2730,26 +3292,24 @@ matrices to invert. The methods discussed here and for many other supervised learning algorithms like classification with logistic regression or support vector machines, exhibit dimensionalities which allow for the usage of direct linear algebra methods such as LU decomposition or Singular Value Decomposition (SVD) for finding the inverse of the matrix -\( \boldsymbol{X}^T\boldsymbol{X} \). +\( \boldsymbol{X}^T\boldsymbol{X} \). +

    -

    -Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect? +

    Small question: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix \( \boldsymbol{X}^T\boldsymbol{X} \)? What kind of problems can we expect?

    -











    -

    Some useful matrix and vector expressions

    -

    -The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and +

    The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and matrices as upper case boldfaced letters. +

    $$ \frac{\partial (\boldsymbol{b}^T\boldsymbol{a})}{\partial \boldsymbol{a}} = \boldsymbol{b}, @@ -2768,65 +3328,97 @@ $$ $$









    -

    Interpretations and optimizing our parameters

    -The residuals \( \boldsymbol{\epsilon} \) are in turn given by +

    The residuals \( \boldsymbol{\epsilon} \) are in turn given by

    $$ \boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}, $$ -and with +

    and with

    $$ \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -we have +

    we have

    $$ \boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0, $$ -meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach. - - +

    meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.

    -

    -Let us now return to our nuclear binding energies and simply code the above equations. +

    Let us now return to our nuclear binding energies and simply code the above equations.

    -











    -

    Own code for Ordinary Least Squares

    -

    -It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to +

    It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to write -

    +

    -
    # matrix inversion to find beta
    +
    +
    +
    +
    +
    +
    # matrix inversion to find beta
     beta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(Energies)
     # and then make the prediction
     ytilde = X @ beta
    -
    -

    -Alternatively, you can use the least squares functionality in Numpy as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Alternatively, you can use the least squares functionality in Numpy as

    -
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
    +
    +
    +
    +
    +
    +
    fit = np.linalg.lstsq(X, Energies, rcond =None)[0]
     ytildenp = np.dot(fit,X.T)
    -
    -

    -And finally we plot our fit with and compare with data -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    And finally we plot our fit with and compare with data

    -
    Masses['Eapprox']  = ytilde
    +
    +
    +
    +
    +
    +
    Masses['Eapprox']  = ytilde
     # Generate a plot comparing the experimental with the fitted values values.
     fig, ax = plt.subplots()
     ax.set_xlabel(r'$A = N + Z$')
    @@ -2838,200 +3430,266 @@ ax.plot(Masses[
     ax.legend()
     save_fig("Masses2016OLS")
     plt.show()
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    Adding error analysis and training set up

    -

    -We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. +

    We can easily test our fit by computing the \( R2 \) score that we discussed in connection with the functionality of Scikit-Learn in the introductory slides. Since we are not using Scikit-Learn here we can define our own \( R2 \) function as -

    +

    -
    def R2(y_data, y_model):
    +
    +
    +
    +
    +
    +
    def R2(y_data, y_model):
         return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
    -
    -

    -and we would be using it as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and we would be using it as

    -
    print(R2(Energies,ytilde))
    -
    -

    -We can easily add our MSE score as -

    +

    +
    +
    +
    +
    +
    print(R2(Energies,ytilde))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    We can easily add our MSE score as

    -
    def MSE(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def MSE(y_data,y_model):
         n = np.size(y_model)
         return np.sum((y_data-y_model)**2)/n
     
     print(MSE(Energies,ytilde))
    -
    -

    -and finally the relative error as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    and finally the relative error as

    -
    def RelativeError(y_data,y_model):
    +
    +
    +
    +
    +
    +
    def RelativeError(y_data,y_model):
         return abs((y_data-y_model)/y_data)
     print(RelativeError(Energies, ytilde))
    -
    -

    -









    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    The \( \chi^2 \) function

    -

    -Normally, the response (dependent or outcome) variable \( y_i \) is the +

    Normally, the response (dependent or outcome) variable \( y_i \) is the outcome of a numerical experiment or another type of experiment and is thus only an approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. +

    -

    -Introducing the standard deviation \( \sigma_i \) for each measurement +

    Introducing the standard deviation \( \sigma_i \) for each measurement \( y_i \), we define now the \( \chi^2 \) function (omitting the \( 1/n \) term) as +

    $$ \chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\}, $$ -where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. - - +

    where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements.

    -











    -

    The \( \chi^2 \) function

    -

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring +

    In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0, $$ -which results in +

    which results in

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0, $$ -or in a matrix-vector form as +

    or in a matrix-vector form as

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right). $$ -where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). +

    where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \).

    -











    -

    The \( \chi^2 \) function

    -

    -We can rewrite +

    We can rewrite

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right), $$ -as +

    as

    $$ \boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta}, $$ -and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution +

    and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution

    $$ \boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}. $$
    -











    -

    The \( \chi^2 \) function

    -

    -If we then introduce the matrix +

    If we then introduce the matrix

    $$ \boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}, $$ -we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \)) +

    we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))

    $$ \beta_j = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}\frac{y_i}{\sigma_i}\frac{x_{ik}}{\sigma_i} = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}b_ia_{ik} $$ -We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise) +

    We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)

    $$ \sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2, $$ -resulting in +

    resulting in

    $$ \sigma^2(\beta_j) = \left(\sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}a_{ik}\right)\left(\sum_{l=0}^{p-1}h_{jl}\sum_{m=0}^{n-1}a_{ml}\right) = h_{jj}! $$
    -











    -

    The \( \chi^2 \) function

    -The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write +

    The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write

    $$ y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i. $$ -By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by +

    By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0, $$ -and +

    and

    $$ \frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0. $$
    -











    -

    The \( \chi^2 \) function

    -

    -For a linear fit (a first-order polynomial) we don't need to invert a matrix!! +

    For a linear fit (a first-order polynomial) we don't need to invert a matrix!! Defining +

    $$ \gamma = \sum_{i=0}^{n-1}\frac{1}{\sigma_i^2}, $$ @@ -3056,8 +3714,7 @@ $$ \gamma_{xy} = \sum_{i=0}^{n-1}\frac{y_ix_{i}}{\sigma_i^2}, $$ -

    -we obtain +

    we obtain

    $$ \beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}, @@ -3068,50 +3725,48 @@ $$ \beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}. $$ -

    -This approach (different linear and non-linear regression) suffers +

    This approach (different linear and non-linear regression) suffers often from both being underdetermined and overdetermined in the unknown coefficients \( \beta_i \). A better approach is to use the Singular Value Decomposition (SVD) method discussed next week. - - +

    -











    -

    Fitting an Equation of State for Dense Nuclear Matter

    -

    -Before we continue, let us introduce yet another example. We are going to fit the +

    Before we continue, let us introduce yet another example. We are going to fit the nuclear equation of state using results from many-body calculations. The equation of state we have made available here, as function of density, has been derived using modern nucleon-nucleon potentials with the addition of three-body forces. This time the file is presented as a standard csv file. +

    -

    -The beginning of the Python code here is similar to what you have seen +

    The beginning of the Python code here is similar to what you have seen before, with the same initializations and declarations. We use also pandas again, rather extensively in order to organize our data. +

    -

    -The difference now is that we use Scikit-Learn's regression tools +

    The difference now is that we use Scikit-Learn's regression tools instead of our own matrix inversion implementation. Furthermore, we sneak in Ridge regression (to be discussed below) which includes a hyperparameter \( \lambda \), also to be explained below. +

    -











    -

    The code

    -

    -

    # Common imports
    +
    +
    +
    +
    +
    +
    # Common imports
     import os
     import numpy as np
     import pandas as pd
    @@ -3196,23 +3851,34 @@ ax.plot(EoS[
     ax.legend()
     save_fig("EoSfitting")
     plt.show()
    -
    -

    -The above simple polynomial in density \( \rho \) gives an excellent fit -to the data. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + -

    -We note also that there is a small deviation between the +

    The above simple polynomial in density \( \rho \) gives an excellent fit +to the data. +

    + +

    We note also that there is a small deviation between the standard OLS and the Ridge regression at higher densities. We discuss this in more detail below. +

    -











    -

    Splitting our Data in Training and Test data

    -

    -It is normal in essentially all Machine Learning studies to split the +

    It is normal in essentially all Machine Learning studies to split the data in a training set and a test set (sometimes also an additional validation set). Scikit-Learn has an own function for this. There is no explicit recipe for how much data should be included as training @@ -3222,11 +3888,16 @@ postpone a discussion of this splitting to the end of these notes and our discussion of the so-called bias-variance tradeoff. Here we limit ourselves to repeat the above equation of state fitting example but now splitting the data into a training set and a test set. +

    -

    -

    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -3290,144 +3961,172 @@ ypredict = X_test print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +









    -

    Exercises for week 35

    -Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1. +

    Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1.

    -

    -

    Exercise 1: Setting up various Python environments

    -

    -The first exercise here is of a mere technical art. We want you to have - +

    The first exercise here is of a mere technical art. We want you to have

    • 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.
    • Install various Python packages
    - -We will make extensive use of Python as programming language and its +

    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. +

    -

    -If you have Python installed (we recommend Python3) and you feel +

    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 +

    1. pip install numpy scipy matplotlib ipython scikit-learn sympy pandas pillow
    - -For Tensorflow, we recommend following the instructions in the text of +

    For Tensorflow, we recommend following the instructions in the text of Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly +

    -

    -We will come back to tensorflow later. +

    We will come back to tensorflow later.

    -

    -For Python3, replace pip with pip3. +

    For Python3, replace pip with pip3.

    -

    -For OSX users we recommend, after having installed Xcode, to +

    For OSX users we recommend, after having installed Xcode, to install brew. Brew allows for a seamless installation of additional software via for example +

    1. brew install python3
    - -For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +

    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 +

    1. sudo apt-get install python3 (or python for Python2.7)
    - -If you don't want to perform these operations separately and venture +

    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 +

    - -which is an open source +

    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. +

    - -is a Python +

    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 if you are not too familiar with setting paths in a terminal environment. +

    We recommend using Anaconda if you are not too familiar with setting paths in a terminal environment.

    -

    -

    -

    Exercise 2: making your own data and exploring scikit-learn

    -

    -We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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) \). +

    We will generate our own dataset for a function \( y(x) \) where \( x \in [0,1] \) 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). -

    +

    -
    x = np.random.rand(100,1)
    +
    +
    +
    +
    +
    +
    x = np.random.rand(100,1)
     y = 2.0+5*x*x+0.1*np.random.randn(100,1)
    -
    +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +
    1. Write your own code (following the examples under the regression notes) for computing the parametrization of the data set fitting a second-order polynomial.
    2. Use thereafter scikit-learn (see again the examples in the regression slides) and compare with your own code.
    3. Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as
    - $$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ -and the \( R^2 \) score function. +

    and the \( R^2 \) score function. If \( \tilde{\boldsymbol{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 +

    $$ R^2(\boldsymbol{y}, \tilde{\boldsymbol{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, $$ -where we have defined the mean value of \( \boldsymbol{y} \) as +

    where we have defined the mean value of \( \boldsymbol{y} \) as

    $$ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. $$ -You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. +

    You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. 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. +

    -

    +

    Solution. The code here is an example of where we define our own design matrix and fit parameters \( \beta \). -

    +

    -
    import os
    +
    +
    +
    +
    +
    +
    import os
     import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -3467,26 +4166,36 @@ ypredict = X_test print(R2(y_test,ypredict))
     print("Test MSE")
     print(MSE(y_test,ypredict))
    -
    -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + + -

    -

    -

    Exercise 3: Normalizing our data

    -

    -A much used approach before starting to train the data is to preprocess our +

    A much used approach before starting to train the data is to preprocess our data. Normally the data may need a rescaling and/or may be sensitive to extreme values. Scaling the data renders our inputs much more suitable for the algorithms we want to employ. +

    -

    -Scikit-Learn has several functions which allow us to rescale the +

    Scikit-Learn has several functions which allow us to rescale the data, normally resulting in much better results in terms of various accuracy scores. The StandardScaler function in Scikit-Learn ensures that for each feature/predictor we study the mean value is @@ -3495,18 +4204,18 @@ matrix). This scaling has the drawback that it does not ensure that we have a particular maximum or minimum in our data set. Another function included in Scikit-Learn is the MinMaxScaler which ensures that all features are exactly between \( 0 \) and \( 1 \). The +

    -

    -The Normalizer scales each data +

    The Normalizer scales each data point such that the feature vector has a euclidean length of one. In other words, it projects a data point on the circle (or sphere in the case of higher dimensions) with a radius of 1. This means every data point is scaled by a different number (by the inverse of it’s length). This normalization is often used when only the direction (or angle) of the data matters, not the length of the feature vector. +

    -

    -The RobustScaler works similarly to the StandardScaler in that it +

    The RobustScaler works similarly to the StandardScaler in that it ensures statistical properties for each feature that guarantee that they are on the same scale. However, the RobustScaler uses the median and quartiles, instead of mean and variance. This makes the @@ -3514,74 +4223,131 @@ RobustScaler ignore data points that are very different from the rest (like measurement errors). These odd data points are also called outliers, and might often lead to trouble for other scaling techniques. +

    -

    -It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest +

    It also common to split the data in a training set and a testing set. A typical split is to use \( 80\% \) of the data for training and the rest for testing. This can be done as follows with our design matrix \( \boldsymbol{X} \) and data \( \boldsymbol{y} \) (remember to import scikit-learn) -

    +

    -
    # split in training and test data
    +
    +
    +
    +
    +
    +
    # split in training and test data
     X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
    -
    -

    -Then we can use the standard scaler to scale our data as -

    +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    Then we can use the standard scaler to scale our data as

    -
    scaler = StandardScaler()
    +
    +
    +
    +
    +
    +
    scaler = StandardScaler()
     scaler.fit(X_train)
     X_train_scaled = scaler.transform(X_train)
     X_test_scaled = scaler.transform(X_test)
    -
    -

    -In this exercise we want you to to compute the MSE for the training +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + + +

    In this exercise we want you to to compute the MSE for the training data and the test data as function of the complexity of a polynomial, -that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +that is the degree of a given polynomial. We want you also to compute the \( R2 \) score as function of the complexity of the model for both training data and test data. You should also run the calculation with and without scaling. +

    -

    -One of +

    One of the aims is to reproduce Figure 2.11 of Hastie et al. +

    -

    -Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points. -

    +

    Our data is defined by \( x\in [-3,3] \) with a total of for example \( 100 \) data points.

    -
    np.random.seed()
    +
    +
    +
    +
    +
    +
    np.random.seed()
     n = 100
     maxdegree = 14
     # Make data set.
     x = np.linspace(-3, 3, n).reshape(-1, 1)
     y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
    -
    -

    -where \( y \) is the function we want to fit with a given polynomial. +

    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    + +

    where \( y \) is the function we want to fit with a given polynomial.

    + +

    a) Write a first code which sets up a design matrix \( X \) defined by a fifth-order polynomial. Scale your data and split it in training and test data. +

    + + +

    b) Perform an ordinary least squares and compute the means squared error and the \( R2 \) factor for the training data and the test data, with and without scaling. +

    + + +

    c) Add now a model which allows you to make polynomials up to degree \( 15 \). Perform a standard OLS fitting of the training data and compute the MSE and \( R2 \) for the training and test data and plot both test and training data MSE and \( R2 \) as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)? +

    + + -

    - - -

    © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    - - - diff --git a/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz b/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz index c9c5818ce..fb3386a2f 100644 Binary files a/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz and b/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz differ diff --git a/doc/pub/week34/ipynb/week34.ipynb b/doc/pub/week34/ipynb/week34.ipynb index 3c16b014b..a4065e2da 100644 --- a/doc/pub/week34/ipynb/week34.ipynb +++ b/doc/pub/week34/ipynb/week34.ipynb @@ -2,25 +2,38 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "id": "778fa583", + "metadata": { + "editable": true + }, + "source": [ + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "a6b35c1f", + "metadata": { + "editable": true + }, "source": [ - "\n", "# Week 34: Introduction to the course, Logistics and Practicalities\n", - "\n", - " \n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **Oct 12, 2021**\n", - "\n", - "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "Date: **Nov 13, 2021**\n", "\n", + "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license" + ] + }, + { + "cell_type": "markdown", + "id": "fc8efbd6", + "metadata": { + "editable": true + }, + "source": [ "## Overview of first week\n", "\n", " * Wednesday August 25: Introduction to software and repetition of Python Programming\n", @@ -31,10 +44,16 @@ "\n", " * Friday August 27: Linear regression \n", "\n", - " * Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 25.\n", - "\n", - "\n", - "\n", + " * Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 25." + ] + }, + { + "cell_type": "markdown", + "id": "4e83c342", + "metadata": { + "editable": true + }, + "source": [ "## Reading Recommendations\n", "\n", "For the reading assignments we use the following abbreviations:\n", @@ -46,32 +65,38 @@ "\n", "* AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow\n", "\n", - "Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at \n", - "\n", - "\n", - "\n", - "\n", + "Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at " + ] + }, + { + "cell_type": "markdown", + "id": "fcee1694", + "metadata": { + "editable": true + }, + "source": [ "## Thursday August 26\n", "\n", - "\n", - "\n", - "\n", "The lectures will be recorded and updated videos will be posted after the lectures. \n", "\n", "\"Video of Lecture August 26, 2021\":\"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage\n", "\n", - "\n", "**Zoom link for lectures**: \n", "\n", "* Meeting ID: 933 1152 9525\n", "\n", "* Passcode: 646102\n", "\n", - "[Video of Lecture from Fall Semester 2020](https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/zoom_0.mp4?vrtx=view-as-webpage).\n", - "\n", - "\n", - "\n", - "\n", + "[Video of Lecture from Fall Semester 2020](https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/zoom_0.mp4?vrtx=view-as-webpage)." + ] + }, + { + "cell_type": "markdown", + "id": "e9c0ae5d", + "metadata": { + "editable": true + }, + "source": [ "## Lectures and ComputerLab\n", "\n", " * Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm). \n", @@ -84,24 +109,44 @@ "\n", " * Weekly plans and all other information are on the official webpage.\n", "\n", - " * No final exam, three projects that are graded and have to be approved.\n", - "\n", - "\n", - "\n", - "\n", + " * No final exam, three projects that are graded and have to be approved." + ] + }, + { + "cell_type": "markdown", + "id": "e862726a", + "metadata": { + "editable": true + }, + "source": [ "## Announcement\n", "\n", - "**NORA AI competetion:** See the link here \n", - "\n", - "\n", + "**NORA AI competetion:** See the link here " + ] + }, + { + "cell_type": "markdown", + "id": "b7e9a904", + "metadata": { + "editable": true + }, + "source": [ "## Communication channels\n", "\n", "* Chat and communications via , GDPR safe\n", "\n", "* **Slack** channel: machinelearninguio.slack.com\n", "\n", - "* **Piazza** : enlist at \n", - "\n", + "* **Piazza** : enlist at " + ] + }, + { + "cell_type": "markdown", + "id": "cb950912", + "metadata": { + "editable": true + }, + "source": [ "## Course Format\n", "\n", " * Three compulsory projects. Electronic reports only using [Canvas](https://www.uio.no/english/services/it/education/canvas/) to hand in projects and [git](https://git-scm.com/) as version control software and [GitHub](https://github.com/) for repository (or [GitLab](https://about.gitlab.com/)) of all your material.\n", @@ -116,17 +161,18 @@ "\n", "d. Based on feedback etc, each group finalizes the report and submits for grading. \n", "\n", - "\n", - " * Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and [github address](https://github.com/CompPhysics/MachineLearning/tree/master/doc/Programs) of the course.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + " * Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and [github address](https://github.com/CompPhysics/MachineLearning/tree/master/doc/Programs) of the course." + ] + }, + { + "cell_type": "markdown", + "id": "4f4f5449", + "metadata": { + "editable": true + }, + "source": [ "## Teachers\n", "\n", - "\n", "**Teachers :**\n", "* Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no\n", "\n", @@ -136,44 +182,50 @@ "\n", " * **Office hours**: *Anytime*! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning. \n", "\n", - "\n", "* Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no\n", "\n", " * **Office**: Department of Physics, University of Oslo, Eastern wing, room FØ452\n", "\n", - "\n", "* Stian Dysthe Bilek stian.bilek@fys.uio.no\n", "\n", " * **Office**: Department of Physics, University of Oslo, Eastern wing, room FØ450\n", "\n", - "\n", "* Linus Ekstrøm, linueks@gmail.com, linus.ekstrom@fys.uio.no\n", "\n", "* Nicholas Karlsen, nicholaskarlsen1102@gmail.com, nicholas.karlsen@fys.uio.no\n", "\n", "* Bendik Steinsvåg Dalen, b.s.dalen@fys.uio.no\n", "\n", - "* Philip Karim Sørli Niane, p.k.s.niane@fys.uio.no\n", - "\n", - "\n", - "\n", + "* Philip Karim Sørli Niane, p.k.s.niane@fys.uio.no" + ] + }, + { + "cell_type": "markdown", + "id": "0de9f263", + "metadata": { + "editable": true + }, + "source": [ "## Deadlines for projects (tentative)\n", "\n", - "\n", "1. Project 1: October 11 (available September 10) graded with feedback)\n", "\n", - "2. Project 2: November 15 (available October 12, graded with feedback)\n", - "\n", - "3. Project 3: December 13 (available November 8, graded with feedback)\n", - "\n", - "Projects are handed in using **Canvas**. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via **Canvas**.\n", - "\n", - "\n", + "2. Project 2: November 20 (available October 12, graded with feedback)\n", "\n", + "3. Project 3: December 17 (available November 13, graded with feedback)\n", "\n", + "Projects are handed in using **Canvas**. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via **Canvas**." + ] + }, + { + "cell_type": "markdown", + "id": "39cb9d48", + "metadata": { + "editable": true + }, + "source": [ "## Recommended textbooks\n", "\n", - "\n", "1. The lecture notes are collected as a jupyter-book at \n", "\n", "In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below.\n", @@ -186,8 +238,16 @@ "\n", "1. Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, This is a well-known text and serves as additional literature.\n", "\n", - "2. Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course.\n", - "\n", + "2. Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course." + ] + }, + { + "cell_type": "markdown", + "id": "45351170", + "metadata": { + "editable": true + }, + "source": [ "## Prerequisites\n", "\n", "Basic knowledge in programming and mathematics, with an emphasis on\n", @@ -198,14 +258,18 @@ "of the corresponding computing and programming courses INF1000/INF1110\n", "or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1100. Most universities\n", "offer nowadays a basic programming course (often compulsory) where\n", - "Python is the recurring programming language.\n", - "\n", - "\n", - "\n", + "Python is the recurring programming language." + ] + }, + { + "cell_type": "markdown", + "id": "071161a1", + "metadata": { + "editable": true + }, + "source": [ "## Learning outcomes\n", "\n", - "\n", - "\n", "This course aims at giving you insights and knowledge about many of\n", "the central algorithms used in Data Analysis and Machine Learning.\n", "The course is project based and through various numerical projects,\n", @@ -238,10 +302,16 @@ "\n", "* Autoencoders and Reinforcement Learning;\n", "\n", - "* Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++ and/or Fortran (Fortran2003 or later) or Julia or other.\n", - "\n", - "\n", - "\n", + "* Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++ and/or Fortran (Fortran2003 or later) or Julia or other." + ] + }, + { + "cell_type": "markdown", + "id": "638641fd", + "metadata": { + "editable": true + }, + "source": [ "## Topics covered in this course: Statistical analysis and optimization of data\n", "\n", "The course has two central parts\n", @@ -254,7 +324,6 @@ "\n", "**Statistical analysis and optimization of data.**\n", "\n", - "\n", "We plan to cover the following topics:\n", "* Basic concepts, expectation values, variance, covariance, correlation functions and errors;\n", "\n", @@ -268,11 +337,16 @@ "\n", "* Estimation of errors and resampling techniques such as the cross-validation, blocking, bootstrapping and jackknife methods;\n", "\n", - "* Principal Component Analysis (PCA) and its mathematical foundation\n", - "\n", - "\n", - "\n", - "\n", + "* Principal Component Analysis (PCA) and its mathematical foundation" + ] + }, + { + "cell_type": "markdown", + "id": "4d686486", + "metadata": { + "editable": true + }, + "source": [ "## Topics covered in this course: Machine Learning\n", "\n", "The following topics will be covered\n", @@ -290,25 +364,32 @@ "\n", "* Unsupervised learning Dimensionality reduction, from PCA to clustering\n", "\n", - "Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics.\n", - "\n", - "\n", - "\n", - "\n", + "Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics." + ] + }, + { + "cell_type": "markdown", + "id": "448b469d", + "metadata": { + "editable": true + }, + "source": [ "## Extremely useful tools, strongly recommended\n", "\n", "**and discussed at the lab sessions.**\n", "\n", " * GIT for version control, and GitHub or GitLab as repositories, highly recommended. This will be discussed during the first exercise session\n", "\n", - " * Anaconda and other Python environments, see intro slides and links to programming resources at \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + " * Anaconda and other Python environments, see intro slides and links to programming resources at " + ] + }, + { + "cell_type": "markdown", + "id": "6fa4bed1", + "metadata": { + "editable": true + }, + "source": [ "## Other courses on Data science and Machine Learning at UiO\n", "\n", "The link here gives an excellent overview of courses on Machine learning at UiO.\n", @@ -333,8 +414,16 @@ "\n", "10. [STK4051 Computational Statistics](https://www.uio.no/studier/emner/matnat/math/STK4051/index-eng.html)\n", "\n", - "11. [STK4021 Applied Bayesian Analysis and Numerical Methods](https://www.uio.no/studier/emner/matnat/math/STK4021/index-eng.html)\n", - "\n", + "11. [STK4021 Applied Bayesian Analysis and Numerical Methods](https://www.uio.no/studier/emner/matnat/math/STK4021/index-eng.html)" + ] + }, + { + "cell_type": "markdown", + "id": "f2061698", + "metadata": { + "editable": true + }, + "source": [ "## Introduction\n", "\n", "Our emphasis throughout this series of lectures \n", @@ -368,9 +457,16 @@ "Tensorflow (see below for links etc). Moreover, the examples we\n", "introduce will serve as inputs to many of our discussions later, as\n", "well as allowing you to set up models and produce your own data and\n", - "get started with programming.\n", - "\n", - "\n", + "get started with programming." + ] + }, + { + "cell_type": "markdown", + "id": "80ee1e31", + "metadata": { + "editable": true + }, + "source": [ "## What is Machine Learning?\n", "\n", "Statistics, data science and machine learning form important fields of\n", @@ -434,12 +530,18 @@ "solid command of linear algebra, multivariate theory, probability\n", "theory, statistical data analysis, understanding errors and Monte\n", "Carlo methods are central elements in a proper understanding of many\n", - "of algorithms and methods we will discuss.\n", - "\n", - "\n", + "of algorithms and methods we will discuss." + ] + }, + { + "cell_type": "markdown", + "id": "aaddb93e", + "metadata": { + "editable": true + }, + "source": [ "## Types of Machine Learning\n", "\n", - "\n", "The approaches to machine learning are many, but are often split into\n", "two main categories. In *supervised learning* we know the answer to a\n", "problem, and let the computer deduce the logic behind it. On the other\n", @@ -457,8 +559,16 @@ "\n", " * Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.\n", "\n", - " * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.\n", - "\n", + " * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning." + ] + }, + { + "cell_type": "markdown", + "id": "2260de85", + "metadata": { + "editable": true + }, + "source": [ "## Essential elements of ML\n", "\n", "The methods we cover have three main topics in common, irrespective of\n", @@ -467,16 +577,28 @@ "\n", "* The second item is a model which is normally a function of some parameters. The model reflects our knowledge of the system (or lack thereof). As an example, if we know that our data show a behavior similar to what would be predicted by a polynomial, fitting our data to a polynomial of some degree would then determin our model. \n", "\n", - "* The last ingredient is a so-called **cost/loss** function (or error or risk function) which allows us to present an estimate on how good our model is in reproducing the data it is supposed to train. \n", - "\n", - "\n", - "\n", - "\n", - "\n", + "* The last ingredient is a so-called **cost/loss** function (or error or risk function) which allows us to present an estimate on how good our model is in reproducing the data it is supposed to train." + ] + }, + { + "cell_type": "markdown", + "id": "f559e833", + "metadata": { + "editable": true + }, + "source": [ "## An optimization/minimization problem\n", "\n", - "At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called **gradient methods**.\n", - "\n", + "At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called **gradient methods**." + ] + }, + { + "cell_type": "markdown", + "id": "97d9dee8", + "metadata": { + "editable": true + }, + "source": [ "## A Frequentist approach to data analysis\n", "\n", "When you hear phrases like **predictions and estimations** and\n", @@ -502,9 +624,16 @@ "where the aim is to make predictions and find correlations. We focus\n", "less on for example extracting a probability distribution function (PDF). The PDF can be\n", "used in turn to make estimations and find causations such as given $A$\n", - "what is the likelihood of finding $B$.\n", - "\n", - "\n", + "what is the likelihood of finding $B$." + ] + }, + { + "cell_type": "markdown", + "id": "d3c059e8", + "metadata": { + "editable": true + }, + "source": [ "## What is a good model?\n", "\n", "In science and engineering we often end up in situations where we want to infer (or learn) a\n", @@ -525,12 +654,18 @@ "A first important consideration to keep in mind is that inferring the *correct* model\n", "for a given data set is an elusive, if not impossible, task. The fundamental difficulty\n", "is that if we are not specific about what we mean by a *correct* model, there\n", - "could easily be many different models that fit the given data set *equally well*.\n", - "\n", - "\n", + "could easily be many different models that fit the given data set *equally well*." + ] + }, + { + "cell_type": "markdown", + "id": "0bdeab16", + "metadata": { + "editable": true + }, + "source": [ "## What is a good model? Can we define it?\n", "\n", - "\n", "The central question is this: what leads us to say that a model is correct or\n", "optimal for a given data set? To make the model inference problem well posed, i.e.,\n", "to guarantee that there is a unique optimal model for the given data, we need to\n", @@ -550,15 +685,16 @@ "simpler models become inadequate. For instance, if we work with a regression problem to fit a set of sample points, one\n", "may first try the simplest class of models, namely linear models, followed obviously by more complex models.\n", "\n", - "How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures." + ] + }, + { + "cell_type": "markdown", + "id": "1c060598", + "metadata": { + "editable": true + }, + "source": [ "## Software and needed installations\n", "\n", "We will make extensive use of Python as programming language and its\n", @@ -569,7 +705,6 @@ "Rust, Julia, Fortran etc if you prefer. The focus in these lectures will be\n", "on Python.\n", "\n", - "\n", "If you have Python installed (we strongly recommend Python3) and you feel\n", "pretty familiar with installing different packages, we recommend that\n", "you install the following Python packages via **pip** as \n", @@ -589,9 +724,16 @@ "\n", "1. sudo apt-get install python3 (or python for pyhton2.7)\n", "\n", - "etc etc. \n", - "\n", - "\n", + "etc etc." + ] + }, + { + "cell_type": "markdown", + "id": "6cc9ab21", + "metadata": { + "editable": true + }, + "source": [ "## Python installers\n", "\n", "If you don't want to perform these operations separately and venture\n", @@ -615,8 +757,16 @@ "license.\n", "\n", "Furthermore, [Google's Colab](https://colab.research.google.com/notebooks/welcome.ipynb) is a free Jupyter notebook environment that requires \n", - "no setup and runs entirely in the cloud. Try it out!\n", - "\n", + "no setup and runs entirely in the cloud. Try it out!" + ] + }, + { + "cell_type": "markdown", + "id": "b4220192", + "metadata": { + "editable": true + }, + "source": [ "## Useful Python libraries\n", "Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)\n", "\n", @@ -640,8 +790,16 @@ "\n", "* [Keras](https://keras.io/) is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano\n", "\n", - "* And many more such as [pytorch](https://pytorch.org/), [Theano](https://pypi.org/project/Theano/) etc \n", - "\n", + "* And many more such as [pytorch](https://pytorch.org/), [Theano](https://pypi.org/project/Theano/) etc" + ] + }, + { + "cell_type": "markdown", + "id": "601d504c", + "metadata": { + "editable": true + }, + "source": [ "## Installing R, C++, cython or Julia\n", "\n", "You will also find it convenient to utilize **R**. We will mainly\n", @@ -656,13 +814,18 @@ "lectures.\n", "\n", "To install **R** with Jupyter notebook \n", - "[follow the link here](https://mpacer.org/maths/r-kernel-for-ipython-notebook)\n", - "\n", - "\n", - "\n", + "[follow the link here](https://mpacer.org/maths/r-kernel-for-ipython-notebook)" + ] + }, + { + "cell_type": "markdown", + "id": "a4beb747", + "metadata": { + "editable": true + }, + "source": [ "## Installing R, C++, cython, Numba etc\n", "\n", - "\n", "For the C++ aficionados, Jupyter/IPython notebook allows you also to\n", "install C++ and run codes written in this language interactively in\n", "the browser. Since we will emphasize writing many of the algorithms\n", @@ -683,22 +846,35 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "87030410", + "metadata": { + "editable": true + }, "source": [ " pycod jupyter nbconvert filename.ipynb --to latex \n" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "973375a2", + "metadata": { + "editable": true + }, "source": [ "And to add more versatility, the Python package [SymPy](http://www.sympy.org/en/index.html) is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. \n", "\n", "Finally, if you wish to use the light mark-up language \n", "[doconce](https://github.com/hplgit/doconce) you can convert a standard ascii text file into various HTML \n", - "formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using **doconce**.\n", - "\n", - "\n", + "formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using **doconce**." + ] + }, + { + "cell_type": "markdown", + "id": "bbd99efa", + "metadata": { + "editable": true + }, + "source": [ "## Numpy examples and Important Matrix and vector handling packages\n", "\n", "There are several central software libraries for linear algebra and eigenvalue problems. Several of the more\n", @@ -710,8 +886,16 @@ "\n", " * LAPACK:package for solving symmetric, unsymmetric and generalized eigenvalue problems. From LAPACK's website it is possible to download for free all source codes from this library. Both C/C++ and Fortran versions are available.\n", "\n", - " * BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from .\n", - "\n", + " * BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from ." + ] + }, + { + "cell_type": "markdown", + "id": "3b716073", + "metadata": { + "editable": true + }, + "source": [ "## Basic Matrix Features\n", "\n", "**Matrix properties reminder.**" @@ -719,7 +903,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "02ae660b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbf{A} =\n", @@ -739,14 +926,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "7950a446", + "metadata": { + "editable": true + }, "source": [ "The inverse of a matrix is defined by" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "1bd26546", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\mathbf{A}^{-1} \\cdot \\mathbf{A} = I\n", @@ -755,9 +948,12 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c9631af0", + "metadata": { + "editable": true + }, "source": [ - "\n", + "
    \n", "\n", "\n", "\n", @@ -768,10 +964,16 @@ "\n", "\n", "\n", - "
    Relations Name matrix elements
    $A=A^{\\dagger}$ hermitian $a_{ij}=a_{ji}^{*}$
    $A=\\left(A^{\\dagger}\\right )^{-1}$ unitary $\\sum_k a_{ik}a_{jk}^{*}=\\sum_k a_{ki}^{ * } a_{kj}=\\delta_{ij}$
    \n", - "\n", - "\n", - "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "a47420ee", + "metadata": { + "editable": true + }, + "source": [ "### Some famous Matrices\n", "\n", " * Diagonal if $a_{ij}=0$ for $i\\ne j$\n", @@ -790,8 +992,16 @@ "\n", " * Upper banded with bandwidth $p$: $a_{ij}=0$ for $i\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mscipy\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msparse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0meye\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meye\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meye\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'scipy'" - ] - } - ], + "id": "f10c8b39", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "%matplotlib inline\n", "\n", @@ -1367,15 +1537,18 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "646fca17", + "metadata": { + "editable": true + }, "source": [ "## Meet the Pandas\n", "\n", - "\n", "\n", "\n", - "

    Figure 1:

    \n", "\n", + "

    Figure 1:

    \n", + "\n", "\n", "Another useful Python package is\n", "[pandas](https://pandas.pydata.org/), which is an open source library\n", @@ -1390,80 +1563,12 @@ { "cell_type": "code", "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    First NameLast NamePlace of birthDate of Birth T.A.
    0FrodoBagginsShire2968
    1BilboBagginsShire2890
    2Aragorn IIElessarEriador2931
    3SamwiseGamgeeShire2980
    \n", - "
    " - ], - "text/plain": [ - " First Name Last Name Place of birth Date of Birth T.A.\n", - "0 Frodo Baggins Shire 2968\n", - "1 Bilbo Baggins Shire 2890\n", - "2 Aragorn II Elessar Eriador 2931\n", - "3 Samwise Gamgee Shire 2980" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "95d49d4c", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import pandas as pd\n", "from IPython.display import display\n", @@ -1478,7 +1583,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "38790248", + "metadata": { + "editable": true + }, "source": [ "In the above we have imported **pandas** with the shorthand **pd**, the latter has become the standard way we import **pandas**. We make then a list of various variables\n", "and reorganize the aboves lists into a **DataFrame** and then print out a neat table with specific column labels as *Name*, *place of birth* and *date of birth*.\n", @@ -1489,80 +1597,12 @@ { "cell_type": "code", "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    First NameLast NamePlace of birthDate of Birth T.A.
    FrodoFrodoBagginsShire2968
    BilboBilboBagginsShire2890
    AragornAragorn IIElessarEriador2931
    SamSamwiseGamgeeShire2980
    \n", - "
    " - ], - "text/plain": [ - " First Name Last Name Place of birth Date of Birth T.A.\n", - "Frodo Frodo Baggins Shire 2968\n", - "Bilbo Bilbo Baggins Shire 2890\n", - "Aragorn Aragorn II Elessar Eriador 2931\n", - "Sam Samwise Gamgee Shire 2980" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "e630cc31", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])\n", "display(data_pandas)" @@ -1570,7 +1610,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d0d27d68", + "metadata": { + "editable": true + }, "source": [ "Thereafter we display the content of the row which begins with the index **Aragorn**" ] @@ -1578,29 +1621,22 @@ { "cell_type": "code", "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "First Name Aragorn II\n", - "Last Name Elessar\n", - "Place of birth Eriador\n", - "Date of Birth T.A. 2931\n", - "Name: Aragorn, dtype: object" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "2591ed5d", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "display(data_pandas.loc['Aragorn'])" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "85bf5f70", + "metadata": { + "editable": true + }, "source": [ "We can easily append data to this, for example" ] @@ -1608,88 +1644,12 @@ { "cell_type": "code", "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    First NameLast NamePlace of birthDate of Birth T.A.
    FrodoFrodoBagginsShire2968
    BilboBilboBagginsShire2890
    AragornAragorn IIElessarEriador2931
    SamSamwiseGamgeeShire2980
    PippinPeregrinTookShire2990
    \n", - "
    " - ], - "text/plain": [ - " First Name Last Name Place of birth Date of Birth T.A.\n", - "Frodo Frodo Baggins Shire 2968\n", - "Bilbo Bilbo Baggins Shire 2890\n", - "Aragorn Aragorn II Elessar Eriador 2931\n", - "Sam Samwise Gamgee Shire 2980\n", - "Pippin Peregrin Took Shire 2990" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "9bbe0db8", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "new_hobbit = {'First Name': [\"Peregrin\"],\n", " 'Last Name': [\"Took\"],\n", @@ -1702,7 +1662,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d9ebb24b", + "metadata": { + "editable": true + }, "source": [ "Here are other examples where we use the **DataFrame** functionality to handle arrays, now with more interesting features for us, namely numbers. We set up a matrix \n", "of dimensionality $10\\times 5$ and compute the mean value and standard deviation of each column. Similarly, we can perform mathematial operations like squaring the matrix elements and many other operations." @@ -1711,287 +1674,12 @@ { "cell_type": "code", "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    01234
    0-1.7497650.3426801.153036-0.2524360.981321
    10.5142190.221180-1.070043-0.1894960.255001
    2-0.4580270.435163-0.5835950.8168470.672721
    3-0.104411-0.5312801.029733-0.438136-1.118318
    41.6189821.541605-0.251879-0.8424360.184519
    50.9370820.7310001.361556-0.3262380.055676
    60.222400-1.443217-0.7563520.8164540.750445
    7-0.4559471.189622-1.690617-1.356399-1.232435
    8-0.544439-0.6681720.007315-0.6129391.299748
    9-1.733096-0.9833100.357508-1.6135791.470714
    \n", - "
    " - ], - "text/plain": [ - " 0 1 2 3 4\n", - "0 -1.749765 0.342680 1.153036 -0.252436 0.981321\n", - "1 0.514219 0.221180 -1.070043 -0.189496 0.255001\n", - "2 -0.458027 0.435163 -0.583595 0.816847 0.672721\n", - "3 -0.104411 -0.531280 1.029733 -0.438136 -1.118318\n", - "4 1.618982 1.541605 -0.251879 -0.842436 0.184519\n", - "5 0.937082 0.731000 1.361556 -0.326238 0.055676\n", - "6 0.222400 -1.443217 -0.756352 0.816454 0.750445\n", - "7 -0.455947 1.189622 -1.690617 -1.356399 -1.232435\n", - "8 -0.544439 -0.668172 0.007315 -0.612939 1.299748\n", - "9 -1.733096 -0.983310 0.357508 -1.613579 1.470714" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0 -0.175300\n", - "1 0.083527\n", - "2 -0.044334\n", - "3 -0.399836\n", - "4 0.331939\n", - "dtype: float64\n", - "0 1.069584\n", - "1 0.965548\n", - "2 1.018232\n", - "3 0.793167\n", - "4 0.918992\n", - "dtype: float64\n" - ] - }, - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    01234
    03.0616790.1174301.3294920.0637240.962990
    10.2644210.0489201.1449930.0359090.065026
    20.2097890.1893670.3405830.6672390.452553
    30.0109020.2822591.0603490.1919631.250636
    42.6211022.3765470.0634430.7096980.034047
    50.8781230.5343621.8538350.1064310.003100
    60.0494622.0828750.5720690.6665970.563167
    70.2078881.4152012.8581851.8398181.518895
    80.2964140.4464530.0000540.3756941.689345
    93.0036200.9668990.1278122.6036362.162999
    \n", - "
    " - ], - "text/plain": [ - " 0 1 2 3 4\n", - "0 3.061679 0.117430 1.329492 0.063724 0.962990\n", - "1 0.264421 0.048920 1.144993 0.035909 0.065026\n", - "2 0.209789 0.189367 0.340583 0.667239 0.452553\n", - "3 0.010902 0.282259 1.060349 0.191963 1.250636\n", - "4 2.621102 2.376547 0.063443 0.709698 0.034047\n", - "5 0.878123 0.534362 1.853835 0.106431 0.003100\n", - "6 0.049462 2.082875 0.572069 0.666597 0.563167\n", - "7 0.207888 1.415201 2.858185 1.839818 1.518895\n", - "8 0.296414 0.446453 0.000054 0.375694 1.689345\n", - "9 3.003620 0.966899 0.127812 2.603636 2.162999" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "f5f4acfb", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", @@ -2010,7 +1698,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0b4ef9f6", + "metadata": { + "editable": true + }, "source": [ "Thereafter we can select specific columns only and plot final results" ] @@ -2018,188 +1709,12 @@ { "cell_type": "code", "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
    \n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
    FirstSecondThirdFourthFifth
    0-1.7497650.3426801.153036-0.2524360.981321
    10.5142190.221180-1.070043-0.1894960.255001
    2-0.4580270.435163-0.5835950.8168470.672721
    3-0.104411-0.5312801.029733-0.438136-1.118318
    41.6189821.541605-0.251879-0.8424360.184519
    50.9370820.7310001.361556-0.3262380.055676
    60.222400-1.443217-0.7563520.8164540.750445
    7-0.4559471.189622-1.690617-1.356399-1.232435
    8-0.544439-0.6681720.007315-0.6129391.299748
    9-1.733096-0.9833100.357508-1.6135791.470714
    \n", - "
    " - ], - "text/plain": [ - " First Second Third Fourth Fifth\n", - "0 -1.749765 0.342680 1.153036 -0.252436 0.981321\n", - "1 0.514219 0.221180 -1.070043 -0.189496 0.255001\n", - "2 -0.458027 0.435163 -0.583595 0.816847 0.672721\n", - "3 -0.104411 -0.531280 1.029733 -0.438136 -1.118318\n", - "4 1.618982 1.541605 -0.251879 -0.842436 0.184519\n", - "5 0.937082 0.731000 1.361556 -0.326238 0.055676\n", - "6 0.222400 -1.443217 -0.756352 0.816454 0.750445\n", - "7 -0.455947 1.189622 -1.690617 -1.356399 -1.232435\n", - "8 -0.544439 -0.668172 0.007315 -0.612939 1.299748\n", - "9 -1.733096 -0.983310 0.357508 -1.613579 1.470714" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.08352721390288316\n", - "\n", - "Int64Index: 10 entries, 0 to 9\n", - "Data columns (total 5 columns):\n", - " # Column Non-Null Count Dtype \n", - "--- ------ -------------- ----- \n", - " 0 First 10 non-null float64\n", - " 1 Second 10 non-null float64\n", - " 2 Third 10 non-null float64\n", - " 3 Fourth 10 non-null float64\n", - " 4 Fifth 10 non-null float64\n", - "dtypes: float64(5)\n", - "memory usage: 480.0 bytes\n", - "None\n", - " First Second Third Fourth Fifth\n", - "count 10.000000 10.000000 10.000000 10.000000 10.000000\n", - "mean -0.175300 0.083527 -0.044334 -0.399836 0.331939\n", - "std 1.069584 0.965548 1.018232 0.793167 0.918992\n", - "min -1.749765 -1.443217 -1.690617 -1.613579 -1.232435\n", - "25% -0.522836 -0.633949 -0.713163 -0.785061 0.087887\n", - "50% -0.280179 0.281930 -0.122282 -0.382187 0.463861\n", - "75% 0.441264 0.657041 0.861676 -0.205231 0.923602\n", - "max 1.618982 1.541605 1.361556 0.816847 1.470714\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlIAAAFkCAYAAADrFNVeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAACqXklEQVR4nOyddXhc17W330GxNIIRM9iyzBQz23HiJA6THeakaZu0Kffe3q+3t5yGsQ2zQw44ie2YmS2jbDFLMyOc0fCc8/0xsmzHJBiUz/s8fmSNzpyzRkt7n99Ze+21ZKIoikhISEhISEhISPQZub8NkJCQkJCQkJAIViQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRT5T+uKheb/T6NWJjw2lrM3v9OhLeQ/Jh8CP5MPiRfBjcSP7zDFpt1Dl/NmgjUkqlwt8mSAwQyYfBj+TD4EfyYXAj+c/7DFohJSEhISEhISHhbSQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRTyQhJSEhISEhISHRT/xSkDNQOXLkEC+++CxOp5OJEycBYLfbsdvtHDiwn1dffROFovc1Ob755itmzJhNVNS5C3lJSEhISEhIBC+SkDqFoqIRjB07HovFwr33PgiAzWZj9+6d/OQnP0Mmk/XpfN988xVjx46XhJSEhISEhMQgJSCF1NMfF3OgvMWj5xyVF89jN47u03ucTicvv/w848dP4MYbF/Pcc6/Q0mLgn//8K0OHFqJSqVm/fg3vvPMRL7zwDLm5+dTWVnPZZVdis1lpampk2bIPyMrK4pprbvDo55GQkJCQkJDwPwEppPzN3r27eeaZJxFFEZlMxvTps/jww/cAGDFiFDNmzMJms/LIIz/lmm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/zCAlIZf/r9ftdkOr1QpUDXnj3XffRUlJCRobG2G1WoUuh+aopqYGHo8Hf/jDHzA5OYmwsDA8/PDDQpdFc6DVaqFSqTAxMYGQkBBYrVakp6cLXZZf8rsgNTQ0hKCgoJnfBwcHY2hoSMCKaD6OHDmCdevWITU1VehSaJZaWlpw7tw5fOc730FjY6PQ5ZAXent7UVVVhZ///OfQ6XT47ne/C5VKhQceeEDo0miWgoOD8b3vfQ/PPvssoqKiEBMTg6SkJKHL8kt+t9g8IiICFotl5vcTExOIiIgQsCLy1smTJ/HZZ5/h+eefF7oUmoMjR45ArVbj1VdfxenTp1FdXY3XX39d6LJoDoKCgrB8+XLodDoAwIoVK3Dq1CmBq6K5qK+vx2uvvYZXXnkFL730EvR6Pf77v/9b6LL8kt+NSBUVFaG3txdTU1NQq9WoqKjAY489JnRZNEcff/wxysvL8S//8i8YGBhAb28viouLhS6LZuHpp5+eed9ut8NqteKJJ54QriCas8LCQoyOjsLlckGhUKC3txfJyclCl0Vz0N/fj7CwsJm1bVFRUTAajQJX5Z/88tDiY8eO4dChQ9Dr9VCpVLzjS2Jqa2vxla98ZWZxudVqxbZt2zitIDGHDh3C7t274XA4sG3bNmzevFnokmgOjhw5gpMnT0Kv18NoNGLnzp2840tCXC4XfvKTn0Cj0UCn06G5uRnPP/88DAaD0KX5Hb8MUkRERESLwe/WSBEREREtFgYpIiIiIi8xSBERERF5iUGKiIiIyEsMUkREREReYpAiIiIi8hKDFBEREZGXGKSIiIiIvPT/AYYRgDOUasVWAAAAAElFTkSuQmCC\n", - "text/plain": [ - "
    " - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAAFlCAYAAADcXS0xAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAApcUlEQVR4nO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eeyouLvZ0WW6zevVqHTlyRD179tSBAwe0cuVKff/99x6tqd6Hrbffflvt2rVT27ZtNWTIEP3rX//Szp07PV2WW5w4cUJDhw7Vbbfdpm+++UaS55dS3WnYsGG69957lZCQoI4dOyojI8PTJbnVkCFDNGDAALVv317NmzeX3W6Xr6/3v2QvPwfT0tLUvXt3+fj46NixY5JkqTA5ZMgQ9enTR4WFhfrnP/+pzMxMT5fkVu+9954qKip07Ngxbd261VL9hYWFad68efqP//gP9evXTxUVFcrOzvZ0WW6zadMmtW7dWu3bt1ebNm0kSYGBgZb4+2C32/Xll18qISFBbdu21d13361du3bpu+++82hd3v/O7YKysjJ16NBBhw4dkiTFxcUpJCREe/fu9XBl7hEfH69OnTopOjpaX375pSTrhK1bbrlFd955pwICAiRJLVu2VGxsrIercq+hQ4eqcePG+tvf/qb9+/erbdu2stvtni7LZT4+Pjp48KAiIiI0fPhw+fj4aO/evcrJybFEmLysadOmSk1NVUREhMrLyzVz5kwdPnzY02W5RXl5uaKiorRp0yY1bdpUMTExWrlypdavX+/p0twiICBAt956qySpoKBAYWFhio6O9nBV7jN48GBt2rRJy5Yt07Fjx1ReXq7s7GxLfPpRUlKitm3batu2bZKkZs2aKSsrSwcPHvRoXdZ5Z7sBPj4+atasmeN/ZGFhYWrcuLHjD7i38/X11U033aROnTpp//79jjEruPJNISMjQ0ePHtWwYcNUUFDgwarcr7y8XDExMZo8ebI2b96sJUuWeLokt7hw4YIyMzOVnp6uY8eOadOmTUpLS/N0WW7Vr18/jR07VvHx8brnnnuUkJCgv/3tb54uyy0uv/4yMjIUGxurfv36qWfPnvryyy8t8x+6y3x9fbV9+3Z17tzZ06W4zahRo9S2bVs1adJEY8aM0YULFzR//nxLPHZBQUG65557tGfPHn366afau3evevXqpaCgII/WZY2/vDfI19dXPXv21MGDB3Xx4kUFBATo5MmTjmVVK/D19dWtt96qsrIy5ebmerocI/bt26cxY8YoPz9fqampKikp8XRJbmO325WQkKCEhAR1795dJSUllvjVV2Zmppo1a6bw8HAlJSUpJiZGsbGxlnizvywwMFCBgYGSJH9/fxUVFSkiIsLDVbmHj4+P+vTpo8DAQNlsNvn6+qqkpETt2rVTaWmpp8tzq4CAADVt2lQ5OTmeLsVtsrOz9f777+vBBx9U27Zt1aFDB0VGRlrmP6t9+vTRrFmzdMstt2jkyJHy8/NTfHy8R2uq979GvO2225SYmKiVK1cqNDRUwcHBat26tafLcqvS0lLl5eVpypQpmjhxojp16uTpktxm8+bNWrFihf7xj3/o8OHDuvPOO1VaWqqbbrrJ06W5LD8/X5s2bVJRUZGCg4O1c+dODR482OO/qnGHESNGOFZHPv30U+3Zs0ebNm1SeHi4mjRp4uHq3KOgoEDvv/++ysrKFBoaquLiYku99rp166bOnTtr+fLluuWWW5SZmakhQ4ZY4rV3pc8++0wxMTGKiIiwzC+6b775ZnXt2lWvv/66YmJitHPnTt17772W+kViVlaWjhw5olOnTikqKkoxMTEercenwkr/lbxBdrtdGRkZKisrU8eOHeXn52eZF5Xdbtfnn3+u06dPq2vXrkpMTLREX5ctX75cWVlZevjhh5WQkGC5N/rNmzfr9OnT6tevn2JiYiwRtK5ks9mUnZ2tmJgY+ftb7/9+X3zxhbKysnT77berVatWlnv8CgoKlJGRoYCAAMXFxVnqvfOyzMxMVVRUqG3btp4uxa0yMzP17bff6tZbb1WbNm0s99z88ssvtXPnTg0YMEBt2rTx+FdoCFsAAAAG1evvbAEAAJhG2AIAADCIsAUAAGAQYQsAAMAgwhYAAIBBhC0AAACDCFsAAAAG/X8idFJ0xKGYiQAAAABJRU5ErkJggg==\n", - "text/plain": [ - "
    " - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "id": "f70279c1", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']\n", "df.index = np.arange(10)\n", @@ -2223,7 +1738,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "963e3f64", + "metadata": { + "editable": true + }, "source": [ "We can produce a $4\\times 4$ matrix" ] @@ -2231,24 +1749,12 @@ { "cell_type": "code", "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[ 0 1 2 3]\n", - " [ 4 5 6 7]\n", - " [ 8 9 10 11]\n", - " [12 13 14 15]]\n", - " 0 1 2 3\n", - "0 0 1 2 3\n", - "1 4 5 6 7\n", - "2 8 9 10 11\n", - "3 12 13 14 15\n" - ] - } - ], + "id": "8f579fb1", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "b = np.arange(16).reshape((4,4))\n", "print(b)\n", @@ -2258,7 +1764,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "970a7544", + "metadata": { + "editable": true + }, "source": [ "and many other operations. \n", "\n", @@ -2267,21 +1776,30 @@ "we have just a single column of data. It shares many of the same features as _DataFrame. As with **DataFrame**,\n", "most operations are vectorized, achieving thereby a high performance when dealing with computations of arrays, in particular labeled arrays.\n", "As we will see below it leads also to a very concice code close to the mathematical operations we may be interested in.\n", - "For multidimensional arrays, we recommend strongly [xarray](http://xarray.pydata.org/en/stable/). **xarray** has much of the same flexibility as **pandas**, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both **pandas** and **xarray**. \n", - "\n", - "\n", + "For multidimensional arrays, we recommend strongly [xarray](http://xarray.pydata.org/en/stable/). **xarray** has much of the same flexibility as **pandas**, but allows for the extension to higher dimensions than two. We will see examples later of the usage of both **pandas** and **xarray**." + ] + }, + { + "cell_type": "markdown", + "id": "691ca1d1", + "metadata": { + "editable": true + }, + "source": [ "## Friday August 27\n", "\n", - "\n", "\"Video of Lecture August 27, 2021\":\"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust27.mp4?vrtx=view-as-webpage\n", "\n", - "\n", - "\n", - "[Video of Lecture from fall 2020](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/LectureAug21.mp4?vrtx=view-as-webpage) and [Handwritten notes](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesAugust21.pdf)\n", - "\n", - "\n", - "\n", - "\n", + "[Video of Lecture from fall 2020](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/LectureAug21.mp4?vrtx=view-as-webpage) and [Handwritten notes](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesAugust21.pdf)" + ] + }, + { + "cell_type": "markdown", + "id": "d378c442", + "metadata": { + "editable": true + }, + "source": [ "### Simple linear regression model using **scikit-learn**\n", "\n", "We start with perhaps our simplest possible example, using **Scikit-Learn** to perform linear regression analysis on a data set produced by us. \n", @@ -2295,7 +1813,6 @@ "(tabulated again as a vector) with a linear dependence on $x$ plus a\n", "random noise added via the normal distribution.\n", "\n", - "\n", "The Numpy functions are imported used the **import numpy as np**\n", "statement and the random number generator for the uniform distribution\n", "is called using the function **np.random.rand()**, where we specificy\n", @@ -2309,7 +1826,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e5ab3567", + "metadata": { + "editable": true + }, "source": [ "$$\n", "y = 2x+N(0,1),\n", @@ -2318,7 +1838,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "48638276", + "metadata": { + "editable": true + }, "source": [ "where $N(0,1)$ represents random numbers generated by the normal\n", "distribution. From **Scikit-Learn** we import then the\n", @@ -2343,20 +1866,12 @@ { "cell_type": "code", "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "ename": "ModuleNotFoundError", - "evalue": "No module named 'sklearn'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12115/2268754013.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinear_model\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mLinearRegression\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'sklearn'" - ] - } - ], + "id": "5d268e23", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "# Importing various packages\n", "import numpy as np\n", @@ -2381,7 +1896,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a0bc9fe7", + "metadata": { + "editable": true + }, "source": [ "This example serves several aims. It allows us to demonstrate several\n", "aspects of data analysis and later machine learning algorithms. The\n", @@ -2395,7 +1913,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "2fa1f5fd", + "metadata": { + "editable": true + }, "source": [ "$$\n", "y = 10x+0.01 \\times N(0,1),\n", @@ -2404,7 +1925,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "69c2a007", + "metadata": { + "editable": true + }, "source": [ "where $x$ is defined as before. Does the fit look better? Indeed, by\n", "reducing the role of the noise given by the normal distribution we see immediately that\n", @@ -2422,7 +1946,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c946d217", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\chi^2 = \\frac{1}{n}\n", @@ -2432,7 +1959,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "88362352", + "metadata": { + "editable": true + }, "source": [ "where $\\sigma_i^2$ is the variance (to be defined later) of the entry\n", "$y_i$. We may not know the explicit value of $\\sigma_i^2$, it serves\n", @@ -2460,7 +1990,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "cf70f181", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\epsilon_{\\mathrm{relative}}= \\frac{\\vert \\boldsymbol{y} -\\boldsymbol{\\tilde{y}}\\vert}{\\vert \\boldsymbol{y}\\vert}.\n", @@ -2469,7 +2002,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "45b3e51a", + "metadata": { + "editable": true + }, "source": [ "The squared cost function results in an arithmetic mean-unbiased\n", "estimator, and the absolute-value cost function results in a\n", @@ -2483,8 +2019,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 25, + "id": "acbb097e", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np\n", @@ -2507,7 +2047,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "906ec623", + "metadata": { + "editable": true + }, "source": [ "Depending on the parameter in front of the normal distribution, we may\n", "have a small or larger relative error. Try to play around with\n", @@ -2525,8 +2068,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 26, + "id": "ae576654", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np \n", @@ -2560,7 +2107,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4fa873c4", + "metadata": { + "editable": true + }, "source": [ "The function **coef** gives us the parameter $\\beta$ of our fit while **intercept** yields \n", "$\\alpha$. Depending on the constant in front of the normal distribution, we get values near or far from $\\alpha =2$ and $\\beta =5$. Try to play around with different parameters in front of the normal distribution. The function **meansquarederror** gives us the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error or loss defined as" @@ -2568,7 +2118,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "28e7c10c", + "metadata": { + "editable": true + }, "source": [ "$$\n", "MSE(\\boldsymbol{y},\\boldsymbol{\\tilde{y}}) = \\frac{1}{n}\n", @@ -2578,7 +2131,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f7dc1729", + "metadata": { + "editable": true + }, "source": [ "The smaller the value, the better the fit. Ideally we would like to\n", "have an MSE equal zero. The attentive reader has probably recognized\n", @@ -2596,7 +2152,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "8a05b954", + "metadata": { + "editable": true + }, "source": [ "$$\n", "R^2(\\boldsymbol{y}, \\tilde{\\boldsymbol{y}}) = 1 - \\frac{\\sum_{i=0}^{n - 1} (y_i - \\tilde{y}_i)^2}{\\sum_{i=0}^{n - 1} (y_i - \\bar{y})^2},\n", @@ -2605,14 +2164,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e580bea2", + "metadata": { + "editable": true + }, "source": [ "where we have defined the mean value of $\\boldsymbol{y}$ as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "0c51facd", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\bar{y} = \\frac{1}{n} \\sum_{i=0}^{n - 1} y_i.\n", @@ -2621,7 +2186,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "62a0f4f7", + "metadata": { + "editable": true + }, "source": [ "Another quantity taht we will meet again in our discussions of regression analysis is \n", " the mean absolute error (MAE), a risk metric corresponding to the expected value of the absolute error loss or what we call the $l1$-norm loss. In our discussion above we presented the relative error.\n", @@ -2630,7 +2198,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f785e614", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\text{MAE}(\\boldsymbol{y}, \\boldsymbol{\\tilde{y}}) = \\frac{1}{n} \\sum_{i=0}^{n-1} \\left| y_i - \\tilde{y}_i \\right|.\n", @@ -2639,7 +2210,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bf583443", + "metadata": { + "editable": true + }, "source": [ "We present the \n", "squared logarithmic (quadratic) error" @@ -2647,7 +2221,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "724378dc", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\text{MSLE}(\\boldsymbol{y}, \\boldsymbol{\\tilde{y}}) = \\frac{1}{n} \\sum_{i=0}^{n - 1} (\\log_e (1 + y_i) - \\log_e (1 + \\tilde{y}_i) )^2,\n", @@ -2656,14 +2233,16 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0f2058ae", + "metadata": { + "editable": true + }, "source": [ "where $\\log_e (x)$ stands for the natural logarithm of $x$. This error\n", "estimate is best to use when targets having exponential growth, such\n", "as population counts, average sales of a commodity over a span of\n", "years etc. \n", "\n", - "\n", "Finally, another cost function is the Huber cost function used in robust regression.\n", "\n", "The rationale behind this possible cost function is its reduced\n", @@ -2676,7 +2255,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e7caa601", + "metadata": { + "editable": true + }, "source": [ "$$\n", "H_{\\delta}(\\boldsymbol{a})=\\left\\{\\begin{array}{cc}\\frac{1}{2} \\boldsymbol{a}^{2}& \\text{for }|\\boldsymbol{a}|\\leq \\delta\\\\ \\delta (|\\boldsymbol{a}|-\\frac{1}{2}\\delta ),&\\text{otherwise}.\\end{array}\\right.\n", @@ -2685,11 +2267,13 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0fe54ee3", + "metadata": { + "editable": true + }, "source": [ "Here $\\boldsymbol{a}=\\boldsymbol{y} - \\boldsymbol{\\tilde{y}}$.\n", "\n", - "\n", "We will discuss in more detail these and other functions in the\n", "various lectures. We conclude this part with another example. Instead\n", "of a linear $x$-dependence we study now a cubic polynomial and use the\n", @@ -2698,8 +2282,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 27, + "id": "07b7f404", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -2736,7 +2324,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "2a3e7169", + "metadata": { + "editable": true + }, "source": [ "### To our real data: nuclear binding energies. Brief reminder on masses and binding energies\n", "\n", @@ -2750,7 +2341,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ffb61b21", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\Delta M(N, Z) = M(N, Z) - uA,\n", @@ -2759,14 +2353,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "dae62975", + "metadata": { + "editable": true + }, "source": [ "where $u$ is the Atomic Mass Unit" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "47c55cae", + "metadata": { + "editable": true + }, "source": [ "$$\n", "u = M(^{12}\\mathrm{C})/12 = 931.4940954(57) \\hspace{0.1cm} \\mathrm{MeV}/c^2.\n", @@ -2775,14 +2375,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ba0c4ef5", + "metadata": { + "editable": true + }, "source": [ "The nucleon masses are" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "d44a78b4", + "metadata": { + "editable": true + }, "source": [ "$$\n", "m_p = 1.00727646693(9)u,\n", @@ -2791,14 +2397,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e478b442", + "metadata": { + "editable": true + }, "source": [ "and" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "bc08de2b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "m_n = 939.56536(8)\\hspace{0.1cm} \\mathrm{MeV}/c^2 = 1.0086649156(6)u.\n", @@ -2807,7 +2419,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e5e9dae9", + "metadata": { + "editable": true + }, "source": [ "In the [2016 mass evaluation of by W.J.Huang, G.Audi, M.Wang, F.G.Kondev, S.Naimi and X.Xu](http://nuclearmasses.org/resources_folder/Wang_2017_Chinese_Phys_C_41_030003.pdf)\n", "there are data on masses and decays of 3437 nuclei.\n", @@ -2820,7 +2435,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "55a50874", + "metadata": { + "editable": true + }, "source": [ "$$\n", "BE(N, Z) = ZM_H c^2 + Nm_n c^2 - M(N, Z)c^2 ,\n", @@ -2829,7 +2447,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0722bdc3", + "metadata": { + "editable": true + }, "source": [ "where $M_H$ is the mass of the hydrogen atom and $m_n$ is the mass of the neutron.\n", "In terms of the mass excess the binding energy is given by" @@ -2837,7 +2458,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "1ad2c13d", + "metadata": { + "editable": true + }, "source": [ "$$\n", "BE(N, Z) = Z\\Delta_H c^2 + N\\Delta_n c^2 -\\Delta(N, Z)c^2 ,\n", @@ -2846,11 +2470,13 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b55ccbf6", + "metadata": { + "editable": true + }, "source": [ "where $\\Delta_H c^2 = 7.2890$ MeV and $\\Delta_n c^2 = 8.0713$ MeV.\n", "\n", - "\n", "A popular and physically intuitive model which can be used to parametrize \n", "the experimental binding energies as function of $A$, is the so-called \n", "**liquid drop model**. The ansatz is based on the following expression" @@ -2858,7 +2484,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e9bc1ac6", + "metadata": { + "editable": true + }, "source": [ "$$\n", "BE(N,Z) = a_1A-a_2A^{2/3}-a_3\\frac{Z^2}{A^{1/3}}-a_4\\frac{(N-Z)^2}{A},\n", @@ -2867,14 +2496,14 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "47174561", + "metadata": { + "editable": true + }, "source": [ "where $A$ stands for the number of nucleons and the $a_i$s are parameters which are determined by a fit \n", "to the experimental data. \n", "\n", - "\n", - "\n", - "\n", "To arrive at the above expression we have assumed that we can make the following assumptions:\n", "\n", " * There is a volume term $a_1A$ proportional with the number of nucleons (the energy is also an extensive quantity). When an assembly of nucleons of the same size is packed together into the smallest volume, each interior nucleon has a certain number of other nucleons in contact with it. This contribution is proportional to the volume.\n", @@ -2887,23 +2516,33 @@ "\n", "We could also add a so-called pairing term, which is a correction term that\n", "arises from the tendency of proton pairs and neutron pairs to\n", - "occur. An even number of particles is more stable than an odd number. \n", - "\n", - "\n", + "occur. An even number of particles is more stable than an odd number." + ] + }, + { + "cell_type": "markdown", + "id": "3a54d55d", + "metadata": { + "editable": true + }, + "source": [ "### Organizing our data\n", "\n", "Let us start with reading and organizing our data. \n", "We start with the compilation of masses and binding energies from 2016.\n", "After having downloaded this file to our own computer, we are now ready to read the file and start structuring our data.\n", "\n", - "\n", "We start with preparing folders for storing our calculations and the data file over masses and binding energies. We import also various modules that we will find useful in order to present various Machine Learning methods. Here we focus mainly on the functionality of **scikit-learn**." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 28, + "id": "6a858ae6", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Common imports\n", @@ -2943,15 +2582,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "37694bf4", + "metadata": { + "editable": true + }, "source": [ "Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various **matplotlib** commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 29, + "id": "0d909cb1", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "from pylab import plt, mpl\n", @@ -2969,7 +2615,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "476a0da3", + "metadata": { + "editable": true + }, "source": [ "Our next step is to read the data on experimental binding energies and\n", "reorganize them as functions of the mass number $A$, the number of\n", @@ -2977,14 +2626,17 @@ "always useful (unless you have a binary file or other types of compressed\n", "data) to actually open the file and simply take a look at it!\n", "\n", - "\n", "In particular, the program that outputs the final nuclear masses is written in Fortran with a specific format. It means that we need to figure out the format and which columns contain the data we are interested in. Pandas comes with a function that reads formatted output. After having admired the file, we are now ready to start massaging it with **pandas**. The file begins with some basic format information." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 30, + "id": "808a944d", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "\"\"\" \n", @@ -3001,7 +2653,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f13998e8", + "metadata": { + "editable": true + }, "source": [ "The data we are interested in are in columns 2, 3, 4 and 11, giving us\n", "the number of neutrons, protons, mass numbers and binding energies,\n", @@ -3011,8 +2666,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 31, + "id": "87734ea5", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Read the experimental data with Pandas\n", @@ -3037,7 +2696,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c5cd7bf2", + "metadata": { + "editable": true + }, "source": [ "We have now read in the data, grouped them according to the variables we are interested in. \n", "We see how easy it is to reorganize the data using **pandas**. If we\n", @@ -3053,8 +2715,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 32, + "id": "135551a3", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "A = Masses['A']\n", @@ -3067,7 +2733,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "9f4a6509", + "metadata": { + "editable": true + }, "source": [ "The next step, and we will define this mathematically later, is to set up the so-called **design matrix**. We will throughout call this matrix $\\boldsymbol{X}$.\n", "It has dimensionality $p\\times n$, where $n$ is the number of data points and $p$ are the so-called predictors. In our case here they are given by the number of polynomials in $A$ we wish to include in the fit." @@ -3075,8 +2744,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 33, + "id": "02c2d4c3", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Now we set up the design matrix X\n", @@ -3090,15 +2763,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "10be1594", + "metadata": { + "editable": true + }, "source": [ "With **scikitlearn** we are now ready to use linear regression and fit our data." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 34, + "id": "65a53863", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "clf = skl.LinearRegression().fit(X, Energies)\n", @@ -3107,7 +2787,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "86f51dcf", + "metadata": { + "editable": true + }, "source": [ "Pretty simple! \n", "Now we can print measures of how our fit is doing, the coefficients from the fits and plot the final fit together with our data." @@ -3115,8 +2798,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 35, + "id": "b13eba7f", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# The mean squared error \n", @@ -3143,7 +2830,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "279b2fb0", + "metadata": { + "editable": true + }, "source": [ "### Seeing the wood for the trees\n", "\n", @@ -3152,8 +2842,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 36, + "id": "84d1e91b", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "\n", @@ -3190,7 +2884,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "8bead0b5", + "metadata": { + "editable": true + }, "source": [ "### And what about using neural networks?\n", "\n", @@ -3200,8 +2897,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 37, + "id": "96646081", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "from sklearn.neural_network import MLPRegressor\n", @@ -3237,7 +2938,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "93ebbcd3", + "metadata": { + "editable": true + }, "source": [ "## A first summary\n", "\n", @@ -3249,9 +2953,16 @@ "Furthermore,\n", "**Scikit-Learn** allows us with few lines of code to implement popular\n", "Machine Learning algorithms for supervised learning. Later we will meet **Tensorflow**, a powerful library for deep learning. \n", - "Now it is time to dive more into the details of various methods. We will start with linear regression and try to take a deeper look at what it entails.\n", - "\n", - "\n", + "Now it is time to dive more into the details of various methods. We will start with linear regression and try to take a deeper look at what it entails." + ] + }, + { + "cell_type": "markdown", + "id": "129b1e89", + "metadata": { + "editable": true + }, + "source": [ "## Why Linear Regression (aka Ordinary Least Squares and family)\n", "\n", "Fitting a continuous function with linear parameterization in terms of the parameters $\\boldsymbol{\\beta}$.\n", @@ -3274,9 +2985,16 @@ "* and many more features\n", "\n", "For more discussions of Ridge and Lasso regression, [Wessel van Wieringen's](https://arxiv.org/abs/1509.09169) article is highly recommended.\n", - "Similarly, [Mehta et al's article](https://arxiv.org/abs/1803.08823) is also recommended.\n", - "\n", - "\n", + "Similarly, [Mehta et al's article](https://arxiv.org/abs/1803.08823) is also recommended." + ] + }, + { + "cell_type": "markdown", + "id": "465172ea", + "metadata": { + "editable": true + }, + "source": [ "## Regression analysis, overarching aims\n", "\n", "Regression modeling deals with the description of the sampling distribution of a given random variable $y$ and how it varies as function of another variable or a set of such variables $\\boldsymbol{x} =[x_0, x_1,\\dots, x_{n-1}]^T$. \n", @@ -3289,13 +3007,18 @@ "\n", "* $p$ so-called explanatory (independent or predictor) variables $\\boldsymbol{x}_i=[x_{i0}, x_{i1}, \\dots, x_{ip-1}]$ with $i = 0, 1, 2, \\dots, n-1$ and explanatory variables running from $0$ to $p-1$. See below for more explicit examples. \n", "\n", - " The goal of the regression analysis is to extract/exploit relationship between $\\boldsymbol{y}$ and $\\boldsymbol{x}$ in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.\n", - "\n", - "\n", - "\n", + " The goal of the regression analysis is to extract/exploit relationship between $\\boldsymbol{y}$ and $\\boldsymbol{x}$ in or to infer causal dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things." + ] + }, + { + "cell_type": "markdown", + "id": "b7cf94d8", + "metadata": { + "editable": true + }, + "source": [ "## Regression analysis, overarching aims II\n", "\n", - "\n", "Consider an experiment in which $p$ characteristics of $n$ samples are\n", "measured. The data from this experiment, for various explanatory variables $p$ are normally represented by a matrix \n", "$\\mathbf{X}$.\n", @@ -3312,12 +3035,16 @@ "the *linear regression model* where $\\boldsymbol{\\beta} = [\\beta_0, \\ldots,\n", "\\beta_{p-1}]^{T}$ are the *regression parameters*. \n", "\n", - "Linear regression gives us a set of analytical equations for the parameters $\\beta_j$.\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "Linear regression gives us a set of analytical equations for the parameters $\\beta_j$." + ] + }, + { + "cell_type": "markdown", + "id": "3b98d102", + "metadata": { + "editable": true + }, + "source": [ "## Examples\n", "In order to understand the relation among the predictors $p$, the set of data $n$ and the target (outcome, output etc) $\\boldsymbol{y}$,\n", "consider the model we discussed for describing nuclear binding energies. \n", @@ -3328,7 +3055,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a3814cbf", + "metadata": { + "editable": true + }, "source": [ "$$\n", "BE(A) = a_0+a_1A+a_2A^{2/3}+a_3A^{-1/3}+a_4A^{-1},\n", @@ -3337,21 +3067,26 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "34db7d71", + "metadata": { + "editable": true + }, "source": [ "we have five predictors, that is the intercept, the $A$ dependent term, the $A^{2/3}$ term and the $A^{-1/3}$ and $A^{-1}$ terms.\n", "This gives $p=0,1,2,3,4$. Furthermore we have $n$ entries for each predictor. It means that our design matrix is a \n", "$p\\times n$ matrix $\\boldsymbol{X}$.\n", "\n", "Here the predictors are based on a model we have made. A popular data set which is widely encountered in ML applications is the\n", - "so-called [credit card default data from Taiwan](https://www.sciencedirect.com/science/article/pii/S0957417407006719?via%3Dihub). The data set contains data on $n=30000$ credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are $24$ such predictors or attributes leading to a design matrix of dimensionality $24 \\times 30000$. This is however a classification problem and we will come back to it when we discuss Logistic Regression.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "so-called [credit card default data from Taiwan](https://www.sciencedirect.com/science/article/pii/S0957417407006719?via%3Dihub). The data set contains data on $n=30000$ credit card holders with predictors like gender, marital status, age, profession, education, etc. In total there are $24$ such predictors or attributes leading to a design matrix of dimensionality $24 \\times 30000$. This is however a classification problem and we will come back to it when we discuss Logistic Regression." + ] + }, + { + "cell_type": "markdown", + "id": "0f3d34aa", + "metadata": { + "editable": true + }, + "source": [ "## General linear models\n", "Before we proceed let us study a case from linear algebra where we aim at fitting a set of data $\\boldsymbol{y}=[y_0,y_1,\\dots,y_{n-1}]$. We could think of these data as a result of an experiment or a complicated numerical experiment. These data are functions of a series of variables $\\boldsymbol{x}=[x_0,x_1,\\dots,x_{n-1}]$, that is $y_i = y(x_i)$ with $i=0,1,2,\\dots,n-1$. The variables $x_i$ could represent physical quantities like time, temperature, position etc. We assume that $y(x)$ is a smooth function. \n", "\n", @@ -3360,7 +3095,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "3ae8a917", + "metadata": { + "editable": true + }, "source": [ "$$\n", "y=y(x) \\rightarrow y(x_i)=\\tilde{y}_i+\\epsilon_i=\\sum_{j=0}^{n-1} \\beta_j x_i^j+\\epsilon_i,\n", @@ -3369,20 +3107,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "85b75da7", + "metadata": { + "editable": true + }, + "source": [ + "where $\\epsilon_i$ is the error in our approximation." + ] + }, + { + "cell_type": "markdown", + "id": "b1ad5988", + "metadata": { + "editable": true + }, "source": [ - "where $\\epsilon_i$ is the error in our approximation.\n", - "\n", - "\n", - "\n", - "\n", "## Rewriting the fitting procedure as a linear algebra problem\n", "For every set of values $y_i,x_i$ we have thus the corresponding set of equations" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "d31fc0eb", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\begin{align*}\n", @@ -3397,7 +3146,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f0c96fe6", + "metadata": { + "editable": true + }, "source": [ "## Rewriting the fitting procedure as a linear algebra problem, more details\n", "Defining the vectors" @@ -3405,7 +3157,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e05fb474", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{y} = [y_0,y_1, y_2,\\dots, y_{n-1}]^T,\n", @@ -3414,14 +3169,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "832b4a52", + "metadata": { + "editable": true + }, "source": [ "and" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "2a04c6b0", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\beta} = [\\beta_0,\\beta_1, \\beta_2,\\dots, \\beta_{n-1}]^T,\n", @@ -3430,14 +3191,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "95feb9c7", + "metadata": { + "editable": true + }, "source": [ "and" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "9388dae6", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\epsilon} = [\\epsilon_0,\\epsilon_1, \\epsilon_2,\\dots, \\epsilon_{n-1}]^T,\n", @@ -3446,14 +3213,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4b407da6", + "metadata": { + "editable": true + }, "source": [ "and the design matrix" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "d6f77716", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}=\n", @@ -3469,14 +3242,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "7ac4ebe7", + "metadata": { + "editable": true + }, "source": [ "we can rewrite our equations as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "666e3761", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{y} = \\boldsymbol{X}\\boldsymbol{\\beta}+\\boldsymbol{\\epsilon}.\n", @@ -3485,13 +3264,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "7281f3db", + "metadata": { + "editable": true + }, + "source": [ + "The above design matrix is called a [Vandermonde matrix](https://en.wikipedia.org/wiki/Vandermonde_matrix)." + ] + }, + { + "cell_type": "markdown", + "id": "b6402b93", + "metadata": { + "editable": true + }, "source": [ - "The above design matrix is called a [Vandermonde matrix](https://en.wikipedia.org/wiki/Vandermonde_matrix).\n", - "\n", - "\n", - "\n", - "\n", "## Generalizing the fitting procedure as a linear algebra problem\n", "\n", "We are obviously not limited to the above polynomial expansions. We\n", @@ -3503,7 +3290,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "be28ea6a", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\begin{align*}\n", @@ -3520,20 +3310,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d6ff0add", + "metadata": { + "editable": true + }, + "source": [ + "**Note that we have $p=n$ here. The matrix is symmetric. This is generally not the case!**" + ] + }, + { + "cell_type": "markdown", + "id": "10f87413", + "metadata": { + "editable": true + }, "source": [ - "**Note that we have $p=n$ here. The matrix is symmetric. This is generally not the case!**\n", - "\n", - "\n", - "\n", - "\n", "## Generalizing the fitting procedure as a linear algebra problem\n", "We redefine in turn the matrix $\\boldsymbol{X}$ as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "2fc2d589", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}=\n", @@ -3549,14 +3350,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "49448051", + "metadata": { + "editable": true + }, "source": [ "and without loss of generality we rewrite again our equations as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "c96a1d13", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{y} = \\boldsymbol{X}\\boldsymbol{\\beta}+\\boldsymbol{\\epsilon}.\n", @@ -3565,20 +3372,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "34f05f37", + "metadata": { + "editable": true + }, + "source": [ + "The left-hand side of this equation is kwown. Our error vector $\\boldsymbol{\\epsilon}$ and the parameter vector $\\boldsymbol{\\beta}$ are our unknow quantities. How can we obtain the optimal set of $\\beta_i$ values?" + ] + }, + { + "cell_type": "markdown", + "id": "e6ff72db", + "metadata": { + "editable": true + }, "source": [ - "The left-hand side of this equation is kwown. Our error vector $\\boldsymbol{\\epsilon}$ and the parameter vector $\\boldsymbol{\\beta}$ are our unknow quantities. How can we obtain the optimal set of $\\beta_i$ values?\n", - "\n", - "\n", - "\n", - "\n", "## Optimizing our parameters\n", "We have defined the matrix $\\boldsymbol{X}$ via the equations" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "39aef328", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\begin{align*}\n", @@ -3595,15 +3413,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0a4e3a65", + "metadata": { + "editable": true + }, "source": [ "As we noted above, we stayed with a system with the design matrix \n", " $\\boldsymbol{X}\\in {\\mathbb{R}}^{n\\times n}$, that is we have $p=n$. For reasons to come later (algorithmic arguments) we will hereafter define \n", - "our matrix as $\\boldsymbol{X}\\in {\\mathbb{R}}^{n\\times p}$, with the predictors refering to the column numbers and the entries $n$ being the row elements.\n", - "\n", - "\n", - "\n", - "\n", + "our matrix as $\\boldsymbol{X}\\in {\\mathbb{R}}^{n\\times p}$, with the predictors refering to the column numbers and the entries $n$ being the row elements." + ] + }, + { + "cell_type": "markdown", + "id": "523fbdc7", + "metadata": { + "editable": true + }, + "source": [ "## Our model for the nuclear binding energies\n", "\n", "In our [introductory notes](https://compphysics.github.io/MachineLearning/doc/pub/How2ReadData/html/How2ReadData.html) we looked at the so-called [liquid drop model](https://en.wikipedia.org/wiki/Semi-empirical_mass_formula). Let us remind ourselves about what we did by looking at the code.\n", @@ -3613,8 +3439,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 38, + "id": "65375fc3", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Common imports\n", @@ -3690,14 +3520,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a6b35fe6", + "metadata": { + "editable": true + }, "source": [ "With $\\boldsymbol{\\beta}\\in {\\mathbb{R}}^{p\\times 1}$, it means that we will hereafter write our equations for the approximation as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "b4a0e652", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\tilde{y}}= \\boldsymbol{X}\\boldsymbol{\\beta},\n", @@ -3706,18 +3542,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "040adc2c", + "metadata": { + "editable": true + }, + "source": [ + "throughout these lectures." + ] + }, + { + "cell_type": "markdown", + "id": "8cb88980", + "metadata": { + "editable": true + }, "source": [ - "throughout these lectures. \n", - "\n", - "\n", "## Optimizing our parameters, more details\n", "With the above we use the design matrix to define the approximation $\\boldsymbol{\\tilde{y}}$ via the unknown quantity $\\boldsymbol{\\beta}$ as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "fc947e4c", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\tilde{y}}= \\boldsymbol{X}\\boldsymbol{\\beta},\n", @@ -3726,14 +3575,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c54ed44f", + "metadata": { + "editable": true + }, "source": [ "and in order to find the optimal parameters $\\beta_i$ instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values $y_i$ (which represent hopefully the exact values) and the parameterized values $\\tilde{y}_i$, namely" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "9700bc2a", + "metadata": { + "editable": true + }, "source": [ "$$\n", "C(\\boldsymbol{\\beta})=\\frac{1}{n}\\sum_{i=0}^{n-1}\\left(y_i-\\tilde{y}_i\\right)^2=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}}\\right)\\right\\},\n", @@ -3742,14 +3597,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "6486ad4b", + "metadata": { + "editable": true + }, "source": [ "or using the matrix $\\boldsymbol{X}$ and in a more compact matrix-vector notation as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "b17f3473", + "metadata": { + "editable": true + }, "source": [ "$$\n", "C(\\boldsymbol{\\beta})=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)\\right\\}.\n", @@ -3758,19 +3619,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "511ef4cd", + "metadata": { + "editable": true + }, "source": [ "This function is one possible way to define the so-called cost function.\n", "\n", - "\n", - "\n", "It is also common to define\n", "the function $C$ as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "15a9cc37", + "metadata": { + "editable": true + }, "source": [ "$$\n", "C(\\boldsymbol{\\beta})=\\frac{1}{2n}\\sum_{i=0}^{n-1}\\left(y_i-\\tilde{y}_i\\right)^2,\n", @@ -3779,13 +3644,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "367d1bd9", + "metadata": { + "editable": true + }, + "source": [ + "since when taking the first derivative with respect to the unknown parameters $\\beta$, the factor of $2$ cancels out." + ] + }, + { + "cell_type": "markdown", + "id": "300db0a3", + "metadata": { + "editable": true + }, "source": [ - "since when taking the first derivative with respect to the unknown parameters $\\beta$, the factor of $2$ cancels out.\n", - "\n", - "\n", - "\n", - "\n", "## Interpretations and optimizing our parameters\n", "\n", "The function" @@ -3793,7 +3666,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "78ad2d59", + "metadata": { + "editable": true + }, "source": [ "$$\n", "C(\\boldsymbol{\\beta})=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)\\right\\},\n", @@ -3802,7 +3678,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "adb62030", + "metadata": { + "editable": true + }, "source": [ "can be linked to the variance of the quantity $y_i$ if we interpret the latter as the mean value. \n", "When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret $y_i$ as a mean value" @@ -3810,7 +3689,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4cb086a5", + "metadata": { + "editable": true + }, "source": [ "$$\n", "y_{i}=\\langle y_i \\rangle = \\beta_0x_{i,0}+\\beta_1x_{i,1}+\\beta_2x_{i,2}+\\dots+\\beta_{n-1}x_{i,n-1}+\\epsilon_i,\n", @@ -3819,7 +3701,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f5164d25", + "metadata": { + "editable": true + }, "source": [ "where $\\langle y_i \\rangle$ is the mean value. Keep in mind also that\n", "till now we have treated $y_i$ as the exact value. Normally, the\n", @@ -3835,7 +3720,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "171787e6", + "metadata": { + "editable": true + }, "source": [ "$$\n", "{\\displaystyle \\min_{\\boldsymbol{\\beta}\\in\n", @@ -3845,14 +3733,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bc2e0510", + "metadata": { + "editable": true + }, "source": [ "In practical terms it means we will require" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e5649cfc", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial C(\\boldsymbol{\\beta})}{\\partial \\beta_j} = \\frac{\\partial }{\\partial \\beta_j}\\left[ \\frac{1}{n}\\sum_{i=0}^{n-1}\\left(y_i-\\beta_0x_{i,0}-\\beta_1x_{i,1}-\\beta_2x_{i,2}-\\dots-\\beta_{n-1}x_{i,n-1}\\right)^2\\right]=0,\n", @@ -3861,14 +3755,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "134777d3", + "metadata": { + "editable": true + }, "source": [ "which results in" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "18b005f8", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial C(\\boldsymbol{\\beta})}{\\partial \\beta_j} = -\\frac{2}{n}\\left[ \\sum_{i=0}^{n-1}x_{ij}\\left(y_i-\\beta_0x_{i,0}-\\beta_1x_{i,1}-\\beta_2x_{i,2}-\\dots-\\beta_{n-1}x_{i,n-1}\\right)\\right]=0,\n", @@ -3877,14 +3777,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b34ed0d9", + "metadata": { + "editable": true + }, "source": [ "or in a matrix-vector form as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "7cc13452", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial C(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} = 0 = \\boldsymbol{X}^T\\left( \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right).\n", @@ -3893,7 +3799,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "31f0b7c2", + "metadata": { + "editable": true + }, "source": [ "## Interpretations and optimizing our parameters\n", "We can rewrite" @@ -3901,7 +3810,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "feb09e6a", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial C(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} = 0 = \\boldsymbol{X}^T\\left( \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right),\n", @@ -3910,14 +3822,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4c1fbe44", + "metadata": { + "editable": true + }, "source": [ "as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "12a694e5", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}^T\\boldsymbol{y} = \\boldsymbol{X}^T\\boldsymbol{X}\\boldsymbol{\\beta},\n", @@ -3926,14 +3844,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ba26ca19", + "metadata": { + "editable": true + }, "source": [ "and if the matrix $\\boldsymbol{X}^T\\boldsymbol{X}$ is invertible we have the solution" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "39958365", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\beta} =\\left(\\boldsymbol{X}^T\\boldsymbol{X}\\right)^{-1}\\boldsymbol{X}^T\\boldsymbol{y}.\n", @@ -3942,7 +3866,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "bcc1b272", + "metadata": { + "editable": true + }, "source": [ "We note also that since our design matrix is defined as $\\boldsymbol{X}\\in\n", "{\\mathbb{R}}^{n\\times p}$, the product $\\boldsymbol{X}^T\\boldsymbol{X} \\in\n", @@ -3955,12 +3882,16 @@ "allow for the usage of direct linear algebra methods such as **LU** decomposition or **Singular Value Decomposition** (SVD) for finding the inverse of the matrix\n", "$\\boldsymbol{X}^T\\boldsymbol{X}$.\n", "\n", - "\n", - "\n", - "**Small question**: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix $\\boldsymbol{X}^T\\boldsymbol{X}$? What kind of problems can we expect?\n", - "\n", - "\n", - "\n", + "**Small question**: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix $\\boldsymbol{X}^T\\boldsymbol{X}$? What kind of problems can we expect?" + ] + }, + { + "cell_type": "markdown", + "id": "5dc4f920", + "metadata": { + "editable": true + }, + "source": [ "## Some useful matrix and vector expressions\n", "\n", "The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and \n", @@ -3969,79 +3900,46 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f341bf32", + "metadata": { + "editable": true + }, "source": [ - "4\n", - "8\n", - " \n", - "<\n", - "<\n", - "<\n", - "!\n", - "!\n", - "M\n", - "A\n", - "T\n", - "H\n", - "_\n", - "B\n", - "L\n", - "O\n", - "C\n", - "K" + "$$\n", + "\\frac{\\partial (\\boldsymbol{b}^T\\boldsymbol{a})}{\\partial \\boldsymbol{a}} = \\boldsymbol{b},\n", + "$$" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e5aa6d33", + "metadata": { + "editable": true + }, "source": [ - "4\n", - "9\n", - " \n", - "<\n", - "<\n", - "<\n", - "!\n", - "!\n", - "M\n", - "A\n", - "T\n", - "H\n", - "_\n", - "B\n", - "L\n", - "O\n", - "C\n", - "K" + "$$\n", + "\\frac{\\partial (\\boldsymbol{a}^T\\boldsymbol{A}\\boldsymbol{a})}{\\partial \\boldsymbol{a}} = (\\boldsymbol{A}+\\boldsymbol{A}^T)\\boldsymbol{a},\n", + "$$" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e0163aef", + "metadata": { + "editable": true + }, "source": [ - "5\n", - "0\n", - " \n", - "<\n", - "<\n", - "<\n", - "!\n", - "!\n", - "M\n", - "A\n", - "T\n", - "H\n", - "_\n", - "B\n", - "L\n", - "O\n", - "C\n", - "K" + "$$\n", + "\\frac{\\partial tr(\\boldsymbol{B}\\boldsymbol{A})}{\\partial \\boldsymbol{A}} = \\boldsymbol{B}^T,\n", + "$$" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "f3d8529d", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\log{\\vert\\boldsymbol{A}\\vert}}{\\partial \\boldsymbol{A}} = (\\boldsymbol{A}^{-1})^T.\n", @@ -4050,7 +3948,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "926fae33", + "metadata": { + "editable": true + }, "source": [ "## Interpretations and optimizing our parameters\n", "The residuals $\\boldsymbol{\\epsilon}$ are in turn given by" @@ -4058,7 +3959,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "459363f3", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\epsilon} = \\boldsymbol{y}-\\boldsymbol{\\tilde{y}} = \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta},\n", @@ -4067,14 +3971,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c1ae7c6c", + "metadata": { + "editable": true + }, "source": [ "and with" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "52de9181", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}^T\\left( \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)= 0,\n", @@ -4083,14 +3993,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b4619337", + "metadata": { + "editable": true + }, "source": [ "we have" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e384b941", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{X}^T\\boldsymbol{\\epsilon}=\\boldsymbol{X}^T\\left( \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)= 0,\n", @@ -4099,15 +4015,23 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4123b6f6", + "metadata": { + "editable": true + }, "source": [ "meaning that the solution for $\\boldsymbol{\\beta}$ is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.\n", "\n", - "\n", - "\n", - "\n", - "Let us now return to our nuclear binding energies and simply code the above equations. \n", - "\n", + "Let us now return to our nuclear binding energies and simply code the above equations." + ] + }, + { + "cell_type": "markdown", + "id": "8f1c0df4", + "metadata": { + "editable": true + }, + "source": [ "## Own code for Ordinary Least Squares\n", "\n", "It is rather straightforward to implement the matrix inversion and obtain the parameters $\\boldsymbol{\\beta}$. After having defined the matrix $\\boldsymbol{X}$ we simply need to \n", @@ -4116,8 +4040,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 39, + "id": "f06d4256", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# matrix inversion to find beta\n", @@ -4128,15 +4056,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "cdf3d845", + "metadata": { + "editable": true + }, "source": [ "Alternatively, you can use the least squares functionality in **Numpy** as" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 40, + "id": "bff161d1", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "fit = np.linalg.lstsq(X, Energies, rcond =None)[0]\n", @@ -4145,15 +4080,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "1ba8de37", + "metadata": { + "editable": true + }, "source": [ "And finally we plot our fit with and compare with data" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 41, + "id": "ff3cb363", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "Masses['Eapprox'] = ytilde\n", @@ -4172,7 +4114,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "367e150e", + "metadata": { + "editable": true + }, "source": [ "## Adding error analysis and training set up\n", "\n", @@ -4182,8 +4127,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 42, + "id": "e75d549e", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "def R2(y_data, y_model):\n", @@ -4192,15 +4141,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "5937c2eb", + "metadata": { + "editable": true + }, "source": [ "and we would be using it as" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 43, + "id": "6e4a7267", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "print(R2(Energies,ytilde))" @@ -4208,15 +4164,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "af9b5785", + "metadata": { + "editable": true + }, "source": [ "We can easily add our **MSE** score as" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 44, + "id": "1eda8437", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "def MSE(y_data,y_model):\n", @@ -4228,15 +4191,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b5d3d853", + "metadata": { + "editable": true + }, "source": [ "and finally the relative error as" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 45, + "id": "5166df6e", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "def RelativeError(y_data,y_model):\n", @@ -4246,7 +4216,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "236c30eb", + "metadata": { + "editable": true + }, "source": [ "## The $\\chi^2$ function\n", "\n", @@ -4265,7 +4238,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "50a6a65f", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\chi^2(\\boldsymbol{\\beta})=\\frac{1}{n}\\sum_{i=0}^{n-1}\\frac{\\left(y_i-\\tilde{y}_i\\right)^2}{\\sigma_i^2}=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}}\\right)^T\\frac{1}{\\boldsymbol{\\Sigma^2}}\\left(\\boldsymbol{y}-\\boldsymbol{\\tilde{y}}\\right)\\right\\},\n", @@ -4274,12 +4250,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "1f7a0ed2", + "metadata": { + "editable": true + }, + "source": [ + "where the matrix $\\boldsymbol{\\Sigma}$ is a diagonal matrix with $\\sigma_i$ as matrix elements." + ] + }, + { + "cell_type": "markdown", + "id": "254e32f6", + "metadata": { + "editable": true + }, "source": [ - "where the matrix $\\boldsymbol{\\Sigma}$ is a diagonal matrix with $\\sigma_i$ as matrix elements.\n", - "\n", - "\n", - "\n", "## The $\\chi^2$ function\n", "\n", "In order to find the parameters $\\beta_i$ we will then minimize the spread of $\\chi^2(\\boldsymbol{\\beta})$ by requiring" @@ -4287,7 +4272,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "309cb707", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\beta_j} = \\frac{\\partial }{\\partial \\beta_j}\\left[ \\frac{1}{n}\\sum_{i=0}^{n-1}\\left(\\frac{y_i-\\beta_0x_{i,0}-\\beta_1x_{i,1}-\\beta_2x_{i,2}-\\dots-\\beta_{n-1}x_{i,n-1}}{\\sigma_i}\\right)^2\\right]=0,\n", @@ -4296,14 +4284,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ed0d9230", + "metadata": { + "editable": true + }, "source": [ "which results in" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "6e729fff", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\beta_j} = -\\frac{2}{n}\\left[ \\sum_{i=0}^{n-1}\\frac{x_{ij}}{\\sigma_i}\\left(\\frac{y_i-\\beta_0x_{i,0}-\\beta_1x_{i,1}-\\beta_2x_{i,2}-\\dots-\\beta_{n-1}x_{i,n-1}}{\\sigma_i}\\right)\\right]=0,\n", @@ -4312,14 +4306,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4b8c3db8", + "metadata": { + "editable": true + }, "source": [ "or in a matrix-vector form as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "0f38e855", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} = 0 = \\boldsymbol{A}^T\\left( \\boldsymbol{b}-\\boldsymbol{A}\\boldsymbol{\\beta}\\right).\n", @@ -4328,12 +4328,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e9810355", + "metadata": { + "editable": true + }, + "source": [ + "where we have defined the matrix $\\boldsymbol{A} =\\boldsymbol{X}/\\boldsymbol{\\Sigma}$ with matrix elements $a_{ij} = x_{ij}/\\sigma_i$ and the vector $\\boldsymbol{b}$ with elements $b_i = y_i/\\sigma_i$." + ] + }, + { + "cell_type": "markdown", + "id": "d64064a7", + "metadata": { + "editable": true + }, "source": [ - "where we have defined the matrix $\\boldsymbol{A} =\\boldsymbol{X}/\\boldsymbol{\\Sigma}$ with matrix elements $a_{ij} = x_{ij}/\\sigma_i$ and the vector $\\boldsymbol{b}$ with elements $b_i = y_i/\\sigma_i$.\n", - "\n", - "\n", - "\n", "## The $\\chi^2$ function\n", "\n", "We can rewrite" @@ -4341,7 +4350,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ca671f7b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} = 0 = \\boldsymbol{A}^T\\left( \\boldsymbol{b}-\\boldsymbol{A}\\boldsymbol{\\beta}\\right),\n", @@ -4350,14 +4362,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "857dac9b", + "metadata": { + "editable": true + }, "source": [ "as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "6f16b544", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{A}^T\\boldsymbol{b} = \\boldsymbol{A}^T\\boldsymbol{A}\\boldsymbol{\\beta},\n", @@ -4366,14 +4384,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "7152f392", + "metadata": { + "editable": true + }, "source": [ "and if the matrix $\\boldsymbol{A}^T\\boldsymbol{A}$ is invertible we have the solution" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "0d6ac746", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{\\beta} =\\left(\\boldsymbol{A}^T\\boldsymbol{A}\\right)^{-1}\\boldsymbol{A}^T\\boldsymbol{b}.\n", @@ -4382,7 +4406,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "62cc38ae", + "metadata": { + "editable": true + }, "source": [ "## The $\\chi^2$ function\n", "\n", @@ -4391,7 +4418,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "eeb7f574", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\boldsymbol{H} = \\left(\\boldsymbol{A}^T\\boldsymbol{A}\\right)^{-1},\n", @@ -4400,14 +4430,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "9963ae15", + "metadata": { + "editable": true + }, "source": [ "we have then the following expression for the parameters $\\beta_j$ (the matrix elements of $\\boldsymbol{H}$ are $h_{ij}$)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "4e816631", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\beta_j = \\sum_{k=0}^{p-1}h_{jk}\\sum_{i=0}^{n-1}\\frac{y_i}{\\sigma_i}\\frac{x_{ik}}{\\sigma_i} = \\sum_{k=0}^{p-1}h_{jk}\\sum_{i=0}^{n-1}b_ia_{ik}\n", @@ -4416,14 +4452,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "75595bb9", + "metadata": { + "editable": true + }, "source": [ "We state without proof the expression for the uncertainty in the parameters $\\beta_j$ as (we leave this as an exercise)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "278292fc", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\sigma^2(\\beta_j) = \\sum_{i=0}^{n-1}\\sigma_i^2\\left( \\frac{\\partial \\beta_j}{\\partial y_i}\\right)^2,\n", @@ -4432,14 +4474,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "82c2439c", + "metadata": { + "editable": true + }, "source": [ "resulting in" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "59ff6249", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\sigma^2(\\beta_j) = \\left(\\sum_{k=0}^{p-1}h_{jk}\\sum_{i=0}^{n-1}a_{ik}\\right)\\left(\\sum_{l=0}^{p-1}h_{jl}\\sum_{m=0}^{n-1}a_{ml}\\right) = h_{jj}!\n", @@ -4448,7 +4496,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "eb2dc41e", + "metadata": { + "editable": true + }, "source": [ "## The $\\chi^2$ function\n", "The first step here is to approximate the function $y$ with a first-order polynomial, that is we write" @@ -4456,7 +4507,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "723aa239", + "metadata": { + "editable": true + }, "source": [ "$$\n", "y=y(x) \\rightarrow y(x_i) \\approx \\beta_0+\\beta_1 x_i.\n", @@ -4465,14 +4519,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b513b90f", + "metadata": { + "editable": true + }, "source": [ "By computing the derivatives of $\\chi^2$ with respect to $\\beta_0$ and $\\beta_1$ show that these are given by" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "62903cbc", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\beta_0} = -2\\left[ \\frac{1}{n}\\sum_{i=0}^{n-1}\\left(\\frac{y_i-\\beta_0-\\beta_1x_{i}}{\\sigma_i^2}\\right)\\right]=0,\n", @@ -4481,14 +4541,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "207584d4", + "metadata": { + "editable": true + }, "source": [ "and" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "6c910491", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\frac{\\partial \\chi^2(\\boldsymbol{\\beta})}{\\partial \\beta_1} = -\\frac{2}{n}\\left[ \\sum_{i=0}^{n-1}x_i\\left(\\frac{y_i-\\beta_0-\\beta_1x_{i}}{\\sigma_i^2}\\right)\\right]=0.\n", @@ -4497,7 +4563,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "1bc61f61", + "metadata": { + "editable": true + }, "source": [ "## The $\\chi^2$ function\n", "\n", @@ -4507,7 +4576,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "d573377f", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\gamma = \\sum_{i=0}^{n-1}\\frac{1}{\\sigma_i^2},\n", @@ -4516,7 +4588,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "3cbeb35c", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\gamma_x = \\sum_{i=0}^{n-1}\\frac{x_{i}}{\\sigma_i^2},\n", @@ -4525,7 +4600,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "c91cb43e", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\gamma_y = \\sum_{i=0}^{n-1}\\left(\\frac{y_i}{\\sigma_i^2}\\right),\n", @@ -4534,7 +4612,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "e20a004b", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\gamma_{xx} = \\sum_{i=0}^{n-1}\\frac{x_ix_{i}}{\\sigma_i^2},\n", @@ -4543,7 +4624,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a116dd64", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\gamma_{xy} = \\sum_{i=0}^{n-1}\\frac{y_ix_{i}}{\\sigma_i^2},\n", @@ -4552,14 +4636,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f1fa634c", + "metadata": { + "editable": true + }, "source": [ "we obtain" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "d83177be", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\beta_0 = \\frac{\\gamma_{xx}\\gamma_y-\\gamma_x\\gamma_y}{\\gamma\\gamma_{xx}-\\gamma_x^2},\n", @@ -4568,7 +4658,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "ff3efe3f", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\beta_1 = \\frac{\\gamma_{xy}\\gamma-\\gamma_x\\gamma_y}{\\gamma\\gamma_{xx}-\\gamma_x^2}.\n", @@ -4577,16 +4670,24 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "b94950d4", + "metadata": { + "editable": true + }, "source": [ "This approach (different linear and non-linear regression) suffers\n", "often from both being underdetermined and overdetermined in the\n", "unknown coefficients $\\beta_i$. A better approach is to use the\n", - "Singular Value Decomposition (SVD) method discussed next week.\n", - "\n", - "\n", - "\n", - "\n", + "Singular Value Decomposition (SVD) method discussed next week." + ] + }, + { + "cell_type": "markdown", + "id": "8889337c", + "metadata": { + "editable": true + }, + "source": [ "## Fitting an Equation of State for Dense Nuclear Matter\n", "\n", "Before we continue, let us introduce yet another example. We are going to fit the\n", @@ -4604,15 +4705,27 @@ "The difference now is that we use **Scikit-Learn's** regression tools\n", "instead of our own matrix inversion implementation. Furthermore, we\n", "sneak in **Ridge** regression (to be discussed below) which includes a\n", - "hyperparameter $\\lambda$, also to be explained below.\n", - "\n", + "hyperparameter $\\lambda$, also to be explained below." + ] + }, + { + "cell_type": "markdown", + "id": "79eeb561", + "metadata": { + "editable": true + }, + "source": [ "## The code" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 46, + "id": "194a1d1a", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Common imports\n", @@ -4704,16 +4817,26 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "a8dcc692", + "metadata": { + "editable": true + }, "source": [ "The above simple polynomial in density $\\rho$ gives an excellent fit\n", "to the data. \n", "\n", "We note also that there is a small deviation between the\n", "standard OLS and the Ridge regression at higher densities. We discuss this in more detail\n", - "below.\n", - "\n", - "\n", + "below." + ] + }, + { + "cell_type": "markdown", + "id": "12a0253c", + "metadata": { + "editable": true + }, + "source": [ "## Splitting our Data in Training and Test data\n", "\n", "It is normal in essentially all Machine Learning studies to split the\n", @@ -4730,8 +4853,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 47, + "id": "5ff33c4e", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import os\n", @@ -4802,16 +4929,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "4befc696", + "metadata": { + "editable": true + }, "source": [ "## Exercises for week 35\n", - "Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "Here are three possible exercises for week 35 and the lab sessions of Wednesday September 1." + ] + }, + { + "cell_type": "markdown", + "id": "f833fa2b", + "metadata": { + "editable": true + }, + "source": [ "## Exercise 1: Setting up various Python environments\n", "\n", "The first exercise here is of a mere technical art. We want you to have \n", @@ -4871,15 +5004,16 @@ "analysis environment, available for free and under a commercial\n", "license.\n", "\n", - "We recommend using **Anaconda** if you are not too familiar with setting paths in a terminal environment.\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", + "We recommend using **Anaconda** if you are not too familiar with setting paths in a terminal environment." + ] + }, + { + "cell_type": "markdown", + "id": "21b7c11f", + "metadata": { + "editable": true + }, + "source": [ "## Exercise 2: making your own data and exploring scikit-learn\n", "\n", "We will generate our own dataset for a function $y(x)$ where $x \\in [0,1]$ 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)$.\n", @@ -4888,8 +5022,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 48, + "id": "9213ce7d", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "x = np.random.rand(100,1)\n", @@ -4898,7 +5036,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "0166974f", + "metadata": { + "editable": true + }, "source": [ "1. Write your own code (following the examples under the [regression notes](https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/chapter1.html)) for computing the parametrization of the data set fitting a second-order polynomial. \n", "\n", @@ -4909,7 +5050,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "982d42cb", + "metadata": { + "editable": true + }, "source": [ "$$\n", "MSE(\\boldsymbol{y},\\boldsymbol{\\tilde{y}}) = \\frac{1}{n}\n", @@ -4919,7 +5063,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "9d32cf1a", + "metadata": { + "editable": true + }, "source": [ "and the $R^2$ score function.\n", "If $\\tilde{\\boldsymbol{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" @@ -4927,7 +5074,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "f07e5904", + "metadata": { + "editable": true + }, "source": [ "$$\n", "R^2(\\boldsymbol{y}, \\tilde{\\boldsymbol{y}}) = 1 - \\frac{\\sum_{i=0}^{n - 1} (y_i - \\tilde{y}_i)^2}{\\sum_{i=0}^{n - 1} (y_i - \\bar{y})^2},\n", @@ -4936,14 +5086,20 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "3c91a4d7", + "metadata": { + "editable": true + }, "source": [ "where we have defined the mean value of $\\boldsymbol{y}$ as" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "22dce6cd", + "metadata": { + "editable": true + }, "source": [ "$$\n", "\\bar{y} = \\frac{1}{n} \\sum_{i=0}^{n - 1} y_i.\n", @@ -4952,12 +5108,14 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "63dbfea2", + "metadata": { + "editable": true + }, "source": [ "You can use the functionality included in scikit-learn. If you feel for it, you can use your own program and define functions which compute the above two functions. \n", "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.\n", "\n", - "\n", "\n", "**Solution.**\n", "The code here is an example of where we define our own design matrix and fit parameters $\\beta$." @@ -4965,8 +5123,12 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 49, + "id": "c007a8f7", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import os\n", @@ -5013,17 +5175,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "093a802e", + "metadata": { + "editable": true + }, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "id": "a4fd1970", + "metadata": { + "editable": true + }, "source": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", "## Exercise 3: Normalizing our data\n", "\n", "A much used approach before starting to train the data is to preprocess our\n", @@ -5041,7 +5207,6 @@ "function included in **Scikit-Learn** is the **MinMaxScaler** which\n", "ensures that all features are exactly between $0$ and $1$. The\n", "\n", - "\n", "The **Normalizer** scales each data\n", "point such that the feature vector has a euclidean length of one. In other words, it\n", "projects a data point on the circle (or sphere in the case of higher dimensions) with a\n", @@ -5059,15 +5224,18 @@ "outliers, and might often lead to trouble for other scaling\n", "techniques.\n", "\n", - "\n", "It also common to split the data in a **training** set and a **testing** set. A typical split is to use $80\\%$ of the data for training and the rest\n", "for testing. This can be done as follows with our design matrix $\\boldsymbol{X}$ and data $\\boldsymbol{y}$ (remember to import **scikit-learn**)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 50, + "id": "27b4f807", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# split in training and test data\n", @@ -5076,15 +5244,22 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "78154d99", + "metadata": { + "editable": true + }, "source": [ "Then we can use the standard scaler to scale our data as" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 51, + "id": "709a18d0", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "scaler = StandardScaler()\n", @@ -5095,7 +5270,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "2362e332", + "metadata": { + "editable": true + }, "source": [ "In this exercise we want you to to compute the MSE for the training\n", "data and the test data as function of the complexity of a polynomial,\n", @@ -5104,15 +5282,17 @@ "One of \n", "the aims is to reproduce Figure 2.11 of [Hastie et al](https://github.com/CompPhysics/MLErasmus/blob/master/doc/Textbooks/elementsstat.pdf).\n", "\n", - "\n", - "\n", "Our data is defined by $x\\in [-3,3]$ with a total of for example $100$ data points." ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, + "execution_count": 52, + "id": "47021865", + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "np.random.seed()\n", @@ -5125,44 +5305,49 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "eb6cf432", + "metadata": { + "editable": true + }, + "source": [ + "where $y$ is the function we want to fit with a given polynomial." + ] + }, + { + "cell_type": "markdown", + "id": "b61a59b9", + "metadata": { + "editable": true + }, "source": [ - "where $y$ is the function we want to fit with a given polynomial.\n", - "\n", - "\n", "**a)**\n", - "Write a first code which sets up a design matrix $X$ defined by a fifth-order polynomial. Scale your data and split it in training and test data.\n", - "\n", + "Write a first code which sets up a design matrix $X$ defined by a fifth-order polynomial. Scale your data and split it in training and test data." + ] + }, + { + "cell_type": "markdown", + "id": "c334b79a", + "metadata": { + "editable": true + }, + "source": [ "**b)**\n", - "Perform an ordinary least squares and compute the means squared error and the $R2$ factor for the training data and the test data, with and without scaling.\n", - "\n", + "Perform an ordinary least squares and compute the means squared error and the $R2$ factor for the training data and the test data, with and without scaling." + ] + }, + { + "cell_type": "markdown", + "id": "5164c62c", + "metadata": { + "editable": true + }, + "source": [ "**c)**\n", - "Add now a model which allows you to make polynomials up to degree $15$. Perform a standard OLS fitting of the training data and compute the MSE and $R2$ for the training and test data and plot both test and training data MSE and $R2$ as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)?\n", - "\n", - "\n", - "" + "Add now a model which allows you to make polynomials up to degree $15$. Perform a standard OLS fitting of the training data and compute the MSE and $R2$ for the training and test data and plot both test and training data MSE and $R2$ as functions of the polynomial degree. Compare what you see with Figure 2.11 of Hastie et al. Comment your results. For which polynomial degree do you find an optimal MSE (smallest value)?" ] } ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.9.7" - } - }, + "metadata": {}, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 } diff --git a/doc/src/week34/week34.do.txt b/doc/src/week34/week34.do.txt index 524fcd24e..8cf5cc504 100644 --- a/doc/src/week34/week34.do.txt +++ b/doc/src/week34/week34.do.txt @@ -124,8 +124,8 @@ _Teachers :_ !bblock o Project 1: October 11 (available September 10) graded with feedback) -o Project 2: November 15 (available October 12, graded with feedback) -o Project 3: December 13 (available November 8, graded with feedback) +o Project 2: November 20 (available October 12, graded with feedback) +o Project 3: December 17 (available November 13, graded with feedback) Projects are handed in using _Canvas_. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via _Canvas_.