Skip to content

Commit

Permalink
v20240317.4
Browse files Browse the repository at this point in the history
  • Loading branch information
xbresson committed Mar 17, 2024
1 parent 6bbcd53 commit 11f665e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 62 deletions.
44 changes: 24 additions & 20 deletions codes/02_Graph_Science/code01.ipynb

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions codes/02_Graph_Science/code02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
" print(path_to_file)\n",
" # change current path to the folder containing \"path_to_file\"\n",
" os.chdir(path_to_file)\n",
" !pwd"
" !pwd\n",
" "
]
},
{
Expand Down Expand Up @@ -81,7 +82,7 @@
"\n",
"# Remove warnings\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
Expand All @@ -102,7 +103,7 @@
"mat = scipy.io.loadmat('datasets/discoboy_network.mat')\n",
"X = mat['X']\n",
"W = mat['W']\n",
"print(X.shape,W.shape)"
"print(X.shape,W.shape)\n"
]
},
{
Expand All @@ -126,7 +127,7 @@
"plt.figure(10)\n",
"size_vertex_plot = 20.\n",
"plt.scatter(X[:,0], X[:,1], s=size_vertex_plot*np.ones(X.shape[0]), color=pyplot.jet())\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand All @@ -139,7 +140,7 @@
"L = graph_laplacian(W)\n",
"\n",
"# Compute modes of variations of graph system = Fourier functions\n",
"lamb, U = scipy.sparse.linalg.eigsh(L, k=9, which='SM')"
"lamb, U = scipy.sparse.linalg.eigsh(L, k=9, which='SM')\n"
]
},
{
Expand Down Expand Up @@ -243,7 +244,8 @@
"for i in range(1,10):\n",
" plt.figure(str(10+i))\n",
" plt.scatter(X[:,0], X[:,1], c=U[:,i-1], s=size_vertex_plot*np.ones(X.shape[0]), color=pyplot.jet())\n",
" plt.show()"
" plt.show()\n",
" "
]
},
{
Expand Down Expand Up @@ -280,7 +282,7 @@
"plt.figure(20)\n",
"size_vertex_plot = 20.\n",
"plt.scatter(X[:,0], X[:,1], s=size_vertex_plot*np.ones(X.shape[0]), color=pyplot.jet())\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -390,7 +392,8 @@
"for i in range(1,10):\n",
" plt.figure(str(20+i))\n",
" plt.scatter(X[:,0], X[:,1], c=U[:,i-1], s=size_vertex_plot*np.ones(X.shape[0]), color=pyplot.jet())\n",
" plt.show()"
" plt.show()\n",
" "
]
},
{
Expand Down
33 changes: 17 additions & 16 deletions codes/02_Graph_Science/code03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
" print(path_to_file)\n",
" # change current path to the folder containing \"path_to_file\"\n",
" os.chdir(path_to_file)\n",
" !pwd"
" !pwd\n",
" "
]
},
{
Expand Down Expand Up @@ -81,7 +82,7 @@
"\n",
"# Remove warnings\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
Expand Down Expand Up @@ -120,7 +121,7 @@
"size_vertex_plot = 20.\n",
"plt.scatter(X[:,0], X[:,1], s=size_vertex_plot*np.ones(n), c=C, color=pyplot.jet())\n",
"plt.title('Visualization of two-moon datase (with ground truth), DIMENTIONALITY= ' + str(dim))\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -154,7 +155,7 @@
"plt.figure(31)\n",
"plt.scatter(Xzc[:,0], Xzc[:,1], s=size_vertex_plot*np.ones(n), c=C, color=pyplot.jet())\n",
"plt.title('Center the data')\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -188,7 +189,7 @@
"plt.figure(32)\n",
"plt.scatter(Xnvar[:,0], Xnvar[:,1], s=size_vertex_plot*np.ones(n), c=C, color=pyplot.jet())\n",
"plt.title('Normalize the variance')\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -222,7 +223,7 @@
"plt.figure(33)\n",
"plt.scatter(Xl2proj[:,0], Xl2proj[:,1], s=size_vertex_plot*np.ones(n), c=C, color=pyplot.jet())\n",
"plt.title('Projection on the L2-ball')\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -282,7 +283,7 @@
"#W.setdiag(0)\n",
"\n",
"print(W.shape)\n",
"print(W.nnz)"
"print(W.nnz)\n"
]
},
{
Expand Down Expand Up @@ -320,7 +321,7 @@
"\n",
"fig.tight_layout()\n",
"\n",
"fig.show()"
"fig.show()\n"
]
},
{
Expand All @@ -342,7 +343,7 @@
"source": [
"plt.figure(50)\n",
"plt.spy(W,precision=0.01, markersize=1, color=pyplot.jet())\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand All @@ -360,7 +361,7 @@
],
"source": [
"Cncut,acc = compute_ncut(W, C, 2)\n",
"print(acc)"
"print(acc)\n"
]
},
{
Expand All @@ -383,7 +384,7 @@
"plt.figure(75)\n",
"plt.scatter(X[:,0], X[:,1], s=size_vertex_plot*np.ones(n), c=Cncut, color=pyplot.jet())\n",
"plt.title('Clustering result with EUCLIDEAN distance, ACCURACY= '+ str(acc))\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -448,7 +449,7 @@
"#W.setdiag(0)\n",
"\n",
"print(W.shape)\n",
"print(W.nnz)"
"print(W.nnz)\n"
]
},
{
Expand Down Expand Up @@ -486,7 +487,7 @@
"\n",
"fig.tight_layout()\n",
"\n",
"fig.show()"
"fig.show()\n"
]
},
{
Expand All @@ -508,7 +509,7 @@
"source": [
"plt.figure(70)\n",
"plt.spy(W,precision=0.01, markersize=1, color=pyplot.jet())\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand All @@ -526,7 +527,7 @@
],
"source": [
"Cncut,acc = compute_ncut(W, C, 2)\n",
"print(acc)"
"print(acc)\n"
]
},
{
Expand All @@ -549,7 +550,7 @@
"plt.figure(77)\n",
"plt.scatter(X[:,0], X[:,1], s=size_vertex_plot*np.ones(n), c=Cncut, color=pyplot.jet())\n",
"plt.title('Clustering result with EUCLIDEAN distance, ACCURACY= '+ str(acc))\n",
"plt.show()"
"plt.show()\n"
]
},
{
Expand Down
Loading

0 comments on commit 11f665e

Please sign in to comment.