numerics-2022/Task 3/Lecture 3.ipynb

1245 lines
91 KiB
Plaintext
Raw Normal View History

2022-11-04 23:55:03 +03:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lecture 3. Projectors. Least squares problem. QR factorization."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Projectors"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* A projector is a square matrix $P$ which satisfies\n",
"$$\n",
"P^2=P\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Lets inspect the geometric meaning of a projection\n",
"![](proj.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* For any vector $v$ in $\\mathrm{range}(P)$ one has $Pv=v$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* For $S_1 = \\mathrm{range}(P)$ and $S_2=\\mathrm{null}(P)$ it is said that $P$ projects onto $S_1$ along $S_2$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Orthogonal projectors\n",
"* For orthogonal projector: $S_1\\perp S_2$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* One can show (homework) that this is equivalent to $P = P^T$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- Lets inspect the geometric meaning of an orthogonal projection\n",
"![](projorth.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Projection with orthonormal basis\n",
"* Let us consider orthogonal projection onto certain $S_1$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Let dimension of $S_1$ be $n$; $q_1,q_2,...,q_n$ form an orthonormal basis for $S_1$ and $q_{n+1},...,q_m$ form an orthonormal basis for $S_2$."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Consider \n",
"$$\n",
"Q = \\bigg[q_1\\bigg|q_2\\bigg|...\\bigg|q_n\\bigg|q_{n+1}\\bigg|...\\bigg|q_m\\bigg]\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Then:\n",
"$$\n",
"PQ = \\bigg[q_1\\bigg|q_2\\bigg|...\\bigg|q_n\\bigg|0\\bigg|...\\bigg|0\\bigg]\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
" * We thus have $Q^TPQ =\\mathrm{diag}(1,1,...,1,0,0,0)=\\Sigma$\n",
"which provides SVD decomposition ot $P$: \n",
"\n",
"$$P = Q\\Sigma Q^T$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* Reduced SVD of a projector $P$ reads:\n",
"$$\n",
"P = \\hat Q \\hat Q^T\n",
"$$\n",
"where $\\hat Q$ is not orthogonal matrix (as it is not square), but it has orthonormal columns."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Projection with an arbitrary basis \n",
"* Suppose that we want to project on a space spanned by columns of arbitrary $A$ (they are not necessarily orthonormal, but assumed to be linearly independent)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* In passing from $v$ to its orthogonal projection $y \\in \\mathrm{range}(A)$, the difference $y-v$ must be orthogonal to $\\mathrm{range}(A)$:\n",
"$A^T (Ax-v) = 0$, indeed:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](projorth2.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* If the columns of $A$ are linearly independent:\n",
"$$\n",
"x = (A^T A)^{-1}A^T v\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"* The projection is thus given by the operator\n",
"$$\n",
"P = A(A^T A)^{-1}A^T\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Linear systems\n",
"\n",
"- Linear systems appear as:\n",
"\n",
" - Linear regression problems\n",
" - Discretization of partial differential/integral equations\n",
" - At elementary steps of iterative optimization techniques"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Linear equations and matrices\n",
"A linear system of equations can be written in the form\n",
"\n",
"\\begin{align*}\n",
" &2 x + 3 y = 5\\quad &\\longrightarrow \\quad &2x + 3 y + 0 z = 5\\\\\n",
" &3 x + 2z = 4\\quad &\\longrightarrow\\quad &3 x + 0 y + 2 z = 4\\\\\n",
" &x + y = 2\\quad &\\longrightarrow\\quad & 1 x + 1 y + 0 z = 2\\\\\n",
"\\end{align*}"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Matrix form\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
"2 & 3 & 0 \\\\\n",
"3 & 0 & 2 \\\\\n",
"1 & 1 & 0 \\\\\n",
"\\end{pmatrix}\\begin{pmatrix}\n",
"x \\\\\n",
"y \\\\\n",
"z \n",
"\\end{pmatrix} = \n",
"\\begin{pmatrix}\n",
"5 \\\\\n",
"4 \\\\\n",
"2\n",
"\\end{pmatrix}\n",
"$$\n",
"\n",
"or simply\n",
"\n",
"$$ A u = b $$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Over/under determined linear systems\n",
"\n",
"If the system $Ax = b$ has\n",
"\n",
"- more equations than unknowns, it is called overdetermined system (typically no solution)\n",
"\n",
"- less equations than unknowns, it is called underdetermined system (typically many solutions)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Overdetermined linear systems\n",
"\n",
"- The number of equations is > than the number of unknowns. \n",
"\n",
"- The simplest example is linear fitting, fitting a set of 2D points by a line.\n",
"\n",
"- Then, a typical way is to minimize the residual (least squares)\n",
"\n",
"$$\\Vert A x - b \\Vert_2 \\rightarrow \\min$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"## Underdetermined linear systems\n",
"\n",
"- The number of equations is > than the number of unknowns. \n",
"\n",
"- In this case, there could be infinitely many solutions $x$\n",
"\n",
"- Typical problem in Machine Learning: employ some kind of regularization. For example, one may find the solution to $Ax=b$ with a minimal norm \n",
"$$\\Vert x \\Vert_2\\to\\min$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Example of least squares\n",
"Consider a two-dimensional example. Suppose we have a linear model \n",
"\n",
"$$y = ax + b$$\n",
"\n",
"and noisy data $(x_1, y_1), \\dots (x_n, y_n)$. Then the linear system on coefficients will look as follows\n",
"\n",
"$$\n",
"\\begin{split}\n",
"a x_1 &+ b &= y_1 \\\\\n",
"&\\vdots \\\\\n",
"a x_n &+ b &= y_n \\\\\n",
"\\end{split}\n",
"$$\n",
"\n",
"or in a matrix form\n",
"\n",
"$$\n",
"\\begin{pmatrix}\n",
"x_1 & 1 \\\\\n",
"\\vdots & \\vdots \\\\\n",
"x_n & 1 \\\\\n",
"\\end{pmatrix}\n",
"\\begin{pmatrix}\n",
"a \\\\\n",
"b\n",
"\\end{pmatrix} =\n",
"\\begin{pmatrix}\n",
"y_1 \\\\\n",
"\\vdots \\\\\n",
"y_n \\\\\n",
"\\end{pmatrix},\n",
"$$\n",
"\n",
"which represents overdetermined system."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Solving the least squares\n",
"- Suppose we need to solve\n",
"\n",
"$$ \\Vert A x - b \\Vert_2 \\rightarrow \\min_x, $$\n",
"\n",
"where $A$ is $m \\times n$, $m \\geq n$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](projorth3.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- The residual $r = A x - b$ should be orthogonal to $\\mathrm{range} A$, and\n",
"or equivalently:\n",
"$$\n",
"P b = A x,\n",
"$$\n",
"where $P$ is a projector onto the range of $A$, that is $P = A(A^T A)^{-1}A^T$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- If $A$ is of a full rank, then \n",
"$$\n",
"x = (A^T A)^{-1} A^T b\n",
"$$\n",
"- The matrix $(A^T A)^{-1} A^T$ is known as a pseudoinverse, denoted as $A^+$. Can be easily computed in numpy."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x1fdc8b5e340>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD6CAYAAAC4RRw1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAeNUlEQVR4nO3deXRV5b3/8feTEEhEMCjRC4kY2qvMQjBoLIJCvCAiELE4FH6KWnAoUkVTiBN4V2/hGqBqFf1ZxwqoVREQkaACalVQQpBUIQoImkEJ0SBDICE8948TQgKZzpQz7M9rra5lNufs8+1RPjw8+7u/21hrERGR0BMR6AJERMQzCnARkRClABcRCVEKcBGREKUAFxEJUQpwEZEQ1WiA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zo/vc9XahBHFroDv0u7ke27Zt47LLLuO8885jwIAB1TfqvPXWW1xwwQUkJSVx6aWX8uOPPwLwwQcf0KdPH/r06UNSUhJ79+5l2rRpfPTRR/Tp04e//vWvtc5fVFREhw4dqgM1ISGBdu1cF0qef/55zjnnHC6++GImTJjApEmTABg/fjyvv/569TmO/s1h3759pKam0rdvX3r16sWSJUsA1x8g3bp14/bbb6dv3758//33ZGZm0q9fP84991ymT58OwP79+xk+fDi9e/emZ8+eemqQhIW0pHg+njaYb2cNr/0ghaJN8EwqrLwPOg+EP6yDC24JufCGYFuBvzMNfsj17Tn/oxcMm+X22yZOnMhTTz3F2Wefzbp167j99ttZtWoVF110EWvXrsUYwzPPPMPDDz/MnDlzmD17Nk888QT9+/dn3759REdHM2vWLGbPns2yZctOOP/VV1/NRRddxEcffURqairjxo0jKSmJoqIipk+fTnZ2NqeccgqDBg0iKSmpwVqjo6N58803adu2Lbt37yYlJYWRI0cCkJeXx/PPP8+8efNYuXIl33zzDZ999hnWWkaOHMmHH35IcXExHTt25O233wZgz549bn9fIkEvRFoD3RFcAR4k9u3bxyeffMKYMWOqjx06dAiA/Px8rrnmGoqKiigvL6dz584A9O/fnylTpjB27FhGjx5NQkLDzf4JCQnk5eWxatUqVq1aRWpqKq+99hp79+7lkksuIS4uDoBrrrmGr7/+usFzWWu59957+fDDD4mIiKCgoKD6bwZnnXUWKSkpAKxcuZKVK1dW/4Gwb98+vvnmGwYMGMA999zD1KlTueKKKxgwILivvIu4LYRaA90RXAHuwUrZH44cOUJsbCwbN2484dfuuOMOpkyZwsiRI1mzZk31uNlp06YxfPhwli9fTkpKCu+9916jn9OqVSuGDRvGsGHDOOOMM1i8eDGpqamYelYELVq04MiRI4ArtMvLywHX8zyLi4vJzs4mKiqKxMTE6gdU1NxXt9aSkZHBLbfccsK5s7OzWb58ORkZGQwZMoQHH3yw0fpFgl4Itga6Q3vgdWjbti2dO3fmtddeA1zB98UXXwCu7YWjD2t48cUXq9+zbds2evXqxdSpU0lOTmbLli20adOm3senbdiwgcLCQsD1B8amTZs466yzuOCCC1izZg0lJSVUVFRU1wCQmJhIdnY2AEuWLKGioqK6ptNPP52oqChWr17Nzp076/zMoUOH8txzz7Fv3z4ACgoK2LVrF4WFhZx00kmMGzeOe+65hw0bNnj83YkEhSCbGugvwbUCD5ADBw7U2vKYMmUKCxYs4LbbbuPPf/4zFRUVXHvttfTu3ZsZM2YwZswY4uPjSUlJqW79e+SRR1i9ejWRkZF0796dYcOGERERQYsWLejduzfjx4/nrrvuqv6MXbt2MWHChOqtmfPPP59JkyYRHR3NjBkzuPDCC+nQoQN9+/atHnE7YcIERo0axfnnn09
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"a0 = 1; b0 = 2; n = 10\n",
"\n",
"xi = np.arange(n)\n",
"yi = a0 * xi + b0 + np.random.random(n)\n",
"A = np.hstack([xi[:,None], np.ones(n)[:,None]])\n",
"coef = np.linalg.pinv(A) @ yi\n",
"\n",
"plt.plot(xi, yi, 'o', label='$(x_i, y_i)$')\n",
"plt.plot(xi, coef[0]*xi + coef[1], label='Least Squares')\n",
"plt.legend(loc='best')"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## What happens inside pinv?\n",
"We dont know yet -- computing pseudoinverse might be tough. Let us inspect a computationally cheaper way."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Solving the linear least squares via $QR$ decomposition.\n",
"\n",
"- Any matrix can be factored into a product \n",
"$$ A = Q R$$\n",
"where $Q$ is unitary, and $R$ is upper triangular.\n",
"- Finding optimal $x$ is equivalent to solving\n",
"$$\n",
"A^T A x = A^T b\n",
"$$\n",
"If $A$ is of full rank, it is the same as\n",
"$$ Rx = Q^T b. $$\n",
"- Since $R$ is upper triangular, the solving of this linear system costs $\\mathcal{O}(n^2)$. \n",
"- It is more stable than solving the normal equations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$R^T Q^T Q R x = R^T Q^T b$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$R x = Q^T b$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# QR decomposition\n",
"\n",
"- The name implies that a matrix is represented as a product \n",
"$$\n",
" A = Q R, \n",
"$$\n",
"where $Q$ is a column orthonormal matrix and $R$ is upper triangular. "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- The matrix sizes: $Q$ is $m \\times n$, $R$ is $n \\times n$ if $m\\geq n$."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- QR decomposition is defined for any rectangular matrix."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- QR decomposition can be computed in a $O(mn^2)$ (for $m>n$) (via so called direct methods)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Full QR vs reduced QR\n",
"![](full.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## QR decomposition: applications\n",
"\n",
"This decomposition plays a crucial role in many problems:\n",
"- Computing orthonormal bases in a linear space"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- Solving overdetermined systems of linear equations"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- QR-algorithm for the computation of eigenvectors and eigenvalues ([one of the 10 most important algorithms of the 20th century](https://archive.siam.org/pdf/news/637.pdf)) is based on the QR decomposition"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Existence of QR decomposition\n",
"Every rectangular $m \\times n$ matrix has a QR decomposition. \n",
"\n",
"\n",
"There are several ways to prove it and compute it:\n",
"\n",
"- Geometrical: using the Gram-Schmidt orthogonalization\n",
"- Practical: using Householder/Givens transformations "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Gram-Schmidt orthogonalization\n",
"\n",
"- QR decomposition is a mathematical way of writing down the Gram-Schmidt orthogonalization process. \n",
"- Given a sequence of vectors $a_1, \\ldots, a_m$ we want to find orthogonal basis $q_1, \\ldots, q_m$ such that every $a_i$ is a linear combination of such vectors. "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Gram-Schmidt:\n",
"- $q_1 := a_1/\\Vert a_1\\Vert$\n",
"- $q_2 := a_2 - (a_2, q_1) q_1, \\quad q_2 := q_2/\\Vert q_2 \\Vert$\n",
"- $q_3 := a_3 - (a_3, q_1) q_1 - (a_3, q_2) q_2, \\quad q_3 := q_3/\\Vert q_3 \\Vert$\n",
"\n",
"And so on.\n",
"\n",
"Note that the transformation from $Q$ to $A$ has triangular structure, since from the $k$-th vector we subtract only the previous ones. It follows from the fact that the product of triangular matrices is a triangular matrix."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## QR decomposition: the practical way\n",
"\n",
"* Gram-Schmidt orthogonalization is not very practical as just described for numerical issues (will see later). One typically does it differently: Householder rotations (implemented in numpy)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## More on Pseudoinverse\n",
"Recall that we introduced pseudoinverse as\n",
"$$\n",
"A^+ = (A^T A)^{-1} A^T\n",
"$$\n",
"- Matrix $A^T A$ can be singular in general case.\n",
"- Therefore, we need to introduce the concept of pseudoinverse matrix $A^{\\dagger}$.\n",
"- The matrix $$A^{\\dagger} = \\lim_{\\alpha \\rightarrow 0}(\\alpha I + A^T A)^{-1} A^T$$ is called Moore-Penrose pseudoinverse of the matrix $A$."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Pseudoinverse and linear systems\n",
"Consider a system of equations $Ax\\approx b$\n",
"- $\\forall x$, we have $\\left\\|Ax-b\\right\\|_{2}\\geq \\left\\|Az-b\\right\\|_{2}$, where \n",
"$z=A^{+}b$\n",
"- If $A x = b$ is satisfiable, the vector $z=A^{+}b$ is a solution, and satisfies $\\|z\\|_{2}\\leq \\|x\\|_{2}$ for all other solutions\n",
"\n",
"As a result, the solution to the linear least squares problem (including least norm solutions) can formally be written as\n",
"$$x = A^{\\dagger} b.$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Simple cases\n",
"\n",
"- If matrix $A$ is squared and non-singular we get standard inverse of $A$:\n",
"$$A^{\\dagger} = \\lim_{\\alpha \\rightarrow 0}(\\alpha I + A^T A)^{-1} A^T = (A^T A)^{-1} A^T = A^{-1} (A^{T})^{-1} A^T = A^{-1}$$\n",
"- If matrix $A$ has full column rank, then $A^T A$ is non-singular and we get \n",
"$$A^{\\dagger} = \\lim_{\\alpha \\rightarrow 0}(\\alpha I + A^T A)^{-1} A^T = (A^T A)^{-1} A^T. $$\n",
"- Pseudoinverse is uniquely defined in all other cases, too! "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Least squares via SVD \n",
"Lets inspect SVD approach to over- and under- determined problems."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider solving $Ax \\approx b$ for $A$ of arbitrary shape and possibly not of a full rank (the system cen be under- or overdetermined).\n",
"\n",
"Let $A = U \\Sigma V^T$ be SVD decomposition of $A$, then we need to solve"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"U\\Sigma V^T x \\approx b\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since $U$ and $V$ are orthogonal, we can just switch to new variables, $\\bar x = V^T x$ and $\\bar b = U^T b$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Sigma \\bar x \\approx \\bar b\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Up to now, its not important if the system is under- or overdetermined. Here it becomes important. Lets consider underdetermined case."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\begin{pmatrix}\n",
"\\sigma_1 & 0 & 0\\\\\n",
"0 & \\sigma_2 & 0 \\\\\n",
"0 & 0 & 0 \\\\\n",
"\\end{pmatrix}\n",
"\\begin{pmatrix}\n",
"\\bar x_1 \\\\\n",
"\\bar x_2 \\\\\n",
"\\bar x_3\n",
"\\end{pmatrix} \\approx\n",
"\\begin{pmatrix}\n",
"\\bar b_1 \\\\\n",
"\\bar b_2 \\\\\n",
"\\bar b_3\n",
"\\end{pmatrix},\n",
"$$\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\bar x_1 = \\bar b_1 / \\sigma_1, \\bar x_2 = \\bar b_2 / \\sigma_2, \\bar x_3 = 0\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Example: Signal recovery "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"with np.load('data.npz') as data:\n",
" A, C = data['A'], data[\"C\"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(25, 60)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAACsCAYAAABikvffAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAe4ElEQVR4nO2dW4xl11nn/9/e+9zq0l3d7W637TYxiSxBQIOBVsgo82Aug8JF4/AQiUggIyE1DyAFCTR4eMmAhJQHbg8gJM/EihEQFAkysUYIYgVGgReIEzwTByexsTt22+2+uLuqq+rUOWefvT8e6hiKXv+v65yu6tOzj/4/yequ1avWXmvttb+zff7fxdwdQgghmkd2tycghBDi9pABF0KIhiIDLoQQDUUGXAghGooMuBBCNBQZcCGEaCgHMuBm9kEz+7qZvWxmTxzWpIQQQuyP3a4fuJnlAL4B4D8DuADgiwA+4u7/FP1O2zrexfJ042fBZ4vRzlONCQDI2AAAouvdKaJ9Z/Ooa97XgrWwy5F1W3XwccN1sOZo76Pr1WSQGaYWwq4363PA5hatjxFd7zD2Yqb7x34/6jvDnGfZz1nmOytsHuHUyD9Ez160SXQvgjHYPILr3fBrV9395M3tRTC7aXgfgJfd/RUAMLM/BfAYgNCAd7GM78t+KP0HYoCz5SU6hrEN6nT4BZnR6vK+HrTP9FDO8iEwHE09DxsM+Rit6W9f3W0nbfnGdjCHtC8AgBn8qqJd2YeD94K9D/bNRiVpPPjD7p1036yKPoh4u+2k9yRaH923yDAE99T6g/R60f1n+xmdYza3Iud9yzFvZ/3HM5yLTouPyz60ACAn6wvOBbtP4d6zufX7vG8R3KdWuhYfpPcOADBO99ODZ/1zO3/0TdZ+kNfOBwC8vufnC5M2IYQQc+Agb+DsIy/5yDSzcwDOAUAX/K1aCCHE7BzkDfwCgAf3/HwGwJs3d3L3J939rLufbSH4X0whhBAzcxAD/kUAD5vZt5pZG8BPAnjmcKYlhBBiP277KxR3H5vZLwD4KwA5gKfc/au3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JnJB8F59t4u+fp3nc2gvQdq+n12qv8PuEt3qw3cCGEaCgy4EII0VBkwIUQoqHIgAshREORARdCiIYyZy8Ug7fSS457qceJZ1zlHRMhnDhY7EIcWfJlHjJ/fJmHqz+4vJ60vad7mfbdrNPJrXX5uOvVEm2/Pk5V6Pta6RwArrx/S+tt2vfyOM0rcKrgXgzbdeoVBAAPtK8nbcy7BQDW8nTdpwvueTFw7pHznb20/cXB/bTv0Tz1cBkEnj5Leeqx8mDrGu1bBV42zGuFrRnge3+x5BUPvr37Bm3frFNvirWce+/kpJJFdE+/3rovaetm/BlZieLHCVsV91g5Sbxslgp+vSMtfj3m4VRk3PtqtZV6nAxLfi62t4ltWg6SRQQFJJgzU0kKoQCAB54ss6A3cCGEaCgy4EII0VBkwIUQoqHIgAshREOZs4gJgIiYXqRf5o9IyDwAjI6mAk2gl8DbaQj6PWs8VPnMyjpt/97V80nb+3uv0r4lUTAGPtsWvzY+nrRF4t+JLBXuukEo/X/sridteSDQrWR8Q/9hmAqka0E4fpcIrN1AtFkxLipt1OnY0V4sZdOH0pek1PjDLR7mH1F5ur71IB/4WpaKm9/WuUj7PhSEsXdIruro/nXIfl6tuLh9ulhP2srgzLaMh8cz0fTtmoeEszD/4wUXY6O0EBtVKuieaXMR+hut00nbdskF3VdH6bkog2chKlc/3iGV7YPX5KpD/mFGYVNv4EII0VBkwIUQoqHIgAshREORARdCiIayrwE3s6fM7LKZvbCn7biZPWtmL03+5GFlQggh7hjTuEh8EsDvAfjDPW1PAPi8u3/czJ6
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.imshow(A)\n",
"A.shape"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"The image, stored in a matrix $A$ is obtained from a certain original $A_0$ via convolution with a filter $C$ addition of a noise. The filter $C$ 'blurs' the image, simultaneously changing the image size from $16\\times 51$ to $25\\times 60$."
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"def mat2vec(A):\n",
" return np.reshape(np.flipud(A), np.prod(A.shape))"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"def vec2mat(a, shape):\n",
" return np.flipud(np.reshape(a, shape))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Representing the images as vectors, we can write down the filtering as follows:\n",
"$$\n",
"a_0\\to a = C a_0 + \\epsilon,\n",
"$$\n",
"where $\\epsilon$ is a noise vector (consisting from iid normal variables)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Lets inspect how the filter $C$ acts on the images"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAACJCAYAAAA8GMMgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAIW0lEQVR4nO3dT4xdZRnH8e/PtrRSSQShBCiKmsZIiNRkUklwwR+BqsTiwgQSky6M40ISTDSmsvFPQuLGPxtjUrWhiQIhaqUxRKhVgwujFK1SBKQhRZppOhA04gYFHhf3TJxAp9O5986c8t7vJ5mce945d94nz0x/PXnnnDOpKiRJb3xv6rsASdJ4GOiS1AgDXZIaYaBLUiMMdElqhIEuSY0YKdCTbE3yZJLDSXaMqyhJ0tJl2OvQk6wC/gZcBxwFHgZuqaq/LvSeM7K21rF+qPkkaVK9yD+er6rzFjtu9QhzbAEOV9XTAEnuAbYBCwb6OtbzgVw7wpSSNHl+WT9+5lSOG2XJ5S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J8kMmqwcAVNVMt50F9jBYml5yH/oI9IeBTUnemeQM4GZgbw91nC72Atu719uB+3qsZdllcCr+A+DxqvrmvE9NWh/O687MSfJm4EPAE0xQH6rqS1W1saouYZADv6qqTzJBPQBIsj7JWXOvgesZPMF2yX3o5caiJB9hsHa2CthVVXeseBE9WODJlT8D7gXeDvwd+ERVNfsn/5J8EPgt8Cj/Xze9ncE6+iT14X0MftG1isGJ1b1V9bUkb2OC+jCnW3L5QlXdOGk9SPIuBmflMFgGv6uq7himD94pKkmN8E5RSWqEgS5JjTDQJakRBrokNcJAl6RGGOiS1AgDXZIaYaBLUiP+B5iOd9fD+omsAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"X = np.zeros((16,51))\n",
"X[5:15,15] = 1; X[5:15,30] = 1; X[5:15,40] = 1\n",
"X[5,10:20] = 1; X[5,30:41] = 1; X[15,30:41] = 1\n",
"plt.imshow(X);"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAACsCAYAAABikvffAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAN1klEQVR4nO3dbYwdV33H8d8vy+66fiDYSRysJCVJlRcgBI60SkHpC0MoSinC4UWkRGplJKTlBUhBCiIubwKVkPKipbwAVXIbK0ZAUFSSxqpQwQRQWgmFOGnaODiQKOTB2Hjz4NgbIvlh8++LO4svu2d87+zMnesz+/1I1r337PjOOR77l5M558xxRAgAkJ8Lxl0BAMDKEOAAkCkCHAAyRYADQKYIcADIFAEOAJmqFeC2b7T9K9vP2t7ZVKUAAIN5pfPAbU9I+rWkv5R0SNKjk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t+WdILxceL1czG2uerLrevy22TaF/uuti+d0XEJUsLWw3wPzqxvT8iZsZy8hZ0uX1dbptE+3LX9fb14xYKAGSKAAeATI0zwHeN8dxt6HL7utw2ifblruvt+4Ox3QMHANTDLRQAyFTrAW77Rtu/sv2s7Z1tn79ptnfbnrN9oK9sk+19tp8pXjeOs4512L7C9k9tH7T9lO3bivLs22h7je1f2P7fom1fKcqzb1s/2xO2/8f2fxSfO9M+28/bftL2E7b3F2Wdad8grQa47QlJ35T0V5LeI+lW2+9psw4jcI+kG5eU7ZT0UERcI+mh4nOuzki6PSLeLekDkj5bXLMutPG
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"x = mat2vec(X)\n",
"plt.imshow(vec2mat(C @ x, (25, 60)));"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAACJCAYAAAA8GMMgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAYyElEQVR4nO2deXRc9XXHv3dGI2m02LK8IS94wTYGG28oZjEBO5glgQJpSQollLZJSFtSSEoOJWl70gbS5vScZulpQuKkHGgoS0jCEuKwhJ1ggu1gB+MN413W5kW7NJJmfv1D49aF+322JSOlT9/POT7S3J/uvN+77707z+/3nXsthAAhhBD//0kM9QSEEEKcGJTQhRAiJiihCyFETFBCF0KImKCELoQQMUEJXQghYsKAErqZXWpmW8xsm5ndfqImJYQQ4vix/urQzSwJYCuAiwDsBbAawLUhhI3MJ1lWGgoqK/3BHNlOERkAELrJ51EB3yfrMf+9UtwnkeRzyPX6c0h0+tsBgFyabCsRcSx6yL6m+Nysi39eh0KyrcDnXVHa7tpbG0up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SltdbzokvXy4nMFjf451DYvomdugx8H28q/1Jcd6cenZA9XsoTFXDWT6PBVOOvXnkJ9isimCg/ye87Emf4ckuv5tdzTzlNeT7mvMinbxefQtMw/J3O7+Bws6x/z3hE8zxwrukMXQoiYoIQuhBAxQQldCCFighK6EELEBCV0IYSICUroQggREwZVtgiAfoQkW/yp9OzwpYkAkF3iSxATu3gRp+wqX0K2fwEvjGURhZ9Kany9VfvJvA/hwY2+XC47mfc
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"a = mat2vec(A)\n",
"a0 = np.linalg.pinv(C) @ a\n",
"A0 = vec2mat(a0, (16, 51))\n",
"plt.imshow(A0);"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"u, s, vh = np.linalg.svd(C, full_matrices=False)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"((1500, 816), (816,))"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"C.shape, s.shape"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAACJCAYAAAA8GMMgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAYyElEQVR4nO2deXRc9XXHv3dGI2m02LK8IS94wTYGG28oZjEBO5glgQJpSQollLZJSFtSSEoOJWl70gbS5vScZulpQuKkHGgoS0jCEuKwhJ1ggu1gB+MN413W5kW7NJJmfv1D49aF+322JSOlT9/POT7S3J/uvN+77707z+/3nXsthAAhh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ImKCELoQQMUEJXQghYoISuhBCxIRB7SkakgE9FWTVutkv6FNxGl8tzj3vqwpaZ/KV8REn+eqO9I+5UqP+g/z9WEGt5CFeIKzydF9d0baKKx5mXPW2a9/9wxnUp2kWHcLc8X7/0j2/9AuHAcChuf4xapvDC2O1bycFhyJ80r/11Syd87lCIVnnzw0AsqQvbeYVrrTJkZaZ3W1+H1sAyM72VSltdbzokvXy4nMFjf451DYvomdugx8H28q/1Jcd6cenZA9XsoTFXDWT6PBVOOvXnkJ9isimCg/ye87Emf4ckuv5tdzTzlNeT7mvMinbxefQtMw/J3O7+Bws6x/z3hE8zxwrukMXQoiYoIQuhBAxQQldCCFighK6EELEBCV0IYSICUroQggREwZVtgiAfoQkW/yp9OzwpYkAkF3iSxATu3gRp+wqX0K2fwEvjGURhZ9Kany9VfvJvA/hwY2+XC47mfc
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# equivalent to least squares\n",
"n = 816\n",
"s0 = np.zeros(816)\n",
"s0[:n] = s[:n]\n",
"C0 = np.dot(u, np.dot(np.diag(s0), vh))\n",
"A0_guess = vec2mat(np.linalg.pinv(C0) @ a, (16, 51))\n",
"plt.imshow(A0_guess)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAhRUlEQVR4nO3deXxV5YH/8c9zs+97QlaTELYAYRUEwb0KVtGp1sHWGdtBGbtN22lnqtNOW3+dTpexrW3HsTrW1rEuo47jgrS4gVSlSJA1QICEQEJCNrKRELLc5/dHLjYygIEs59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bF+Zzx6ICOrr7uOWhDXziP97h3f1N9PZ7nY4nIi6nMXw/1dXTx2/eqeLBdRUcO9FHeIiHT83P46tXTSQhOszpeCLiEM3DD0DR4aF84fIibp6Tw7sVTTy3uYbfvlvFzsNt/PJTs8hMiHI6ooi4jIZ0/FxGfCR/MSuH362Yz1evmkjpwRYu+fFantlUrYuri8iHuHJIJ9DPpTOadtW2880XdrDlUCuLJ6Ry0+wcpuckMD4t1uloIjIGNA8/yHi9lgffquD+1/fS228J8Rhump3NN68t1vi+SIBT4Qepnj4vB5o6eWh9Bc+/f5gQj+Gh2+ZwVXGG09FEZJTowKsgFR7qYdK4OH7yyRk8vmIeEzPi+PyT77OxstnpaCLiABV+EDDGsHhCGj++qWRg+uYjG3ns3Sq6enThFZFgosIPItNzEnj7G5czPTuB77xUxpzvvc6zpdW061KLIkFBY/hByFrLO/ub+f7q3eyuayci1MM3lkzmpjk5JERpp66IP9NOWzmtvn4
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(s0)\n",
"plt.yscale('log');"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAACJCAYAAAA8GMMgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAUyElEQVR4nO2dXYwk11XH/6eqq7vna2e/1/baiUNkiUQWMdLKCjIPToDIgIXDQ1AsIfkBsTwQKUggZPISQIrECx8vCMkQy5YgCZbAxEIWiWWCzBN4DYE42AHLcuzVzu7sx8zOV39Udx8epgcm9v2fmemenXZq/j9pNd339q26fU7Vqdq6/z7H3B1CCCF++MkmPQEhhBD7gwK6EEJUBAV0IYSoCA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pOnDJcrcmBFpYJRZktmbZdcEgD7SclQAWKfb43NgtVpXndfmvNqfS7YzfwPAQvco7bvSOZLeT5sfW8vt9PHQ6fFTvddP39exDKgA0Ch4NsF+UHeVwTKQsvMVANqkLm4z4+drJEG82kvbe7Gb9ivAz792l0sqrUtquPJp7xrdoQshREVQQBdCiIqggC6EEBVBAV0IISqCAroQQlSEHVUuZvYkgIcBLLr7vcO24wD+GsDdAN4C8EvuvrTjtvpAQcQIxc206mJ1hqs43qyn1QODIInTUi+dAOtkka5jCcSKjJIk9LnRm6FjFjvpVfMrLb6afrOTTkS21uaqi7IX1MwcpG2UZVxVUNTSdlhp8Dmslem+9V4wpp/uu9HnNj2er9O+OaJ6ihQUzK8rA348XivT/rvcTasnAOBym/ddbaXVLMu
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"n = 10\n",
"s0 = np.zeros(816)\n",
"s0[:n] = s[:n]\n",
"C0 = np.dot(u, np.dot(np.diag(s0), vh))\n",
"A0_guess = vec2mat(np.linalg.pinv(C0) @ a, (16, 51))\n",
"plt.imshow(A0_guess)\n",
"plt.show()"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3.10.8 ('nummethods')",
"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.10.8"
},
"vscode": {
"interpreter": {
"hash": "8d489487a004dbbc79692a52da1077223bea5d5bb7772308e4a4df2310821984"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}