small typos

This commit is contained in:
Morten Hjorth-Jensen
2025-09-01 14:00:15 +02:00
parent eb31c10d1c
commit 55beb4d9b8
8 changed files with 143 additions and 101 deletions
Binary file not shown.
@@ -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
},
@@ -427,7 +427,7 @@ doconce format html exercisesweek37.do.txt -->
<p>We start with a very simple function</p>
<div class="math notranslate nohighlight">
\[
\f(x)= 2-x+5x^2,
f(x)= 2-x+5x^2,
\]</div>
<p>defined for <span class="math notranslate nohighlight">\(x\in [-2,2]\)</span>. You can add noise if you wish.</p>
<p>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(&quot;Closed-form OLS coefficients:&quot;, theta_closed_form)
</div>
</div>
<p>This computes the Ridge and OLS regression coefficients directly. The identity
matrix <span class="math notranslate nohighlight">\(I\)</span> has the same size as <span class="math notranslate nohighlight">\(X^T X\)</span>. It adds <span class="math notranslate nohighlight">\(\lambda\)</span> to the diagonal of <span class="math notranslate nohighlight">\(X^T X for Ridge regression. We
then invert this matrix and multiply by \)</span>X^T y<span class="math notranslate nohighlight">\(. The result
for \)</span>\boldsymbol{\theta}<span class="math notranslate nohighlight">\( is a NumPy array of shape (n\)</span>_<span class="math notranslate nohighlight">\(features,) containing the
fitted parameters \)</span>\boldsymbol{\theta}$..</p>
matrix <span class="math notranslate nohighlight">\(I\)</span> has the same size as <span class="math notranslate nohighlight">\(X^T X\)</span>. It adds <span class="math notranslate nohighlight">\(\lambda\)</span> to the diagonal of <span class="math notranslate nohighlight">\(X^T X\)</span> for Ridge regression. We
then invert this matrix and multiply by <span class="math notranslate nohighlight">\(X^T y\)</span>. The result
for <span class="math notranslate nohighlight">\(\boldsymbol{\theta}\)</span> is a NumPy array of shape (n<span class="math notranslate nohighlight">\(\_\)</span>features,) containing the
fitted parameters <span class="math notranslate nohighlight">\(\boldsymbol{\theta}\)</span>.</p>
<section id="id1">
<h3>3a)<a class="headerlink" href="#id1" title="Link to this heading">#</a></h3>
<p>Finalize, in the above code, the OLS and Ridge regression determination of the optimal parameters <span class="math notranslate nohighlight">\(\boldsymbol{\theta}\)</span>.</p>
@@ -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
},
+28 -28
View File
@@ -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
},
+51 -9
View File
@@ -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
}
+3 -3
View File
@@ -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}$.