Skip to content

Commit

Permalink
Merge branch 'visualize-row-col-ops'
Browse files Browse the repository at this point in the history
  • Loading branch information
beachdweller committed May 18, 2023
2 parents ba4cda7 + ae737ff commit 681c25d
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 14 deletions.
93 changes: 91 additions & 2 deletions 60_linear_algebra_2/100_Systems_of_Linear_Equations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import numpy.random as nr\n",
"import sympy as sy\n",
Expand Down Expand Up @@ -157,6 +158,40 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"def hinton(matrix, max_weight=None, ax=None):\n",
" '''\n",
" Draw Hinton diagram for visualizing a weight matrix.\n",
" https://matplotlib.org/stable/gallery/specialty_plots/hinton_demo.html\n",
" '''\n",
" ax = ax if ax is not None else plt.gca()\n",
"\n",
" if not max_weight:\n",
" max_weight = 2 ** np.ceil(np.log2(np.abs(matrix).max()))\n",
"\n",
" ax.patch.set_facecolor('gray')\n",
" ax.set_aspect('equal', 'box')\n",
"\n",
" ax.xaxis.set_major_locator(plt.NullLocator())\n",
" ax.yaxis.set_major_locator(plt.NullLocator())\n",
"\n",
" for (y, x), w in np.ndenumerate(matrix):\n",
" color = 'white' if w > 0 else 'black'\n",
" size = np.sqrt(abs(w) / max_weight)\n",
" rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,\n",
" facecolor=color, edgecolor=color)\n",
" ax.add_patch(rect)\n",
"\n",
" ax.autoscale_view()\n",
" ax.invert_yaxis()\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -216,6 +251,16 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"hinton(Ab)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -278,6 +323,16 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"hinton(Ab)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -359,6 +414,16 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"hinton(Ab)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -435,7 +500,7 @@
"metadata": {},
"outputs": [],
"source": [
"sol = sy.Matrix([None] * n)\n",
"sol = sy.Matrix([sy.Symbol('None')] * n)\n",
"\n"
]
},
Expand Down Expand Up @@ -773,6 +838,16 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"hinton(Ab_list)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -794,6 +869,16 @@
"\n"
]
},
{
"cell_type": "code",
"source": [
"hinton(Ab_list)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -918,8 +1003,12 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 0
}
Loading

0 comments on commit 681c25d

Please sign in to comment.