Minor updates

This commit is contained in:
Adam Wojdyla 2022-05-14 22:51:06 +02:00
parent 929bf13185
commit ebf9e510f2

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 11,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -13,7 +13,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/tq/jq5nwbnj7v10tls99x99qbh40000gn/T/ipykernel_66956/17056051.py:11: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display\n",
"/var/folders/t3/dwnz0lh916ng4w7bzf0z56ym0000gn/T/ipykernel_43951/17056051.py:11: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display\n",
" from IPython.core.display import display, HTML\n"
]
},
@ -47,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 12,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -80,13 +80,17 @@
"source": [
"Metodę SVD zastosujemy do kompresji obrazów. SVD dokonuje dekompozycji macierzy prostokątnej $M$ na trzy części.\n",
"$M=U\\Sigma V^T$ -\n",
"- $U$ - macierz, w której kolumny są wektorami własnymi macierzy $MM^T$ (lewe wektory osobliwe - 'left singular vectors')\n",
"- $\\Sigma$ - macierz diagonalna, która na swojej diagonalii ma nieujemne wartości osobliwe (pierwiastki wartości własnych) macierzy $M^TM$ uporządkowane nierosnąco\n",
"- $V$ - macierz, w której kolumny są wektorami własnymi macierzy $M^TM$ (prawe wektory osobliwe - 'right singular vectors')\n",
"- $U$ - macierz, w której kolumny są wektorami własnymi macierzy $MM^T$ (lewe wektory osobliwe - 'left singular vectors'). Wektory te tworzą układ ortonormalny.\n",
"- $\\Sigma$ - macierz diagonalna, która na swojej diagonalii ma nieujemne wartości osobliwe (szczególne), czyli pierwiastki wartości własnych macierzy $M^TM$ uporządkowane nierosnąco\n",
"- $V$ - macierz, w której kolumny są wektorami własnymi macierzy $M^TM$ (prawe wektory osobliwe - 'right singular vectors'). Wektory te tworzą układ ortonormalny.\n",
"\n",
"SVD polega na rekonstrukcji oryginalnej macierzy jako kombinacji liniowej kilku macierzy rangi jeden. Macierz rangi jeden można wyrazić jako iloczyn zewnętrzny dwóch wektorów kolumnowych. \n",
"\n",
"$M=\\sigma_1u_1v_1^T+\\sigma_2u_2v_2^T+\\sigma_3u_3v_3^T+\\sigma_3u_3v_3^T+....$ . \n",
"$M=\\sigma_1u_1v_1^T+\\sigma_2u_2v_2^T+\\sigma_3u_3v_3^T+\\sigma_3u_3v_3^T+....$ .\n",
"\n",
"$rank M=r$ .\n",
"$M=\\sum_{i=1}^{r} \\sigma_iu_iv_i^T$\n",
"\n",
"Macierz o randze r będzie miała r takich wyrazów.\n",
"\n",
"Tutaj $\\sigma_1,\\sigma_2,\\sigma_3 ...$ są wartościami osobliwymi. $u_1,u_2,u_3 ...$ i $v_1,v_2,v_3 ...$ są kolejnymi kolumnami (wektorami własnymi) z macierzy U i V.\n",
@ -109,7 +113,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 13,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -150,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 14,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -185,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 15,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -223,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 18,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -244,15 +248,17 @@
"\n",
"list_widget = widgets.Dropdown(options=list(gray_images.keys()))\n",
"int_slider_widget = widgets.IntSlider(min=1,max=compute_k_max('cat'))\n",
"\n",
"def update_k_max(*args):\n",
" img_name=list_widget.value\n",
" int_slider_widget.max = compute_k_max(img_name)\n",
"\n",
"list_widget.observe(update_k_max,'value')\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 33,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -279,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 34,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -289,7 +295,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3909141856c04409b28f9d02306ef5a6",
"model_id": "93aa562a15a44f30bb5fda5ee40fbf5f",
"version_major": 2,
"version_minor": 0
},
@ -306,7 +312,7 @@
"<function __main__.print_matrices(img_name, k)>"
]
},
"execution_count": 25,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
@ -317,7 +323,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 36,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -327,7 +333,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7ca89c134f914dc9bcd4372a352eae5a",
"model_id": "bce351d98f7b471eaebc4e9a02d4396b",
"version_major": 2,
"version_minor": 0
},
@ -356,7 +362,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 37,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -411,7 +417,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -446,7 +452,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -470,66 +476,26 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "de4cb84649574a71b1f36d77a7f6e893",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='img_name', options=('cat', 'astro', 'coffee', 'koala', 'orange'), …"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<function __main__.print_matrices(img_name, k)>"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"interact(print_matrices, img_name=list_widget, k=int_slider_widget)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "be1b04fae0ac4bd4916d48fc5b6eb7d6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='img_name', options=('cat', 'astro', 'coffee', 'koala', 'orange'), …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"interact(compress_show_color_images_reshape,img_name=list_widget,k=int_slider_widget);"
]
@ -558,7 +524,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -596,7 +562,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -620,28 +586,13 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "25bd4e6560f841569923087e4eae6e8c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='img_name', options=('cat', 'astro', 'coffee', 'koala', 'orange'), …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"interact(compress_show_color_images_layer,img_name=list_widget,k=int_slider_widget);"
]
@ -649,7 +600,22 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": []
}