diff --git a/doc/pub/week35/html/week35-bs.html b/doc/pub/week35/html/week35-bs.html index fa3aac41d..e987b6f41 100644 --- a/doc/pub/week35/html/week35-bs.html +++ b/doc/pub/week35/html/week35-bs.html @@ -102,6 +102,7 @@ Automatically generated HTML file from DocOnce source 2, None, 'some-useful-matrix-and-vector-expressions'), + ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, None, @@ -177,6 +178,10 @@ Automatically generated HTML file from DocOnce source 'the-svd-a-fantastic-algorithm'), ('Economy-size SVD', 2, None, 'economy-size-svd'), ('Codes for the SVD', 2, None, 'codes-for-the-svd'), + ('Note about SVD Calculations', + 2, + None, + 'note-about-svd-calculations'), ('Mathematical Properties', 2, None, 'mathematical-properties'), ('Friday September 3', 2, None, 'friday-september-3'), ('Ridge and LASSO Regression', @@ -277,7 +282,7 @@ MathJax.Hub.Config({
  • Why Linear Regression (aka Ordinary Least Squares and family), repeat from last week
  • Regression analysis, overarching aims
  • Regression analysis, overarching aims II
  • -
  • Examples
  • +
  • Examples
  • General linear models
  • Rewriting the fitting procedure as a linear algebra problem
  • Rewriting the fitting procedure as a linear algebra problem, more details
  • @@ -286,55 +291,57 @@ MathJax.Hub.Config({
  • Optimizing our parameters
  • Our model for the nuclear binding energies
  • Optimizing our parameters, more details
  • -
  • Interpretations and optimizing our parameters
  • -
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • +
  • Interpretations and optimizing our parameters
  • Some useful matrix and vector expressions
  • -
  • Interpretations and optimizing our parameters
  • -
  • Own code for Ordinary Least Squares
  • -
  • Adding error analysis and training set up
  • -
  • Splitting our Data in Training and Test data
  • -
  • Examples
  • -
  • Making your own test-train splitting
  • -
  • The Boston housing data example
  • -
  • Housing data, the code
  • -
  • Reducing the number of degrees of freedom, overarching view
  • -
  • Preprocessing our data
  • -
  • Functionality in Scikit-Learn
  • -
  • More preprocessing
  • -
  • Frequently used scaling functions
  • -
  • Example of own Standard scaling
  • -
  • Min-Max Scaling
  • -
  • Testing the Means Squared Error as function of Complexity
  • -
  • More preprocessing examples, Franke function and regression
  • -
  • Mathematical Interpretation of Ordinary Least Squares
  • -
  • Residual Error
  • -
  • Simple case
  • -
  • The singular value decomposition
  • -
  • Linear Regression Problems
  • -
  • Fixing the singularity
  • -
  • Basic math of the SVD
  • -
  • The SVD, a Fantastic Algorithm
  • -
  • Economy-size SVD
  • -
  • Codes for the SVD
  • -
  • Mathematical Properties
  • -
  • Friday September 3
  • -
  • Ridge and LASSO Regression
  • -
  • More on Ridge Regression
  • -
  • Interpreting the Ridge results
  • -
  • More interpretations
  • -
  • A better understanding of regularization
  • -
  • Decomposing the OLS and Ridge expressions
  • -
  • Introducing the Covariance and Correlation functions
  • -
  • Correlation Function and Design/Feature Matrix
  • -
  • Covariance Matrix Examples
  • -
  • Correlation Matrix
  • -
  • Correlation Matrix with Pandas
  • -
  • Correlation Matrix with Pandas and the Franke function
  • -
  • Rewriting the Covariance and/or Correlation Matrix
  • -
  • Linking with SVD
  • -
  • Exercises for week 37, September 6-10
  • -
  • Exercise 1: Adding Ridge and Lasso Regression
  • -
  •    Exercise: Linear Regression for a two-dimensional function
  • +
  • Meet the Hessian Matrix
  • +
  • Interpretations and optimizing our parameters
  • +
  • Own code for Ordinary Least Squares
  • +
  • Adding error analysis and training set up
  • +
  • Splitting our Data in Training and Test data
  • +
  • Examples
  • +
  • Making your own test-train splitting
  • +
  • The Boston housing data example
  • +
  • Housing data, the code
  • +
  • Reducing the number of degrees of freedom, overarching view
  • +
  • Preprocessing our data
  • +
  • Functionality in Scikit-Learn
  • +
  • More preprocessing
  • +
  • Frequently used scaling functions
  • +
  • Example of own Standard scaling
  • +
  • Min-Max Scaling
  • +
  • Testing the Means Squared Error as function of Complexity
  • +
  • More preprocessing examples, Franke function and regression
  • +
  • Mathematical Interpretation of Ordinary Least Squares
  • +
  • Residual Error
  • +
  • Simple case
  • +
  • The singular value decomposition
  • +
  • Linear Regression Problems
  • +
  • Fixing the singularity
  • +
  • Basic math of the SVD
  • +
  • The SVD, a Fantastic Algorithm
  • +
  • Economy-size SVD
  • +
  • Codes for the SVD
  • +
  • Note about SVD Calculations
  • +
  • Mathematical Properties
  • +
  • Friday September 3
  • +
  • Ridge and LASSO Regression
  • +
  • More on Ridge Regression
  • +
  • Interpreting the Ridge results
  • +
  • More interpretations
  • +
  • A better understanding of regularization
  • +
  • Decomposing the OLS and Ridge expressions
  • +
  • Introducing the Covariance and Correlation functions
  • +
  • Correlation Function and Design/Feature Matrix
  • +
  • Covariance Matrix Examples
  • +
  • Correlation Matrix
  • +
  • Correlation Matrix with Pandas
  • +
  • Correlation Matrix with Pandas and the Franke function
  • +
  • Rewriting the Covariance and/or Correlation Matrix
  • +
  • Linking with SVD
  • +
  • Exercises for week 37, September 6-10
  • +
  • Exercise 1: Adding Ridge and Lasso Regression
  • +
  •    Exercise: Linear Regression for a two-dimensional function
  • @@ -393,7 +400,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 62
  • +
  • 64
  • »
  • diff --git a/doc/pub/week35/html/week35-reveal.html b/doc/pub/week35/html/week35-reveal.html index 909d2dda7..f4696fca1 100644 --- a/doc/pub/week35/html/week35-reveal.html +++ b/doc/pub/week35/html/week35-reveal.html @@ -762,6 +762,37 @@ $$ +
    +

    Meet the Hessian Matrix

    + +

    +A very important matrix we will meet again and again in Machine Learning is the Hessian. +It is given by the second derivative of the cost function with respect to the parameter \( \beta \). Using the above expression for derivatives of vectors and matrices, we find that the second derivative of the cost function is, + +

     
    +$$ +\frac{\partial}{\partial \boldsymbol{\beta}^T}\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} =\frac{\partial}{\partial \boldsymbol{\beta}^T}\left[-\frac{2}{n}\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right]=\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +$$ +

     
    + +

    +The Hessian matrix plays an important role and is defined here as + +

     
    +$$ +\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +$$ +

     
    + +

    +For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters +\( \hat{\boldsymbol{\beta}} \). Furthermore, we will see later this week that is (beside \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning problem. + +

    +Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!). +

    + +

    Interpretations and optimizing our parameters

    @@ -1906,6 +1937,26 @@ in the program terminating due to a singular matrix.
    +
    +

    Note about SVD Calculations

    + +

    +The \( U \), \( S \), and \( V \) matrices returned from the svd() function +cannot be multiplied directly. + +

    +As you can see from the code, the \( S \) +vector must be converted into a diagonal matrix. This may cause a +as +the size of the matrices do not fit the rules of matrix +multiplication, where the number of columns in a matrix must match the +number of rows in the subsequent matrix. + +

    +If you wish to include the zero singular values, you will need to resize the matrices. More about this later. +

    + +

    Mathematical Properties

    diff --git a/doc/pub/week35/html/week35-solarized.html b/doc/pub/week35/html/week35-solarized.html index 8b910e2dd..5acb5fd82 100644 --- a/doc/pub/week35/html/week35-solarized.html +++ b/doc/pub/week35/html/week35-solarized.html @@ -122,6 +122,7 @@ div { text-align: justify; text-justify: inter-word; } 2, None, 'some-useful-matrix-and-vector-expressions'), + ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, None, @@ -197,6 +198,10 @@ div { text-align: justify; text-justify: inter-word; } 'the-svd-a-fantastic-algorithm'), ('Economy-size SVD', 2, None, 'economy-size-svd'), ('Codes for the SVD', 2, None, 'codes-for-the-svd'), + ('Note about SVD Calculations', + 2, + None, + 'note-about-svd-calculations'), ('Mathematical Properties', 2, None, 'mathematical-properties'), ('Friday September 3', 2, None, 'friday-september-3'), ('Ridge and LASSO Regression', @@ -862,6 +867,33 @@ $$











    +

    Meet the Hessian Matrix

    + +

    +A very important matrix we will meet again and again in Machine Learning is the Hessian. +It is given by the second derivative of the cost function with respect to the parameter \( \beta \). Using the above expression for derivatives of vectors and matrices, we find that the second derivative of the cost function is, + +$$ +\frac{\partial}{\partial \boldsymbol{\beta}^T}\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} =\frac{\partial}{\partial \boldsymbol{\beta}^T}\left[-\frac{2}{n}\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right]=\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    +The Hessian matrix plays an important role and is defined here as + +$$ +\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    +For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters +\( \hat{\boldsymbol{\beta}} \). Furthermore, we will see later this week that is (beside \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning problem. + +

    +Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!). + +

    +









    +

    Interpretations and optimizing our parameters

    @@ -1967,6 +1999,26 @@ in the program terminating due to a singular matrix.











    +

    Note about SVD Calculations

    + +

    +The \( U \), \( S \), and \( V \) matrices returned from the svd() function +cannot be multiplied directly. + +

    +As you can see from the code, the \( S \) +vector must be converted into a diagonal matrix. This may cause a +as +the size of the matrices do not fit the rules of matrix +multiplication, where the number of columns in a matrix must match the +number of rows in the subsequent matrix. + +

    +If you wish to include the zero singular values, you will need to resize the matrices. More about this later. + +

    +









    +

    Mathematical Properties

    diff --git a/doc/pub/week35/html/week35.html b/doc/pub/week35/html/week35.html index 86ba19579..258737935 100644 --- a/doc/pub/week35/html/week35.html +++ b/doc/pub/week35/html/week35.html @@ -127,6 +127,7 @@ div { text-align: justify; text-justify: inter-word; } 2, None, 'some-useful-matrix-and-vector-expressions'), + ('Meet the Hessian Matrix', 2, None, 'meet-the-hessian-matrix'), ('Interpretations and optimizing our parameters', 2, None, @@ -202,6 +203,10 @@ div { text-align: justify; text-justify: inter-word; } 'the-svd-a-fantastic-algorithm'), ('Economy-size SVD', 2, None, 'economy-size-svd'), ('Codes for the SVD', 2, None, 'codes-for-the-svd'), + ('Note about SVD Calculations', + 2, + None, + 'note-about-svd-calculations'), ('Mathematical Properties', 2, None, 'mathematical-properties'), ('Friday September 3', 2, None, 'friday-september-3'), ('Ridge and LASSO Regression', @@ -867,6 +872,33 @@ $$











    +

    Meet the Hessian Matrix

    + +

    +A very important matrix we will meet again and again in Machine Learning is the Hessian. +It is given by the second derivative of the cost function with respect to the parameter \( \beta \). Using the above expression for derivatives of vectors and matrices, we find that the second derivative of the cost function is, + +$$ +\frac{\partial}{\partial \boldsymbol{\beta}^T}\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} =\frac{\partial}{\partial \boldsymbol{\beta}^T}\left[-\frac{2}{n}\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right]=\frac{2}{n}\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    +The Hessian matrix plays an important role and is defined here as + +$$ +\boldsymbol{H}=\boldsymbol{X}^T\boldsymbol{X}. +$$ + +

    +For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters +\( \hat{\boldsymbol{\beta}} \). Furthermore, we will see later this week that is (beside \( 1/n \)) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning problem. + +

    +Linear algebra question: Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!). + +

    +









    +

    Interpretations and optimizing our parameters

    @@ -1972,6 +2004,26 @@ in the program terminating due to a singular matrix.











    +

    Note about SVD Calculations

    + +

    +The \( U \), \( S \), and \( V \) matrices returned from the svd() function +cannot be multiplied directly. + +

    +As you can see from the code, the \( S \) +vector must be converted into a diagonal matrix. This may cause a +as +the size of the matrices do not fit the rules of matrix +multiplication, where the number of columns in a matrix must match the +number of rows in the subsequent matrix. + +

    +If you wish to include the zero singular values, you will need to resize the matrices. More about this later. + +

    +









    +

    Mathematical Properties

    diff --git a/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz b/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz index 91a436d1e..079540bef 100644 Binary files a/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz and b/doc/pub/week35/ipynb/ipynb-week35-src.tar.gz differ diff --git a/doc/pub/week35/ipynb/week35.ipynb b/doc/pub/week35/ipynb/week35.ipynb index 73ef692d9..a1102bae4 100644 --- a/doc/pub/week35/ipynb/week35.ipynb +++ b/doc/pub/week35/ipynb/week35.ipynb @@ -841,6 +841,46 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "## Meet the Hessian Matrix\n", + "\n", + "A very important matrix we will meet again and again in Machine Learning is the Hessian.\n", + "It is given by the second derivative of the cost function with respect to the parameter $\\beta$. Using the above expression for derivatives of vectors and matrices, we find that the second derivative of the cost function is," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\frac{\\partial}{\\partial \\boldsymbol{\\beta}^T}\\frac{\\partial C(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta}} =\\frac{\\partial}{\\partial \\boldsymbol{\\beta}^T}\\left[-\\frac{2}{n}\\boldsymbol{X}^T\\left( \\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\beta}\\right)\\right]=\\frac{2}{n}\\boldsymbol{X}^T\\boldsymbol{X}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The Hessian matrix plays an important role and is defined here as" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\boldsymbol{H}=\\boldsymbol{X}^T\\boldsymbol{X}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters\n", + "$\\hat{\\boldsymbol{\\beta}}$. Furthermore, we will see later this week that is (beside $1/n$) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning problem.\n", + "\n", + "**Linear algebra question:** Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!). \n", + "\n", "## Interpretations and optimizing our parameters\n", "The residuals $\\boldsymbol{\\epsilon}$ are in turn given by" ] @@ -2360,6 +2400,21 @@ "in the program terminating due to a singular matrix.\n", "\n", "\n", + "## Note about SVD Calculations\n", + "\n", + "The $U$, $S$, and $V$ matrices returned from the **svd()** function\n", + "cannot be multiplied directly.\n", + "\n", + "As you can see from the code, the $S$\n", + "vector must be converted into a diagonal matrix. This may cause a \n", + "as\n", + "the size of the matrices do not fit the rules of matrix\n", + "multiplication, where the number of columns in a matrix must match the\n", + "number of rows in the subsequent matrix.\n", + "\n", + "If you wish to include the zero singular values, you will need to resize the matrices. More about this later.\n", + "\n", + "\n", "\n", "## Mathematical Properties\n", "\n", diff --git a/doc/src/week35/week35.do.txt b/doc/src/week35/week35.do.txt index ba241260d..bca18e8b5 100644 --- a/doc/src/week35/week35.do.txt +++ b/doc/src/week35/week35.do.txt @@ -503,6 +503,33 @@ matrices as upper case boldfaced letters. \] !et +!split +===== Meet the Hessian Matrix ===== + +A very important matrix we will meet again and again in Machine Learning is the Hessian. +It is given by the second derivative of the cost function with respect to the parameter $\beta$. Using the above expression for derivatives of vectors and matrices, we find that the second derivative of the cost function is, + +!bt +\[ +\frac{\partial}{\partial \bm{\beta}^T}\frac{\partial C(\bm{\beta})}{\partial \bm{\beta}} =\frac{\partial}{\partial \bm{\beta}^T}\left[-\frac{2}{n}\bm{X}^T\left( \bm{y}-\bm{X}\bm{\beta}\right)\right]=\frac{2}{n}\bm{X}^T\bm{X}. +\] +!et + + +The Hessian matrix plays an important role and is defined here as + +!bt +\[ +\bm{H}=\bm{X}^T\bm{X}. +\] +!et + + +For ordinary least squares, it is inversely proportional (derivation next week) with the variance of the optimal parameters +$\hat{\bm{\beta}}$. Furthermore, we will see later this week that is (beside $1/n$) equal to the covariance matrix. It plays also a very important role in optmization algorithms and Principal Component Analysis as a way to reduce the dimensionality of a machine learning problem. + +_Linear algebra question:_ Can we use the Hessian matrix to say something about properties of the cost function (our optmization problem)? (hint: think about convex or concave problems and how to relate these to a matrix!). + !split ===== Interpretations and optimizing our parameters ===== !bblock @@ -1483,6 +1510,22 @@ inversion algorithm for matrix inversion with $\bm{X}^T\bm{X}$ results in the program terminating due to a singular matrix. +!split +===== Note about SVD Calculations ===== + +The $U$, $S$, and $V$ matrices returned from the _svd()_ function +cannot be multiplied directly. + +As you can see from the code, the $S$ +vector must be converted into a diagonal matrix. This may cause a +as +the size of the matrices do not fit the rules of matrix +multiplication, where the number of columns in a matrix must match the +number of rows in the subsequent matrix. + +If you wish to include the zero singular values, you will need to resize the matrices. More about this later. + + !split ===== Mathematical Properties =====