diff --git a/doc/LectureNotes/_build/.doctrees/environment.pickle b/doc/LectureNotes/_build/.doctrees/environment.pickle index ad5f50be0..9dca30190 100644 Binary files a/doc/LectureNotes/_build/.doctrees/environment.pickle and b/doc/LectureNotes/_build/.doctrees/environment.pickle differ diff --git a/doc/LectureNotes/_build/.doctrees/exercisesweek37.doctree b/doc/LectureNotes/_build/.doctrees/exercisesweek37.doctree index 287986c75..7553c68ab 100644 Binary files a/doc/LectureNotes/_build/.doctrees/exercisesweek37.doctree and b/doc/LectureNotes/_build/.doctrees/exercisesweek37.doctree differ diff --git a/doc/LectureNotes/_build/html/_sources/exercisesweek37.ipynb b/doc/LectureNotes/_build/html/_sources/exercisesweek37.ipynb index a23fb43b2..933c27090 100644 --- a/doc/LectureNotes/_build/html/_sources/exercisesweek37.ipynb +++ b/doc/LectureNotes/_build/html/_sources/exercisesweek37.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b0268cb1", + "id": "9b0bb122", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "700a1d0b", + "id": "48cf6ad1", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "dbe5809a", + "id": "3765446f", "metadata": { "editable": true }, @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "ac99e9c0", + "id": "82ccb1c9", "metadata": { "editable": true }, @@ -58,19 +58,19 @@ }, { "cell_type": "markdown", - "id": "6d71a32d", + "id": "2d9c0494", "metadata": { "editable": true }, "source": [ "$$\n", - "\\f(x)= 2-x+5x^2,\n", + "f(x)= 2-x+5x^2,\n", "$$" ] }, { "cell_type": "markdown", - "id": "c6496768", + "id": "df88ac02", "metadata": { "editable": true }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "24678181", + "id": "ce2e4a69", "metadata": { "editable": true }, @@ -99,7 +99,7 @@ }, { "cell_type": "markdown", - "id": "6b1bd90a", + "id": "294f41ac", "metadata": { "editable": true }, @@ -120,7 +120,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "5e751a16", + "id": "9c98b0d9", "metadata": { "collapsed": false, "editable": true @@ -140,7 +140,7 @@ }, { "cell_type": "markdown", - "id": "50a68a52", + "id": "802cf96b", "metadata": { "editable": true }, @@ -156,7 +156,7 @@ }, { "cell_type": "markdown", - "id": "db74a970", + "id": "90164acc", "metadata": { "editable": true }, @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "f8feaa49", + "id": "55d1c701", "metadata": { "editable": true }, @@ -179,7 +179,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "e6eca7a7", + "id": "22b80fe2", "metadata": { "collapsed": false, "editable": true @@ -200,21 +200,21 @@ }, { "cell_type": "markdown", - "id": "a2dff0cf", + "id": "a0a8a8ec", "metadata": { "editable": true }, "source": [ "This computes the Ridge and OLS regression coefficients directly. The identity\n", - "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X for Ridge regression. We\n", + "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X$ for Ridge regression. We\n", "then invert this matrix and multiply by $X^T y$. The result\n", "for $\\boldsymbol{\\theta}$ is a NumPy array of shape (n$\\_$features,) containing the\n", - "fitted parameters $\\boldsymbol{\\theta}$.." + "fitted parameters $\\boldsymbol{\\theta}$." ] }, { "cell_type": "markdown", - "id": "d7542c3e", + "id": "8e317939", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "b922fd54", + "id": "7b52e9af", "metadata": { "editable": true }, @@ -238,7 +238,7 @@ }, { "cell_type": "markdown", - "id": "92268a9a", + "id": "ba0b5a80", "metadata": { "editable": true }, @@ -258,7 +258,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "81660fa3", + "id": "e29c2842", "metadata": { "collapsed": false, "editable": true @@ -301,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "95149551", + "id": "9dc52b0e", "metadata": { "editable": true }, @@ -313,7 +313,7 @@ }, { "cell_type": "markdown", - "id": "09b5400e", + "id": "4584ce15", "metadata": { "editable": true }, @@ -325,7 +325,7 @@ }, { "cell_type": "markdown", - "id": "c635ca9e", + "id": "2f9f5861", "metadata": { "editable": true }, @@ -351,7 +351,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "4ca4ce05", + "id": "9e336d9b", "metadata": { "collapsed": false, "editable": true @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "af39d8bc", + "id": "5afbeef2", "metadata": { "editable": true }, @@ -394,7 +394,7 @@ }, { "cell_type": "markdown", - "id": "d35d3438", + "id": "28beeaf3", "metadata": { "editable": true }, @@ -406,7 +406,7 @@ }, { "cell_type": "markdown", - "id": "b28bf122", + "id": "36ba38c1", "metadata": { "editable": true }, diff --git a/doc/LectureNotes/_build/html/exercisesweek37.html b/doc/LectureNotes/_build/html/exercisesweek37.html index 34799f577..b0a3a9843 100644 --- a/doc/LectureNotes/_build/html/exercisesweek37.html +++ b/doc/LectureNotes/_build/html/exercisesweek37.html @@ -427,7 +427,7 @@ doconce format html exercisesweek37.do.txt -->
We start with a very simple function
defined for \(x\in [-2,2]\). You can add noise if you wish.
We are going to fit this function with a polynomial ansatz. The easiest thing is to set up a second-order polynomial and see if you can fit the above function. @@ -496,10 +496,10 @@ print("Closed-form OLS coefficients:", theta_closed_form)
This computes the Ridge and OLS regression coefficients directly. The identity -matrix \(I\) has the same size as \(X^T X\). It adds \(\lambda\) to the diagonal of \(X^T X for Ridge regression. We -then invert this matrix and multiply by \)X^T y\(. The result -for \)\boldsymbol{\theta}\( is a NumPy array of shape (n\)_\(features,) containing the -fitted parameters \)\boldsymbol{\theta}$..
+matrix \(I\) has the same size as \(X^T X\). It adds \(\lambda\) to the diagonal of \(X^T X\) for Ridge regression. We +then invert this matrix and multiply by \(X^T y\). The result +for \(\boldsymbol{\theta}\) is a NumPy array of shape (n\(\_\)features,) containing the +fitted parameters \(\boldsymbol{\theta}\).Finalize, in the above code, the OLS and Ridge regression determination of the optimal parameters \(\boldsymbol{\theta}\).
diff --git a/doc/LectureNotes/_build/jupyter_execute/exercisesweek37.ipynb b/doc/LectureNotes/_build/jupyter_execute/exercisesweek37.ipynb index 4857c84a5..60de5d8c6 100644 --- a/doc/LectureNotes/_build/jupyter_execute/exercisesweek37.ipynb +++ b/doc/LectureNotes/_build/jupyter_execute/exercisesweek37.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b0268cb1", + "id": "9b0bb122", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "700a1d0b", + "id": "48cf6ad1", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "dbe5809a", + "id": "3765446f", "metadata": { "editable": true }, @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "ac99e9c0", + "id": "82ccb1c9", "metadata": { "editable": true }, @@ -58,19 +58,19 @@ }, { "cell_type": "markdown", - "id": "6d71a32d", + "id": "2d9c0494", "metadata": { "editable": true }, "source": [ "$$\n", - "\\f(x)= 2-x+5x^2,\n", + "f(x)= 2-x+5x^2,\n", "$$" ] }, { "cell_type": "markdown", - "id": "c6496768", + "id": "df88ac02", "metadata": { "editable": true }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "24678181", + "id": "ce2e4a69", "metadata": { "editable": true }, @@ -99,7 +99,7 @@ }, { "cell_type": "markdown", - "id": "6b1bd90a", + "id": "294f41ac", "metadata": { "editable": true }, @@ -120,7 +120,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "5e751a16", + "id": "9c98b0d9", "metadata": { "collapsed": false, "editable": true @@ -140,7 +140,7 @@ }, { "cell_type": "markdown", - "id": "50a68a52", + "id": "802cf96b", "metadata": { "editable": true }, @@ -156,7 +156,7 @@ }, { "cell_type": "markdown", - "id": "db74a970", + "id": "90164acc", "metadata": { "editable": true }, @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "f8feaa49", + "id": "55d1c701", "metadata": { "editable": true }, @@ -179,7 +179,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "e6eca7a7", + "id": "22b80fe2", "metadata": { "collapsed": false, "editable": true @@ -200,21 +200,21 @@ }, { "cell_type": "markdown", - "id": "a2dff0cf", + "id": "a0a8a8ec", "metadata": { "editable": true }, "source": [ "This computes the Ridge and OLS regression coefficients directly. The identity\n", - "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X for Ridge regression. We\n", + "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X$ for Ridge regression. We\n", "then invert this matrix and multiply by $X^T y$. The result\n", "for $\\boldsymbol{\\theta}$ is a NumPy array of shape (n$\\_$features,) containing the\n", - "fitted parameters $\\boldsymbol{\\theta}$.." + "fitted parameters $\\boldsymbol{\\theta}$." ] }, { "cell_type": "markdown", - "id": "d7542c3e", + "id": "8e317939", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "b922fd54", + "id": "7b52e9af", "metadata": { "editable": true }, @@ -238,7 +238,7 @@ }, { "cell_type": "markdown", - "id": "92268a9a", + "id": "ba0b5a80", "metadata": { "editable": true }, @@ -258,7 +258,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "81660fa3", + "id": "e29c2842", "metadata": { "collapsed": false, "editable": true @@ -301,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "95149551", + "id": "9dc52b0e", "metadata": { "editable": true }, @@ -313,7 +313,7 @@ }, { "cell_type": "markdown", - "id": "09b5400e", + "id": "4584ce15", "metadata": { "editable": true }, @@ -325,7 +325,7 @@ }, { "cell_type": "markdown", - "id": "c635ca9e", + "id": "2f9f5861", "metadata": { "editable": true }, @@ -351,7 +351,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "4ca4ce05", + "id": "9e336d9b", "metadata": { "collapsed": false, "editable": true @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "af39d8bc", + "id": "5afbeef2", "metadata": { "editable": true }, @@ -394,7 +394,7 @@ }, { "cell_type": "markdown", - "id": "d35d3438", + "id": "28beeaf3", "metadata": { "editable": true }, @@ -406,7 +406,7 @@ }, { "cell_type": "markdown", - "id": "b28bf122", + "id": "36ba38c1", "metadata": { "editable": true }, diff --git a/doc/LectureNotes/exercisesweek37.ipynb b/doc/LectureNotes/exercisesweek37.ipynb index a23fb43b2..933c27090 100644 --- a/doc/LectureNotes/exercisesweek37.ipynb +++ b/doc/LectureNotes/exercisesweek37.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b0268cb1", + "id": "9b0bb122", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "700a1d0b", + "id": "48cf6ad1", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "dbe5809a", + "id": "3765446f", "metadata": { "editable": true }, @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "ac99e9c0", + "id": "82ccb1c9", "metadata": { "editable": true }, @@ -58,19 +58,19 @@ }, { "cell_type": "markdown", - "id": "6d71a32d", + "id": "2d9c0494", "metadata": { "editable": true }, "source": [ "$$\n", - "\\f(x)= 2-x+5x^2,\n", + "f(x)= 2-x+5x^2,\n", "$$" ] }, { "cell_type": "markdown", - "id": "c6496768", + "id": "df88ac02", "metadata": { "editable": true }, @@ -83,7 +83,7 @@ }, { "cell_type": "markdown", - "id": "24678181", + "id": "ce2e4a69", "metadata": { "editable": true }, @@ -99,7 +99,7 @@ }, { "cell_type": "markdown", - "id": "6b1bd90a", + "id": "294f41ac", "metadata": { "editable": true }, @@ -120,7 +120,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "5e751a16", + "id": "9c98b0d9", "metadata": { "collapsed": false, "editable": true @@ -140,7 +140,7 @@ }, { "cell_type": "markdown", - "id": "50a68a52", + "id": "802cf96b", "metadata": { "editable": true }, @@ -156,7 +156,7 @@ }, { "cell_type": "markdown", - "id": "db74a970", + "id": "90164acc", "metadata": { "editable": true }, @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "f8feaa49", + "id": "55d1c701", "metadata": { "editable": true }, @@ -179,7 +179,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "e6eca7a7", + "id": "22b80fe2", "metadata": { "collapsed": false, "editable": true @@ -200,21 +200,21 @@ }, { "cell_type": "markdown", - "id": "a2dff0cf", + "id": "a0a8a8ec", "metadata": { "editable": true }, "source": [ "This computes the Ridge and OLS regression coefficients directly. The identity\n", - "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X for Ridge regression. We\n", + "matrix $I$ has the same size as $X^T X$. It adds $\\lambda$ to the diagonal of $X^T X$ for Ridge regression. We\n", "then invert this matrix and multiply by $X^T y$. The result\n", "for $\\boldsymbol{\\theta}$ is a NumPy array of shape (n$\\_$features,) containing the\n", - "fitted parameters $\\boldsymbol{\\theta}$.." + "fitted parameters $\\boldsymbol{\\theta}$." ] }, { "cell_type": "markdown", - "id": "d7542c3e", + "id": "8e317939", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "b922fd54", + "id": "7b52e9af", "metadata": { "editable": true }, @@ -238,7 +238,7 @@ }, { "cell_type": "markdown", - "id": "92268a9a", + "id": "ba0b5a80", "metadata": { "editable": true }, @@ -258,7 +258,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "81660fa3", + "id": "e29c2842", "metadata": { "collapsed": false, "editable": true @@ -301,7 +301,7 @@ }, { "cell_type": "markdown", - "id": "95149551", + "id": "9dc52b0e", "metadata": { "editable": true }, @@ -313,7 +313,7 @@ }, { "cell_type": "markdown", - "id": "09b5400e", + "id": "4584ce15", "metadata": { "editable": true }, @@ -325,7 +325,7 @@ }, { "cell_type": "markdown", - "id": "c635ca9e", + "id": "2f9f5861", "metadata": { "editable": true }, @@ -351,7 +351,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "4ca4ce05", + "id": "9e336d9b", "metadata": { "collapsed": false, "editable": true @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "af39d8bc", + "id": "5afbeef2", "metadata": { "editable": true }, @@ -394,7 +394,7 @@ }, { "cell_type": "markdown", - "id": "d35d3438", + "id": "28beeaf3", "metadata": { "editable": true }, @@ -406,7 +406,7 @@ }, { "cell_type": "markdown", - "id": "b28bf122", + "id": "36ba38c1", "metadata": { "editable": true }, diff --git a/doc/pub/week36/ipynb/week36.ipynb b/doc/pub/week36/ipynb/week36.ipynb index c39a730a5..9eecb9565 100644 --- a/doc/pub/week36/ipynb/week36.ipynb +++ b/doc/pub/week36/ipynb/week36.ipynb @@ -792,7 +792,10 @@ "id": "1968205f", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1112,7 +1115,10 @@ "id": "7dcfad0e", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -2775,7 +2781,10 @@ "id": "6444430a", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -3019,7 +3028,10 @@ "id": "3ad7c5f2", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -3197,7 +3209,10 @@ "id": "200aa258", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -4711,7 +4726,10 @@ "id": "7ca4918a", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -4792,7 +4810,10 @@ "id": "3b6ba6a2", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -4870,7 +4891,10 @@ "id": "3410ffb2", "metadata": { "collapsed": false, - "editable": true + "editable": true, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -4955,7 +4979,25 @@ ] } ], - "metadata": {}, + "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.15" + } + }, "nbformat": 4, "nbformat_minor": 5 } diff --git a/doc/src/week37/exercisesweek37.do.txt b/doc/src/week37/exercisesweek37.do.txt index 556724301..32dc647ea 100644 --- a/doc/src/week37/exercisesweek37.do.txt +++ b/doc/src/week37/exercisesweek37.do.txt @@ -17,7 +17,7 @@ o Scale the data properly We start with a very simple function !bt \[ -\f(x)= 2-x+5x^2, +f(x)= 2-x+5x^2, \] !et @@ -88,10 +88,10 @@ print("Closed-form OLS coefficients:", theta_closed_form) !ec This computes the Ridge and OLS regression coefficients directly. The identity -matrix $I$ has the same size as $X^T X$. It adds $\lambda$ to the diagonal of $X^T X for Ridge regression. We +matrix $I$ has the same size as $X^T X$. It adds $\lambda$ to the diagonal of $X^T X$ for Ridge regression. We then invert this matrix and multiply by $X^T y$. The result for $\bm{\theta}$ is a NumPy array of shape (n$\_$features,) containing the -fitted parameters $\bm{\theta}$.. +fitted parameters $\bm{\theta}$. === 3a) === Finalize, in the above code, the OLS and Ridge regression determination of the optimal parameters $\bm{\theta}$.