1
Fork 0
solar-conflux/python/denoising/Main.ipynb

317 lines
513 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"id": "9785abf6",
"metadata": {},
"source": [
"We have:\n",
"$$\n",
"\\nabla f = (I + \\beta A) \\vec s - \\vec y\n",
" = \\vec s - \\vec y + \\beta A \\vec s\n",
"$$ \n",
"We can substitute in the partial derivatives:\n",
"$$ \n",
"\\left(\\begin{matrix}\n",
"s_0 - y_0 + \\beta (s_0 - s_1) \\\\\n",
"s_1 - y_1 + \\beta (2s_1 - s_0 - s_2) \\\\\n",
"\\vdots \\\\\n",
"s_N - y_N + \\beta (s_N - s_{N - 1})\n",
"\\end{matrix}\\right) \n",
"= \\vec s - \\vec y + \\beta A \\vec s\n",
"$$\n",
"\n",
"Adding $\\vec y - \\vec s$ to both sides and then dividing by $\\beta$ yields:\n",
"$$ \n",
"\\left(\\begin{matrix}\n",
"s_0 - s_1 \\\\\n",
"2s_1 - s_0 - s_2 \\\\\n",
"\\vdots \\\\\n",
"s_N - s_{N - 1}\n",
"\\end{matrix}\\right) \n",
"= A \\vec s\n",
"$$\n",
"\n",
"Solving for $A$ is trivial and yields:\n",
"$$ \n",
"A = \\left(\\begin{matrix}\n",
"1 & -1 & & & & & \\\\\n",
"-1 & 2 & -1 & & & & \\\\\n",
" & -1 & 2 & -1 & & & \\\\\n",
" & & \\ddots & \\ddots & \\ddots & & \\\\\n",
" & & & -1 & 2 & -1 & \\\\\n",
" & & & & -1 & 2 & -1\\\\\n",
" & & & & & -1 & 1\n",
"\\end{matrix}\\right) \n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "e7d69a97",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import modules.tridiagonal as tridiagonal\n",
"\n",
"def sample_with_noise(points, vectorized_g):\n",
" \"\"\"\n",
" Sample a function at a given set of points,\n",
" introducing noise in the process.\n",
"\n",
" Returns a tuple of the real values of the function\n",
" and the values with introduced noise.\n",
"\n",
" For performance reasons, this function takes in\n",
" a vectorized version of `g`. If you want to pass\n",
" a non vectorized function use `np.vectorize`. Eg:\n",
" ```py\n",
" sample_with_noise(points, np.vectorize(g))\n",
" ```\n",
" \"\"\"\n",
" gs = vectorized_g(points)\n",
" ys = gs + 0.05 * np.random.randn(len(gs))\n",
"\n",
" return (gs, ys)\n",
"\n",
"def p5(x):\n",
" \"\"\"\n",
" Vectorized version of the function\n",
" described in the pdf.\n",
" \"\"\"\n",
" n = 5\n",
" result = 0\n",
"\n",
" for k in range(n + 1):\n",
" result += x**k\n",
"\n",
" return result/(n + 1)\n",
"\n",
"def smooth(data, beta):\n",
" \"\"\"\n",
" Smooth noisy data (y) by means of solving \n",
" a minimization problem.\n",
"\n",
" Args:\n",
" data (numpy.array): noisy data to be smoothed (y)\n",
" beta (float): parameter >= 0 that balances fit and smoothing\n",
"\n",
" Returns:\n",
" numpy array of smoothed data (s)\n",
" \"\"\"\n",
" x,y = data\n",
"\n",
" # We need to solve for s in:\n",
" # (I + βA)s - y = 0\n",
" # <=> (I + βA)s = y\n",
" #\n",
" # Because A and I are tridiagonal, I + βA\n",
" # is tridiagonal as well (linear combinations\n",
" # of tridiagonal matrices are themselves\n",
" # tridiagonal)\n",
" #\n",
" # This means we can use our existing implementation\n",
" # of tridiagonal linear equation system solving.\n",
" # \n",
" # We start by constructing \n",
" # iba := I + βA\n",
" n = len(x) - 1\n",
"\n",
" # The a component of the a-c-e tridiagonal representation of iba\n",
" iba_a = np.ones(n + 1) * (2 * beta + 1)\n",
" iba_a[0] = 1 + beta\n",
" iba_a[-1] = 1 + beta\n",
"\n",
" # I + βA\n",
" iba = (\n",
" iba_a,\n",
" -beta*np.ones(n),\n",
" -beta*np.ones(n)\n",
" )\n",
"\n",
" data_smoothed = tridiagonal.solve(*iba, y)\n",
"\n",
" return data_smoothed"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "2b9f2b79",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANS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kKDw/nzTffRKvV8uKLLwKGG5+iKNkGzX777bfodDqTsgdbPbJk3Twf3Mf9M7Ly0rVrV06fPs3x48dNyn/55ReT94GBgbi6uhIaGkqrVq1yfNnY2BTomFmyBiD/9NNPJuUrV64kKSkp2wDl3Dg6OtK7d2/eeecd0tPTOX36dKHiyElQUBAJCQn8888/JuXLly9/qP327NkTKysrLl26lOt1zEndunWZNm0ajRs35siRI8ZyPz8/Tpw4YVJ369atJCYm5htLbj9TD9YJCgpizpw5ANlmdAlR1knLjRDF5NSpU8axFFFRUezatYslS5ag0WhYvXq1sZXCxcWFzp078/HHH+Ph4YGfnx87duzgu+++w9XV1WSfAQEBAHzzzTc4OztjZ2eHv78/9evXp1atWkyZMgVFUXBzc+Ovv/4qUPcMwGuvvcb3339P3759+eCDD4yzpc6ePWtSz8nJiS+++IKRI0cSGxvL4MGD8fLy4vbt2xw/fpzbt2+zcOHCQl2n7t2707NnTyZPnkx8fDyBgYHG2VLNmzdn+PDhuW77wgsvYG9vT2BgID4+PkRGRhIcHIxWq823xacgRo4cydy5c3n22Wf54IMPqF27Nv/88w8bN24EQK0u2u+Dfn5+vP/++7zzzjtcvnyZXr16UalSJW7dusXBgwdxdHRk5syZnDhxgldeeYUnn3ySOnXqYGNjw9atWzlx4oRJK9/w4cN59913ee+99wg
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plot\n",
"\n",
"# Reusable function to plot the data\n",
"def plot_denoise_results(beta, N, ax):\n",
" # Create the data\n",
" x = np.linspace(-1, 1, num=N+1)\n",
" g, y = sample_with_noise(x, p5)\n",
" s = smooth((x, y), beta)\n",
"\n",
" ax.set_title(f\"β={beta} and {N=}\")\n",
" ax.set_xlabel(\"x\")\n",
" ax.set_ylabel(\"y\")\n",
" ax.plot(x, y, \".\", label=\"raw data points\")\n",
" ax.plot(x, g, \"-\", label=\"original function\")\n",
" ax.plot(x, s, \"-\", label=\"denoised values\")\n",
" ax.legend()\n",
"\n",
"\n",
"N = 100\n",
"beta = 10\n",
"\n",
"fig, ax = plot.subplots()\n",
"fig.suptitle(f\"Data denoising results\")\n",
"\n",
"# Plot the data\n",
"plot_denoise_results(beta, N, ax)"
]
},
{
"cell_type": "markdown",
"id": "f2e5c860",
"metadata": {},
"source": [
"We notice that finding a point where $\\nabla f(s) = 0$ is the same as finding a point where $\\frac 1 \\beta \\nabla f(s) = \\nabla \\frac 1 \\beta f(s) = 0$. We can use this to our advantage, by defining $h(s) = \\frac 1 \\beta f(s)$ and finding the points where $\\nabla h(s) = 0$ instead. When $\\beta \\to \\infty$, we have:\n",
"$$\n",
"\\lim_{\\beta \\to \\inf} h _\\beta (s) =\n",
"\\lim_{\\beta \\to \\inf} \n",
" \\frac 1 {2\\beta} \\sum_{k=0}^n (y_k - s_k)^2\n",
" +\\frac 1 2 \\sum_{k=1}^n (s_k - s_{k - 1})^2\n",
" = \\frac 1 2 \\sum_{k=1}^n (s_k - s_{k - 1})^2\n",
"$$\n",
"\n",
"It now becomes trivial to verify that $\\nabla f(s) = As$. Looking at the value of $A$ we notice that any vector with all values equal to some constant are solutions for this equation. This means the result will be a constant function (which might differ based on the linear equation solver we are using)."
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "d7f7dbdf",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABQsAAAPLCAYAAAD4+99NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1yV9fvH8dc57I2CAweCW1Nzz1yZo8zMUZT9NEd9KzMry5nlqBxpZUPbjtLKSs1Kc+RMzdzmylJRHCjiAARknHP//iBOEkNA4DDez8eDR3DP6747cnFf92eYDMMwEBERERERERERkRLPbO8AREREREREREREpHBQsVBEREREREREREQAFQtFRERERERERETkHyoWioiIiIiIiIiICKBioYiIiIiIiIiIiPxDxUIREREREREREREBVCwUERERERERERGRf6hYKCIiIiIiIiIiIoCKhSIiIiIiIiIiIvIPFQtFREREREREREQEULFQRERERERERERE/qFioYiIiKQzf/58TCaT7cvV1ZXy5cvTsWNHpk6dSkRERK6PvW3bNiZOnMjVq1fzLuAsTJw4EZPJVCDnupnU+3ry5Ml83ac4y+h+FPRnKq/ExcUxadIkateujaurK35+fjz88MNcuXLF3qGJiIhICaZioYiIiGRq3rx5/Pbbb6xdu5bZs2fTsGFDpk+fTp06dfjll19ydcxt27YxadKkIlfYyQvdu3fnt99+IyAgIF/3KWmK4mfKMAwefvhhZs2axRNPPMHPP//MK6+8wuLFi3nzzTftHZ6IiIiUYI72DkBEREQKr3r16tG0aVPbz3369OH555/njjvuoHfv3vz999+UK1fOjhEWLWXKlKFMmTL5vk9+i4uLw93d3d5hFGmbNm3ihx9+4Ntvv6Vv374Atpa7sbGxdo5ORERESjK1LBQREZEcCQwM5M033yQmJoaPPvoIgGPHjjFo0CBq1KiBu7s7FStWpEePHhw4cCDNvhMnTmTkyJEABAcH27o5b9y4MdvHyMqKFSto2LAhLi4uBAcHM3PmzAy3+/vvv+nXrx9ly5bFxcWFOnXqMHv27HSxmkwmDh06xMMPP4yPjw/lypVj8ODBREVFpTvmli1b6NSpE15eXri7u9O6dWtWrFiRZpuMutBevHiR//3vf1SuXBkXFxfKlClDmzZtbC03M9onp7EtX76cBg0a4OLiQtWqVXnnnXey3T07dbs9e/bQt29fSpUqRbVq1bJ9H7NzjQMHDiQoKCjTc98svsw+Uzc7b2ay+1nM7fEBvv32W0qVKkWvXr1syzZv3syFCxe48847b7p/qrfffpvvv/8+y22Sk5PTLbNYLNk+h4iIiJQsalkoIiIiOXbPPffg4ODA5s2bATh37hx+fn5MmzaNMmXKcPnyZRYsWECLFi3Yu3cvtWrVAuCxxx7j8uXLvPfeeyxdutTWtbZu3brs27cvW8fIzLp16+jZsy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F69OlvHzOwzdbPzZiY3n8WcHH/Hjh3pWqIahsGnn35KvXr1qFu3bpb732jGjBm2iXRSC4Wp1zB//nweeeQR/vzzT1q2bMnSpUtJTEykT58+eHp6UqtWLb777rtsn0tERERKBhULRUREJFMHDx60jUUXERHBr7/+yrx583BwcGDZsmWUKVMGgHvvvZf58+dTu3ZtGjRowO7du5kxYwaVKlVKd8zUrsvvvPMOjz76KE5OTtSqVStHx8jIq6++Srdu3ejcuTMvvPACFouF6dOn4+HhweXLl23bvfPOO9xxxx20bduWp556iqCgIGJiYjh27Bg//vgj69evz/F9mjp1Kp07d6Zjx468+OKLODs7M2fOHA4ePMh
"text/plain": [
"<Figure size 1280x960 with 9 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, axs = plot.subplots(\n",
" 3,\n",
" 3,\n",
" layout=\"constrained\",\n",
" figsize=(12.8, 9.6)\n",
")\n",
"\n",
"fig.suptitle(r\"Data denoising results as $\\beta \\to \\infty$\")\n",
"\n",
"N = 100\n",
"\n",
"for i in range(len(axs.flat)):\n",
" ax = axs.flat[i]\n",
" plot_denoise_results(4**i, N, ax)"
]
},
{
"cell_type": "markdown",
"id": "3c9f50cc",
"metadata": {},
"source": [
"When $\\beta \\to 0$ we have:\n",
"$$\n",
"\\lim_{\\beta \\to 0} \\nabla f(s) =\n",
"\\lim_{\\beta \\to 0} (I + \\betaA)s - y = s - y\n",
"$$\n",
"\n",
"This means when solving for $\\nabla f(s) = 0$, we are solving the equation $s - y = 0$, which has the solution $s = y$. The resulting function will then be one equal to the data containing the noise."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "dfc485d5",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABQsAAAPLCAYAAAD4+99NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAP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1DFhERkUpLSEjg0Ucfxd/fn3/84x+AvZBU1KutyLJly/jrr79Kvf/s3m9FKrOPs3l7e9O9e3eWLFlCbm6uY3tGRgZfffWV43cvLy8GDhzItm3b6NixI127di31c3ZvvYocu0ePHixZsqTEOdlsNj766CPCw8Np3bp1hfYVERHBAw88wODBg9m6dWul4igvtq5du/L555+Tn5/v2J6ZmcnXX399wfu9mOtY1jlGRkaSlJRUoqiZn5/PypUrKxRPeZ+p8x23PBfyWazM/n/55ZdSPVENw+C///0v7du3p127dud8f3EvvfSSYyGd4kXBkSNHkpmZyeLFi0u0nz9/Po0bN3YsriIiIiJSnHoWioiIyDnt3LnTMRddUlISP/zwA3PnzsXZ2ZmlS5fSsGFDAK677jrmzZtH27Zt6dixI1u2bOGll14iPDy81D6Lhi6/9tpr3HHHHbi6utKmTZtK7aMszz//PFdffTWDBw9m4sSJWK1WZs2ahbe3t2PoZdFxr7jiCvr27ct9991HZGQkGRkZ7Nu3j6+++orvv/++0tdpxowZDB48mIEDB/Loo4/i5ubG22+/zc6dO1mwYEG588OlpaUxcOB
"text/plain": [
"<Figure size 1280x960 with 6 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, axs = plot.subplots(\n",
" 2,\n",
" 3,\n",
" layout=\"constrained\",\n",
" figsize=(12.8, 9.6)\n",
")\n",
"\n",
"fig.suptitle(r\"Data denoising results as $\\beta \\to 0$\")\n",
"\n",
"N = 100\n",
"\n",
"for i in range(len(axs.flat)):\n",
" ax = axs.flat[i]\n",
" plot_denoise_results(2**-i, N, ax)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ffa20a6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}