Skip to content

Commit

Permalink
Standardize docs (#525)
Browse files Browse the repository at this point in the history
* Standardized first half of tutorials

* updating repo to match upstream

* Suppressing graph messages up to latent_position_test

* finished standardizing tutorials

* standardize simulations

* second standardize of simulations

* standardize models

* standardize embed

* standardize cluster

* standardize inference

* standardize plot

* standardize datasets

* standardize utility

* standardize pipeline

* standardize matching

* standardize subgraph

* standardize align

* blackened repo

* fixing the version.txt file

* responding to feedback

* Correcting version to 3.7.0

* Changing to _ = to suppress graph summary output

* Blackened repo

* Final check of netlify build

* correcting minor typos

* correcting one last typo

Co-authored-by: Benjamin Pedigo <benjamindpedigo@gmail.com>
  • Loading branch information
pauladkisson and bdpedigo authored Nov 6, 2020
1 parent 35eeb90 commit 8d7d29f
Show file tree
Hide file tree
Showing 43 changed files with 292 additions and 300 deletions.
10 changes: 5 additions & 5 deletions docs/tutorials/embedding/AdjacencySpectralEmbed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
"undirected_sbm = sbm(2 * [n_verts], P)\n",
"heatmap(undirected_sbm, title='2-block SBM (undirected)', inner_hier_labels=labels_sbm)\n",
"directed_sbm = sbm(2 * [n_verts], P, directed=True)\n",
"heatmap(directed_sbm, title='2-block SBM (directed)', inner_hier_labels=labels_sbm)"
"_ = heatmap(directed_sbm, title='2-block SBM (directed)', inner_hier_labels=labels_sbm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the AdjacencySpectralEmbed class to embed the adjacency matrix as follows. If no parameters are given to the AdjacencySpectralEmbed class, it will automatically choose the number of dimensions to embed into."
"We can use the ``AdjacencySpectralEmbed`` class to embed the adjacency matrix as follows. If no parameters are given to the ``AdjacencySpectralEmbed`` class, it will automatically choose the number of dimensions to embed into."
]
},
{
Expand All @@ -64,7 +64,7 @@
"source": [
"ase = AdjacencySpectralEmbed()\n",
"Xhat = ase.fit_transform(undirected_sbm)\n",
"pairplot(Xhat, title='SBM adjacency spectral embedding')"
"_ = pairplot(Xhat, title='SBM adjacency spectral embedding')"
]
},
{
Expand All @@ -83,7 +83,7 @@
"ase = AdjacencySpectralEmbed()\n",
"Xhat, Yhat = ase.fit_transform(directed_sbm)\n",
"pairplot(Xhat, title='SBM adjacency spectral embedding \"out\"')\n",
"pairplot(Yhat, title='SBM adjacency spectral embedding \"in\"')"
"_ = pairplot(Yhat, title='SBM adjacency spectral embedding \"in\"')"
]
},
{
Expand All @@ -101,7 +101,7 @@
"source": [
"ase = AdjacencySpectralEmbed(n_components=2, algorithm='truncated')\n",
"Xhat = ase.fit_transform(undirected_sbm)\n",
"pairplot(Xhat, title='2-component embedding', height=4)"
"_ = pairplot(Xhat, title='2-component embedding', height=4)"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/embedding/Omnibus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"\n",
"\\begin{align*}\n",
"P_1 = \n",
"\\begin{bmatrix}0.2 & 0.1\\\\\n",
"\\begin{bmatrix}0.3 & 0.1\\\\\n",
"0.1 & 0.7\n",
"\\end{bmatrix},~\n",
"P_2 = \\begin{bmatrix}0.2 & 0.1\\\\\n",
"0.1 & 0.2\n",
"P_2 = \\begin{bmatrix}0.3 & 0.1\\\\\n",
"0.1 & 0.3\n",
"\\end{bmatrix}\n",
"\\end{align*}\n",
"\n",
Expand Down Expand Up @@ -82,7 +82,7 @@
"from graspologic.plot import heatmap\n",
"\n",
"heatmap(G1, figsize=(7, 7), title='Visualization of Graph 1')\n",
"heatmap(G2, figsize=(7, 7), title='Visualization of Graph 2')"
"_ = heatmap(G2, figsize=(7, 7), title='Visualization of Graph 2')"
]
},
{
Expand Down Expand Up @@ -152,7 +152,7 @@
"for i in range(50):\n",
" ax.plot([Xhat1[i, 0], Xhat2[i, 0]], [Xhat1[i, 1], Xhat2[i, 1]], 'black', alpha = 0.15)\n",
" \n",
"ax.set_title('Latent Positions from Omnibus Embedding', fontsize=20)"
"_ = ax.set_title('Latent Positions from Omnibus Embedding', fontsize=20)"
]
}
],
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/inference/latent_distribution_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"A1 = sbm(csize, P)\n",
"X1 = AdjacencySpectralEmbed(n_components=n_components).fit_transform(A1)\n",
"heatmap(A1, title='2-block SBM adjacency matrix')\n",
"pairplot(X1, title='2-block adjacency spectral embedding', height=4.5)"
"_ = pairplot(X1, title='2-block adjacency spectral embedding', height=4.5)"
]
},
{
Expand All @@ -72,7 +72,7 @@
"A1 = sbm(csize, P)\n",
"X1 = AdjacencySpectralEmbed(n_components=n_components).fit_transform(A1)\n",
"heatmap(A2, title='2-block SBM adjacency matrix')\n",
"pairplot(X2, title='2-block adjacency spectral embedding', height=4.5)"
"_ = pairplot(X2, title='2-block adjacency spectral embedding', height=4.5)"
]
},
{
Expand Down Expand Up @@ -144,7 +144,7 @@
"ax[1].hist(ldt_mgc.null_distribution_, 50)\n",
"ax[1].axvline(ldt_mgc.sample_T_statistic_, color='r')\n",
"ax[1].set_title(\"MGC: P-value = {}\".format(ldt_mgc.p_value_), fontsize=20)\n",
"plt.show();"
"_ = plt.show()"
]
},
{
Expand Down Expand Up @@ -175,7 +175,7 @@
"A3 = sbm(csize, P2)\n",
"heatmap(A3, title='2-block SBM adjacency matrix A3')\n",
"X3 = AdjacencySpectralEmbed(n_components=n_components).fit_transform(A3)\n",
"pairplot(X3, title='2-block adjacency spectral embedding A3', height=4.5)"
"_ = pairplot(X3, title='2-block adjacency spectral embedding A3', height=4.5)"
]
},
{
Expand Down Expand Up @@ -231,7 +231,7 @@
"ax[1].hist(ldt_mgc.null_distribution_, 50)\n",
"ax[1].axvline(ldt_mgc.sample_T_statistic_, color='r')\n",
"ax[1].set_title(\"MGC: P-value = {}\".format(ldt_mgc.p_value_), fontsize=20)\n",
"plt.show();"
"_ = plt.show()"
]
}
],
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorials/inference/latent_position_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@
"A = sbm(csize, P)\n",
"X = AdjacencySpectralEmbed(n_components=n_components).fit_transform(A)\n",
"heatmap(A, title='4-block SBM adjacency matrix')\n",
"pairplot(X, title='4-block adjacency spectral embedding')"
"_ = pairplot(X, title='4-block adjacency spectral embedding')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the adjacency matrix above, there is a clearly defined block structrure corresponding to the 4 communities in the graph that we established. On the right, we see the **adjacency spectral embedding (ASE)** of this graph. ASE(A) recovers an estimate of the **latent positions** of $A $. Latent positions refer to the idea of a **random dot product graph (RDPG)** which can be modeled as follows:\n",
"In the adjacency matrix above, there is a clearly defined block structrure corresponding to the 4 communities in the graph that we established. On the right, we see the **adjacency spectral embedding (ASE)** of this graph. $\\text{ASE}(A)$ recovers an estimate of the **latent positions** of $A$. Latent positions refer to the idea of a **random dot product graph (RDPG)** which can be modeled as follows:\n",
"\n",
"For an adjacency matrix $A \\in \\mathbb{R}^{n x n}$, the probability of an edge existing between node $i$ and node $j$ (aka whether or not $A_{ij}$ is a 1) is determined by the matrix $P \\in \\mathbb{R}^{n x n}$\n",
"For an adjacency matrix $A \\in \\mathbb{R}^{n \\times n}$, the probability of an edge existing between node $i$ and node $j$ (aka whether or not $A_{ij}$ is a 1) is determined by the matrix $P \\in \\mathbb{R}^{n \\times n}$\n",
"\n",
"$P = XX^T$, where $X \\in \\mathbb{R}^{n x d} $ and is referred to as the latent positions of the graph. $X$ is referred to as the latent positions of the graph because each node $n_i$ is modeled as having a hidden, usually unobserved location in $\\mathbb{R}^d$ (we'll call it $x_i$). The probability of an edge existing between $n_i$ and $n_j$ is equal to the dot product $x_i \\cdot x_j$\n",
"$P = XX^T$, where $X \\in \\mathbb{R}^{n \\times d}$ and is referred to as the latent positions of the graph. $X$ is referred to as the latent positions of the graph because each node $n_i$ is modeled as having a hidden, usually unobserved location in $\\mathbb{R}^d$ (we'll call it $x_i$). The probability of an edge existing between $n_i$ and $n_j$ is equal to the dot product $x_i \\cdot x_j$\n",
"\n",
"ASE is one way to obtain an estimate of the latent positions of a graph, $\\hat{X}$\n",
"\n",
Expand All @@ -73,7 +73,7 @@
"metadata": {},
"source": [
"## Sample new RDPGs from this latent position\n",
"Given the estimate of X, we now sample two new RDPGs from the same latent position above"
"Given the estimate of $X$, we now sample two new RDPGs from the same latent position above"
]
},
{
Expand All @@ -97,7 +97,7 @@
"heatmap(A1, title='Sampled RDPG 1 adjacency matrix')\n",
"heatmap(A2, title='Sampled RDPG 2 adjacency matrix')\n",
"pairplot(Xhat1, title='Sampled RDPG 1 adjacency spectral embedding')\n",
"pairplot(Xhat2, title='Sampled RDPG 2 adjacency spectral embedding')"
"_ = pairplot(Xhat2, title='Sampled RDPG 2 adjacency spectral embedding')"
]
},
{
Expand All @@ -120,7 +120,7 @@
"\n",
"Here, R is an orthogonal rotation matrix found from solving the [orthogonal procrustes problem](https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.linalg.orthogonal_procrustes.html) (Note: this constraint can be relaxed for other versions of semipar)\n",
"\n",
"Note that LatentPositionTest.fit() may take several minutes"
"Note that ``LatentPositionTest.fit()`` may take several minutes"
]
},
{
Expand Down Expand Up @@ -177,7 +177,7 @@
"heatmap(A3, title='Sampled RDPG 3 adjacency matrix')\n",
"heatmap(A4, title='Sampled RDPG 4 (distorted) adjacency matrix')\n",
"pairplot(Xhat3, title='Sampled RDPG 3 adjacency spectral embedding')\n",
"pairplot(Xhat4, title='Sampled RDPG 4 (distorted) adjacency spectral embedding')"
"_ = pairplot(Xhat4, title='Sampled RDPG 4 (distorted) adjacency spectral embedding')"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/tutorials/matching/faq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"\n",
"\\begin{equation}\n",
"\\begin{aligned}\n",
"\\min & {\\;-trace(APB^T P^T)}\\\\\n",
"\\min & {\\;-\\text{trace}(APB^T P^T)}\\\\\n",
"\\text{s.t. } & {\\;P \\: \\epsilon \\: \\mathcal{P}} \\\\\n",
"\\end{aligned}\n",
"\\end{equation}\n",
Expand All @@ -44,7 +44,7 @@
"\n",
"\\begin{equation}\n",
"\\begin{aligned}\n",
"\\min & {\\; trace(APB^T P^T)}\\\\\n",
"\\min & {\\; \\text{trace}(APB^T P^T)}\\\\\n",
"\\text{s.t. } & {\\;P \\: \\epsilon \\: \\mathcal{P}} \\\\\n",
"\\end{aligned}\n",
"\\end{equation}\n",
Expand Down Expand Up @@ -110,7 +110,7 @@
"source": [
"from graspologic.plot import heatmap\n",
"heatmap(G1, cbar=False, title = 'G1 [ER-NP(50, 0.3) Simulation]')\n",
"heatmap(G2, cbar=False, title = 'G2 [G1 Randomly Shuffled]')"
"_ = heatmap(G2, cbar=False, title = 'G2 [G1 Randomly Shuffled]')"
]
},
{
Expand Down Expand Up @@ -141,7 +141,7 @@
"outputs": [],
"source": [
"heatmap(G1, cbar=False, title = 'G1[ER-NP(50, 0.3) Simulation]')\n",
"heatmap(G2, cbar=False, title = 'G2[ER-NP(50, 0.3) Randomly Shuffled] unshuffled')"
"_ = heatmap(G2, cbar=False, title = 'G2[ER-NP(50, 0.3) Randomly Shuffled] unshuffled')"
]
}
],
Expand Down
11 changes: 2 additions & 9 deletions docs/tutorials/matching/padded_gm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"heatmap(G1p, ax=axs[0], cbar=False, title=\"G1'\")\n",
"heatmap(G2, ax=axs[1], cbar=False, title=\"G2\")\n",
"heatmap(c, ax=axs[2], cbar=False, title=\"G1\")\n",
"heatmap(topleft_G1, ax=axs[3], cbar=False, title=\"G1 (to top left corner)\")"
"_ = heatmap(topleft_G1, ax=axs[3], cbar=False, title=\"G1 (to top left corner)\")"
]
},
{
Expand Down Expand Up @@ -146,13 +146,6 @@
"\n",
"On the other hand, we see that adopted padding preserves the common block structure between $G_1$ and $G_2$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -171,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.7.0"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/matching/sgm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"fig, axs = plt.subplots(1, 3, figsize=(10, 5))\n",
"heatmap(A1, ax=axs[0], cbar=False, title=\"Graph 1\")\n",
"heatmap(A2, ax=axs[1], cbar=False, title=\"Graph 2\")\n",
"heatmap(A1 - A2, ax=axs[2], cbar=False, title=\"Diff (G1 - G2)\")"
"_ = heatmap(A1 - A2, ax=axs[2], cbar=False, title=\"Diff (G1 - G2)\")"
]
},
{
Expand Down Expand Up @@ -116,7 +116,7 @@
"fig, axs = plt.subplots(1, 3, figsize=(10, 5))\n",
"heatmap(A1, ax=axs[0], cbar=False, title=\"Graph 1\")\n",
"heatmap(A2_shuffle, ax=axs[1], cbar=False, title=\"Graph 2 shuffled\")\n",
"heatmap(A1 - A2_shuffle, ax=axs[2], cbar=False, title=\"Diff (G1 - G2 shuffled)\")\n"
"_ = heatmap(A1 - A2_shuffle, ax=axs[2], cbar=False, title=\"Diff (G1 - G2 shuffled)\")"
]
},
{
Expand Down Expand Up @@ -181,7 +181,7 @@
"heatmap(A1 - A2_unshuffle, ax=axs[2], cbar=False, title=\"Diff (G1 - G2 unshuffled)\")\n",
"\n",
"match_ratio = 1-(np.count_nonzero(abs(sgm.perm_inds_-node_unshuffle_input))/n_verts)\n",
"print(\"Match Ratio with 10 seeds: \", match_ratio)\n"
"print(\"Match Ratio with 10 seeds: \", match_ratio)"
]
},
{
Expand Down
26 changes: 13 additions & 13 deletions docs/tutorials/models/models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"\n",
"adj, labels = load_drosophila_right(return_labels=True)\n",
"adj = binarize(adj)\n",
"heatmap(adj,\n",
"_ = heatmap(adj,\n",
" inner_hier_labels=labels,\n",
" title='Drosophila right MB',\n",
" font_scale=1.5,\n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -115,11 +115,11 @@
" title=\"ER probability matrix\",\n",
" vmin=0, vmax=1, \n",
" sort_nodes=True)\n",
"heatmap(er.sample()[0],\n",
"_ = heatmap(er.sample()[0],\n",
" inner_hier_labels=labels,\n",
" font_scale=1.5,\n",
" title=\"ER sample\",\n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -154,11 +154,11 @@
" font_scale=1.5,\n",
" title=\"DCER probability matrix\", \n",
" sort_nodes=True);\n",
"heatmap(dcer.sample()[0],\n",
"_ = heatmap(dcer.sample()[0],\n",
" inner_hier_labels=labels,\n",
" font_scale=1.5,\n",
" title=\"DCER sample\", \n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -191,11 +191,11 @@
" font_scale=1.5,\n",
" title=\"SBM probability matrix\", \n",
" sort_nodes=True)\n",
"heatmap(sbme.sample()[0],\n",
"_ = heatmap(sbme.sample()[0],\n",
" inner_hier_labels=labels,\n",
" font_scale=1.5,\n",
" title=\"SBM sample\", \n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -230,11 +230,11 @@
" vmin=0,\n",
" vmax=1,\n",
" sort_nodes=True)\n",
"heatmap(dcsbme.sample()[0],\n",
"_ = heatmap(dcsbme.sample()[0],\n",
" inner_hier_labels=labels,\n",
" title=\"DCSBM sample\",\n",
" font_scale=1.5,\n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -271,11 +271,11 @@
" title=\"RDPG probability matrix\",\n",
" sort_nodes=True\n",
" )\n",
"heatmap(rdpge.sample()[0],\n",
"_ = heatmap(rdpge.sample()[0],\n",
" inner_hier_labels=labels,\n",
" font_scale=1.5,\n",
" title=\"RDPG sample\",\n",
" sort_nodes=True);"
" sort_nodes=True)"
]
},
{
Expand Down Expand Up @@ -336,7 +336,7 @@
"# add colorbar\n",
"sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)\n",
"sm.set_array(dcsbme.p_mat_)\n",
"fig.colorbar(sm,\n",
"_ = fig.colorbar(sm,\n",
" ax=axs,\n",
" orientation=\"horizontal\",\n",
" pad=0.04,\n",
Expand Down
11 changes: 2 additions & 9 deletions docs/tutorials/simulations/corr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"source": [
"from graspologic.plot import heatmap\n",
"heatmap(G1, title = 'Correlated ER Simulation Graph 1')\n",
"heatmap(G2, title = 'Correlated ER Simulation Graph 2')"
"_ = heatmap(G2, title = 'Correlated ER Simulation Graph 2')"
]
},
{
Expand Down Expand Up @@ -147,15 +147,8 @@
"outputs": [],
"source": [
"heatmap(G1, title = 'Correlated SBM Simulation Graph 1')\n",
"heatmap(G2, title = 'Correlated SBM Simulation Graph 2')"
"_ = heatmap(G2, title = 'Correlated SBM Simulation Graph 2')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 8d7d29f

Please sign in to comment.