From d35fa373a3a426e23ca599ce86ed86b9c6f68a70 Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Fri, 27 Aug 2021 07:06:06 +0200 Subject: [PATCH] removing hat symbols --- doc/pub/week34/html/._week34-bs000.html | 2 +- doc/pub/week34/html/._week34-bs035.html | 14 +++--- doc/pub/week34/html/._week34-bs038.html | 20 ++++----- doc/pub/week34/html/._week34-bs066.html | 8 ++-- doc/pub/week34/html/week34-bs.html | 2 +- doc/pub/week34/html/week34-reveal.html | 44 +++++++++---------- doc/pub/week34/html/week34-solarized.html | 44 +++++++++---------- doc/pub/week34/html/week34.html | 44 +++++++++---------- doc/pub/week34/ipynb/ipynb-week34-src.tar.gz | Bin 103349 -> 103349 bytes doc/pub/week34/ipynb/week34.ipynb | 44 +++++++++---------- doc/src/week34/week34.do.txt | 42 +++++++++--------- 11 files changed, 132 insertions(+), 132 deletions(-) diff --git a/doc/pub/week34/html/._week34-bs000.html b/doc/pub/week34/html/._week34-bs000.html index 81bc34baf..92b2c270b 100644 --- a/doc/pub/week34/html/._week34-bs000.html +++ b/doc/pub/week34/html/._week34-bs000.html @@ -384,7 +384,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

-

Aug 26, 2021

+

Aug 27, 2021


diff --git a/doc/pub/week34/html/._week34-bs035.html b/doc/pub/week34/html/._week34-bs035.html index 95f58a404..8649470bd 100644 --- a/doc/pub/week34/html/._week34-bs035.html +++ b/doc/pub/week34/html/._week34-bs035.html @@ -369,7 +369,7 @@ MathJax.Hub.Config({

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

@@ -435,9 +435,9 @@ A = np.r

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 -\( \hat{x}, \hat{y}, \hat{z} \) with \( n \) elements each. The covariance matrix is defined as +\( \boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z} \) with \( n \) elements each. The covariance matrix is defined as $$ -\hat{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ +\boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ \sigma_{zx} & \sigma_{zy} & \sigma_{zz} \end{bmatrix}, @@ -449,9 +449,9 @@ $$ $$ 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 \( \hat{W} \) +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} \) $$ -\hat{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ +\boldsymbol{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ x_1 & y_1 & z_1 \\ x_2 & y_2 & z_2 \\ \dots & \dots & \dots \\ @@ -462,8 +462,8 @@ $$

which in turn is converted into into the \( 3\times 3 \) covariance matrix -\( \hat{\Sigma} \) via the Numpy function np.cov(). We note that we can also calculate -the mean value of each set of samples \( \hat{x} \) etc using the Numpy +\( \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. diff --git a/doc/pub/week34/html/._week34-bs038.html b/doc/pub/week34/html/._week34-bs038.html index 31ba24649..ee1073033 100644 --- a/doc/pub/week34/html/._week34-bs038.html +++ b/doc/pub/week34/html/._week34-bs038.html @@ -373,7 +373,7 @@ We start with perhaps our simplest possible example, using Scikit-Learn t

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 \( \hat{x} \) are given +The numbers in the vector \( \boldsymbol{x} \) are given by random numbers generated with a uniform distribution with entries \( x_i \in [0,1] \) (more about probability distribution functions later). These values are then used to define a function \( y(x) \) @@ -400,7 +400,7 @@ 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 -data \( (\hat{x},\hat{y}) \) for our training data. The Python package +data \( (\boldsymbol{x},\boldsymbol{y}) \) for our training data. The Python package 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. @@ -499,7 +499,7 @@ There are many ways to define the cost function. A simpler approach is to look a the relative error (why would we prefer the MSE instead of the relative error?) as $$ -\epsilon_{\mathrm{relative}}= \frac{\vert \hat{y} -\hat{\tilde{y}}\vert}{\vert \hat{y}\vert}. +\epsilon_{\mathrm{relative}}= \frac{\vert \boldsymbol{y} -\boldsymbol{\tilde{y}}\vert}{\vert \boldsymbol{y}\vert}. $$

@@ -581,7 +581,7 @@ plt.show()

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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ @@ -595,16 +595,16 @@ 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 \( \hat{y} \), +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{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. $$ @@ -613,13 +613,13 @@ Another quantity taht we will meet again in our discussions of regression analys 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}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. +\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 squared logarithmic (quadratic) error $$ -\text{MSLE}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, +\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, $$

diff --git a/doc/pub/week34/html/._week34-bs066.html b/doc/pub/week34/html/._week34-bs066.html index fc5c45c6b..5e3e40188 100644 --- a/doc/pub/week34/html/._week34-bs066.html +++ b/doc/pub/week34/html/._week34-bs066.html @@ -473,17 +473,17 @@ y = 2.0+5* 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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ 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. -If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. $$ diff --git a/doc/pub/week34/html/week34-bs.html b/doc/pub/week34/html/week34-bs.html index 81bc34baf..92b2c270b 100644 --- a/doc/pub/week34/html/week34-bs.html +++ b/doc/pub/week34/html/week34-bs.html @@ -384,7 +384,7 @@ MathJax.Hub.Config({

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

-

Aug 26, 2021

+

Aug 27, 2021


diff --git a/doc/pub/week34/html/week34-reveal.html b/doc/pub/week34/html/week34-reveal.html index 390a620c3..3a2da7cec 100644 --- a/doc/pub/week34/html/week34-reveal.html +++ b/doc/pub/week34/html/week34-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({

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

 
-

Aug 26, 2021

+

Aug 27, 2021


@@ -1170,7 +1170,7 @@ x = np.log(np.array([4.0, 2.0+5

  • 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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ 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. -If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. diff --git a/doc/pub/week34/html/week34-solarized.html b/doc/pub/week34/html/week34-solarized.html index 08191ef55..fb074240f 100644 --- a/doc/pub/week34/html/week34-solarized.html +++ b/doc/pub/week34/html/week34-solarized.html @@ -300,7 +300,7 @@ MathJax.Hub.Config({

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

    -

    Aug 26, 2021

    +

    Aug 27, 2021












    @@ -1280,7 +1280,7 @@ x = np.log(np.array([4.0, 2.0+5 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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ 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. -If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. $$ diff --git a/doc/pub/week34/html/week34.html b/doc/pub/week34/html/week34.html index c2f7fa037..2c5788986 100644 --- a/doc/pub/week34/html/week34.html +++ b/doc/pub/week34/html/week34.html @@ -305,7 +305,7 @@ MathJax.Hub.Config({

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

    -

    Aug 26, 2021

    +

    Aug 27, 2021












    @@ -1285,7 +1285,7 @@ x = np.l

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

    @@ -1351,9 +1351,9 @@ A = np.r

    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 -\( \hat{x}, \hat{y}, \hat{z} \) with \( n \) elements each. The covariance matrix is defined as +\( \boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z} \) with \( n \) elements each. The covariance matrix is defined as $$ -\hat{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ +\boldsymbol{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ \sigma_{zx} & \sigma_{zy} & \sigma_{zz} \end{bmatrix}, @@ -1365,9 +1365,9 @@ $$ $$ 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 \( \hat{W} \) +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} \) $$ -\hat{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ +\boldsymbol{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ x_1 & y_1 & z_1 \\ x_2 & y_2 & z_2 \\ \dots & \dots & \dots \\ @@ -1378,8 +1378,8 @@ $$

    which in turn is converted into into the \( 3\times 3 \) covariance matrix -\( \hat{\Sigma} \) via the Numpy function np.cov(). We note that we can also calculate -the mean value of each set of samples \( \hat{x} \) etc using the Numpy +\( \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. @@ -1564,7 +1564,7 @@ We start with perhaps our simplest possible example, using Scikit-Learn t

    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 \( \hat{x} \) are given +The numbers in the vector \( \boldsymbol{x} \) are given by random numbers generated with a uniform distribution with entries \( x_i \in [0,1] \) (more about probability distribution functions later). These values are then used to define a function \( y(x) \) @@ -1591,7 +1591,7 @@ 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 -data \( (\hat{x},\hat{y}) \) for our training data. The Python package +data \( (\boldsymbol{x},\boldsymbol{y}) \) for our training data. The Python package 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. @@ -1690,7 +1690,7 @@ There are many ways to define the cost function. A simpler approach is to look a the relative error (why would we prefer the MSE instead of the relative error?) as $$ -\epsilon_{\mathrm{relative}}= \frac{\vert \hat{y} -\hat{\tilde{y}}\vert}{\vert \hat{y}\vert}. +\epsilon_{\mathrm{relative}}= \frac{\vert \boldsymbol{y} -\boldsymbol{\tilde{y}}\vert}{\vert \boldsymbol{y}\vert}. $$

    @@ -1772,7 +1772,7 @@ plt.show()

    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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ MSE(\boldsymbol{y},\boldsymbol{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, $$ @@ -1786,16 +1786,16 @@ 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 \( \hat{y} \), +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{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. $$ @@ -1804,13 +1804,13 @@ Another quantity taht we will meet again in our discussions of regression analys 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}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. +\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 squared logarithmic (quadratic) error $$ -\text{MSLE}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, +\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, $$

    @@ -3399,17 +3399,17 @@ y = 2.0+5* 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(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +$$ 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. -If \( \tilde{\hat{y}}_i \) is the predicted value of the \( i-th \) sample and \( y_i \) is the corresponding true value, then the score \( R^2 \) is defined as +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(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +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 \( \hat{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. $$ diff --git a/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz b/doc/pub/week34/ipynb/ipynb-week34-src.tar.gz index 849ae396efb12c6d285162ab0359e36be6eef40e..e3b48e526341d917934e4f7d1d9913233e4cece8 100644 GIT binary patch delta 21 dcmdnGoNeoJHg@@L4u+LQ8jb8**%{YO1^`n_2S)$^ delta 21 dcmdnGoNeoJHg@@L4u<|6>W%DM*%{YO1^`sG2XX)a diff --git a/doc/pub/week34/ipynb/week34.ipynb b/doc/pub/week34/ipynb/week34.ipynb index a78310b0a..5f52865d4 100644 --- a/doc/pub/week34/ipynb/week34.ipynb +++ b/doc/pub/week34/ipynb/week34.ipynb @@ -10,7 +10,7 @@ " \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: **Aug 26, 2021**\n", + "Date: **Aug 27, 2021**\n", "\n", "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", @@ -994,7 +994,7 @@ "## Matrices in Python\n", "\n", "Having defined vectors, we are now ready to try out matrices. We can\n", - "define a $3 \\times 3 $ real matrix $\\hat{A}$ as (recall that we user\n", + "define a $3 \\times 3 $ real matrix $\\boldsymbol{A}$ as (recall that we user\n", "lowercase letters for vectors and uppercase letters for matrices)" ] }, @@ -1131,7 +1131,7 @@ "source": [ "As we will see throughout these lectures, there are several extremely useful functionalities in Numpy.\n", "As an example, consider the discussion of the covariance matrix. Suppose we have defined three vectors\n", - "$\\hat{x}, \\hat{y}, \\hat{z}$ with $n$ elements each. The covariance matrix is defined as" + "$\\boldsymbol{x}, \\boldsymbol{y}, \\boldsymbol{z}$ with $n$ elements each. The covariance matrix is defined as" ] }, { @@ -1139,7 +1139,7 @@ "metadata": {}, "source": [ "$$\n", - "\\hat{\\Sigma} = \\begin{bmatrix} \\sigma_{xx} & \\sigma_{xy} & \\sigma_{xz} \\\\\n", + "\\boldsymbol{\\Sigma} = \\begin{bmatrix} \\sigma_{xx} & \\sigma_{xy} & \\sigma_{xz} \\\\\n", " \\sigma_{yx} & \\sigma_{yy} & \\sigma_{yz} \\\\\n", " \\sigma_{zx} & \\sigma_{zy} & \\sigma_{zz} \n", " \\end{bmatrix},\n", @@ -1167,7 +1167,7 @@ "metadata": {}, "source": [ "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. \n", - "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 $\\hat{W}$" + "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}$" ] }, { @@ -1175,7 +1175,7 @@ "metadata": {}, "source": [ "$$\n", - "\\hat{W} = \\begin{bmatrix} x_0 & y_0 & z_0 \\\\\n", + "\\boldsymbol{W} = \\begin{bmatrix} x_0 & y_0 & z_0 \\\\\n", " x_1 & y_1 & z_1 \\\\\n", " x_2 & y_2 & z_2 \\\\\n", " \\dots & \\dots & \\dots \\\\\n", @@ -1190,8 +1190,8 @@ "metadata": {}, "source": [ "which in turn is converted into into the $3\\times 3$ covariance matrix\n", - "$\\hat{\\Sigma}$ via the Numpy function **np.cov()**. We note that we can also calculate\n", - "the mean value of each set of samples $\\hat{x}$ etc using the Numpy\n", + "$\\boldsymbol{\\Sigma}$ via the Numpy function **np.cov()**. We note that we can also calculate\n", + "the mean value of each set of samples $\\boldsymbol{x}$ etc using the Numpy\n", "function **np.mean(x)**. We can also extract the eigenvalues of the\n", "covariance matrix through the **np.linalg.eig()** function." ] @@ -1472,7 +1472,7 @@ "\n", "What follows is a simple Python code where we have defined a function\n", "$y$ in terms of the variable $x$. Both are defined as vectors with $100$ entries. \n", - "The numbers in the vector $\\hat{x}$ are given\n", + "The numbers in the vector $\\boldsymbol{x}$ are given\n", "by random numbers generated with a uniform distribution with entries\n", "$x_i \\in [0,1]$ (more about probability distribution functions\n", "later). These values are then used to define a function $y(x)$\n", @@ -1508,7 +1508,7 @@ "distribution. From **Scikit-Learn** we import then the\n", "**LinearRegression** functionality and make a prediction $\\tilde{y} =\n", "\\alpha + \\beta x$ using the function **fit(x,y)**. We call the set of\n", - "data $(\\hat{x},\\hat{y})$ for our training data. The Python package\n", + "data $(\\boldsymbol{x},\\boldsymbol{y})$ for our training data. The Python package\n", "**scikit-learn** has also a functionality which extracts the above\n", "fitting parameters $\\alpha$ and $\\beta$ (see below). Later we will\n", "distinguish between training data and test data.\n", @@ -1638,7 +1638,7 @@ "metadata": {}, "source": [ "$$\n", - "\\epsilon_{\\mathrm{relative}}= \\frac{\\vert \\hat{y} -\\hat{\\tilde{y}}\\vert}{\\vert \\hat{y}\\vert}.\n", + "\\epsilon_{\\mathrm{relative}}= \\frac{\\vert \\boldsymbol{y} -\\boldsymbol{\\tilde{y}}\\vert}{\\vert \\boldsymbol{y}\\vert}.\n", "$$" ] }, @@ -1752,7 +1752,7 @@ "metadata": {}, "source": [ "$$\n", - "MSE(\\hat{y},\\hat{\\tilde{y}}) = \\frac{1}{n}\n", + "MSE(\\boldsymbol{y},\\boldsymbol{\\tilde{y}}) = \\frac{1}{n}\n", "\\sum_{i=0}^{n-1}(y_i-\\tilde{y}_i)^2,\n", "$$" ] @@ -1769,10 +1769,10 @@ "determination. It provides a measure of how well future samples are\n", "likely to be predicted by the model. Best possible score is 1.0 and it\n", "can be negative (because the model can be arbitrarily worse). A\n", - "constant model that always predicts the expected value of $\\hat{y}$,\n", + "constant model that always predicts the expected value of $\\boldsymbol{y}$,\n", "disregarding the input features, would get a $R^2$ score of $0.0$.\n", "\n", - "If $\\tilde{\\hat{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as" + "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" ] }, { @@ -1780,7 +1780,7 @@ "metadata": {}, "source": [ "$$\n", - "R^2(\\hat{y}, \\tilde{\\hat{y}}) = 1 - \\frac{\\sum_{i=0}^{n - 1} (y_i - \\tilde{y}_i)^2}{\\sum_{i=0}^{n - 1} (y_i - \\bar{y})^2},\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", "$$" ] }, @@ -1788,7 +1788,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "where we have defined the mean value of $\\hat{y}$ as" + "where we have defined the mean value of $\\boldsymbol{y}$ as" ] }, { @@ -1814,7 +1814,7 @@ "metadata": {}, "source": [ "$$\n", - "\\text{MAE}(\\hat{y}, \\hat{\\tilde{y}}) = \\frac{1}{n} \\sum_{i=0}^{n-1} \\left| y_i - \\tilde{y}_i \\right|.\n", + "\\text{MAE}(\\boldsymbol{y}, \\boldsymbol{\\tilde{y}}) = \\frac{1}{n} \\sum_{i=0}^{n-1} \\left| y_i - \\tilde{y}_i \\right|.\n", "$$" ] }, @@ -1831,7 +1831,7 @@ "metadata": {}, "source": [ "$$\n", - "\\text{MSLE}(\\hat{y}, \\hat{\\tilde{y}}) = \\frac{1}{n} \\sum_{i=0}^{n - 1} (\\log_e (1 + y_i) - \\log_e (1 + \\tilde{y}_i) )^2,\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", "$$" ] }, @@ -4156,7 +4156,7 @@ "metadata": {}, "source": [ "$$\n", - "MSE(\\hat{y},\\hat{\\tilde{y}}) = \\frac{1}{n}\n", + "MSE(\\boldsymbol{y},\\boldsymbol{\\tilde{y}}) = \\frac{1}{n}\n", "\\sum_{i=0}^{n-1}(y_i-\\tilde{y}_i)^2,\n", "$$" ] @@ -4166,7 +4166,7 @@ "metadata": {}, "source": [ "and the $R^2$ score function.\n", - "If $\\tilde{\\hat{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as" + "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" ] }, { @@ -4174,7 +4174,7 @@ "metadata": {}, "source": [ "$$\n", - "R^2(\\hat{y}, \\tilde{\\hat{y}}) = 1 - \\frac{\\sum_{i=0}^{n - 1} (y_i - \\tilde{y}_i)^2}{\\sum_{i=0}^{n - 1} (y_i - \\bar{y})^2},\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", "$$" ] }, @@ -4182,7 +4182,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "where we have defined the mean value of $\\hat{y}$ as" + "where we have defined the mean value of $\\boldsymbol{y}$ as" ] }, { diff --git a/doc/src/week34/week34.do.txt b/doc/src/week34/week34.do.txt index cc22402f2..39c829685 100644 --- a/doc/src/week34/week34.do.txt +++ b/doc/src/week34/week34.do.txt @@ -786,7 +786,7 @@ print(x.itemsize) ===== Matrices in Python ===== Having defined vectors, we are now ready to try out matrices. We can -define a $3 \times 3 $ real matrix $\hat{A}$ as (recall that we user +define a $3 \times 3 $ real matrix $\bm{A}$ as (recall that we user lowercase letters for vectors and uppercase letters for matrices) !bc pycod @@ -835,10 +835,10 @@ print(A) 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 -$\hat{x}, \hat{y}, \hat{z}$ with $n$ elements each. The covariance matrix is defined as +$\bm{x}, \bm{y}, \bm{z}$ with $n$ elements each. The covariance matrix is defined as !bt \[ -\hat{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ +\bm{\Sigma} = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ \sigma_{zx} & \sigma_{zy} & \sigma_{zz} \end{bmatrix}, @@ -851,10 +851,10 @@ where for example \] !et 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 $\hat{W}$ +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 $\bm{W}$ !bt \[ -\hat{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ +\bm{W} = \begin{bmatrix} x_0 & y_0 & z_0 \\ x_1 & y_1 & z_1 \\ x_2 & y_2 & z_2 \\ \dots & \dots & \dots \\ @@ -865,8 +865,8 @@ The following simple function uses the _np.vstack_ function which takes each vec !et which in turn is converted into into the $3\times 3$ covariance matrix -$\hat{\Sigma}$ via the Numpy function _np.cov()_. We note that we can also calculate -the mean value of each set of samples $\hat{x}$ etc using the Numpy +$\bm{\Sigma}$ via the Numpy function _np.cov()_. We note that we can also calculate +the mean value of each set of samples $\bm{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. @@ -1026,7 +1026,7 @@ We start with perhaps our simplest possible example, using _Scikit-Learn_ to per 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 $\hat{x}$ are given +The numbers in the vector $\bm{x}$ are given by random numbers generated with a uniform distribution with entries $x_i \in [0,1]$ (more about probability distribution functions later). These values are then used to define a function $y(x)$ @@ -1054,7 +1054,7 @@ 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 -data $(\hat{x},\hat{y})$ for our training data. The Python package +data $(\bm{x},\bm{y})$ for our training data. The Python package _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. @@ -1149,7 +1149,7 @@ the relative error (why would we prefer the MSE instead of the relative error?) !bt \[ -\epsilon_{\mathrm{relative}}= \frac{\vert \hat{y} -\hat{\tilde{y}}\vert}{\vert \hat{y}\vert}. +\epsilon_{\mathrm{relative}}= \frac{\vert \bm{y} -\bm{\tilde{y}}\vert}{\vert \bm{y}\vert}. \] !et @@ -1225,7 +1225,7 @@ plt.show() 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 !bt -\[ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +\[ MSE(\bm{y},\bm{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, \] !et @@ -1238,16 +1238,16 @@ 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 $\hat{y}$, +constant model that always predicts the expected value of $\bm{y}$, disregarding the input features, would get a $R^2$ score of $0.0$. -If $\tilde{\hat{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as +If $\tilde{\bm{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as !bt \[ -R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +R^2(\bm{y}, \tilde{\bm{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, \] !et -where we have defined the mean value of $\hat{y}$ as +where we have defined the mean value of $\bm{y}$ as !bt \[ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i. @@ -1258,14 +1258,14 @@ Another quantity taht we will meet again in our discussions of regression analys The MAE is defined as follows !bt \[ -\text{MAE}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. +\text{MAE}(\bm{y}, \bm{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1} \left| y_i - \tilde{y}_i \right|. \] !et We present the squared logarithmic (quadratic) error !bt \[ -\text{MSLE}(\hat{y}, \hat{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, +\text{MSLE}(\bm{y}, \bm{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n - 1} (\log_e (1 + y_i) - \log_e (1 + \tilde{y}_i) )^2, \] !et @@ -2723,18 +2723,18 @@ o Write your own code (following the examples under the "regression notes":"http o Use thereafter _scikit-learn_ (see again the examples in the regression slides) and compare with your own code. o Using scikit-learn, compute also the mean square error, a risk metric corresponding to the expected value of the squared (quadratic) error defined as !bt -\[ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n} +\[ MSE(\bm{y},\bm{\tilde{y}}) = \frac{1}{n} \sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2, \] !et and the $R^2$ score function. -If $\tilde{\hat{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as +If $\tilde{\bm{y}}_i$ is the predicted value of the $i-th$ sample and $y_i$ is the corresponding true value, then the score $R^2$ is defined as !bt \[ -R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, +R^2(\bm{y}, \tilde{\bm{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2}, \] !et -where we have defined the mean value of $\hat{y}$ as +where we have defined the mean value of $\bm{y}$ as !bt \[ \bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.