Skip to content

Commit

Permalink
Simplify imports
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudon committed Oct 16, 2023
1 parent b262002 commit a853bae
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 39 deletions.
10 changes: 5 additions & 5 deletions examples/Example_1_undirected_sbm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"source": [
"import networkx as nx\n",
"\n",
"from pygenstability import run, plotting\n",
"import pygenstability as pgs\n",
"\n",
"import create_graph"
]
Expand Down Expand Up @@ -59,7 +59,7 @@
],
"source": [
"# run Markov Stability\n",
"all_results = run(adjacency, min_scale=-1, max_scale = 0.75, n_scale = 30, constructor='continuous_normalized')"
"all_results = pgs.run(adjacency, min_scale=-1, max_scale = 0.75, n_scale = 30, constructor='continuous_normalized')"
]
},
{
Expand All @@ -80,7 +80,7 @@
],
"source": [
"# plot the results matplotlib\n",
"_ = plotting.plot_scan(all_results, use_plotly=False)"
"_ = pgs.plot_scan(all_results, use_plotly=False)"
]
},
{
Expand All @@ -101,7 +101,7 @@
],
"source": [
"# plot partition at scale index t\n",
"plotting.plot_single_partition(nx_graph, all_results, scale_id=5)"
"pgs.plot_single_partition(nx_graph, all_results, scale_id=5)"
]
},
{
Expand All @@ -122,7 +122,7 @@
],
"source": [
"# plot optimal partitions\n",
"plotting.plot_optimal_partitions(nx_graph, all_results, show=True)"
"pgs.plot_optimal_partitions(nx_graph, all_results, show=True)"
]
},
{
Expand Down
6 changes: 2 additions & 4 deletions examples/Example_2_multiscale.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"outputs": [],
"source": [
"import pygenstability as pgs\n",
"from pygenstability import plotting\n",
"from pygenstability.pygenstability import evaluate_NVI\n",
"import scipy.sparse as sp\n",
"\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -132,7 +130,7 @@
"source": [
"# plots results\n",
"plt.figure(figsize=(7, 5))\n",
"axes = plotting.plot_scan(results, figure_name=None)\n",
"axes = pgs.plot_scan(results, figure_name=None)\n",
"axes[3].set_ylim(0, 50)\n",
"axes[3].axhline(3, ls=\"--\", color=\"k\", zorder=-1, lw=0.5)\n",
"axes[3].axhline(9, ls=\"--\", color=\"k\", zorder=-1, lw=0.5)\n",
Expand Down Expand Up @@ -160,7 +158,7 @@
"# compare MS partitions to ground truth with NVI\n",
"def _get_NVI(ref_ids):\n",
" return [\n",
" evaluate_NVI([0, i + 1], [ref_ids] + results[\"community_id\"])\n",
" pgs.evaluate_NVI([0, i + 1], [ref_ids] + results[\"community_id\"])\n",
" for i in range(len(results[\"scales\"]))\n",
" ]\n",
"\n",
Expand Down
19 changes: 9 additions & 10 deletions examples/Example_3_directed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"import networkx as nx\n",
"import scipy.sparse as sp\n",
"\n",
"from pygenstability import run, plotting, constructors\n",
"from pygenstability.optimal_scales import identify_optimal_scales"
"import pygenstability as pgs\n"
]
},
{
Expand Down Expand Up @@ -49,7 +48,7 @@
],
"source": [
"# scan markov scale for communities\n",
"all_results = run(sp.csgraph.csgraph_from_dense(adjacency), \n",
"all_results = pgs.run(sp.csgraph.csgraph_from_dense(adjacency), \n",
" min_scale=-1.0, \n",
" max_scale=1.0, \n",
" n_scale=90, \n",
Expand All @@ -76,8 +75,8 @@
],
"source": [
"# select optimal scales\n",
"all_results = identify_optimal_scales(all_results,kernel_size=30,window_size=10)\n",
"_ = plotting.plot_scan(all_results)"
"all_results = pgs.identify_optimal_scales(all_results,kernel_size=30,window_size=10)\n",
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -110,7 +109,7 @@
],
"source": [
"# plot optimal partitions\n",
"plotting.plot_optimal_partitions(nx_graph, all_results, show=True)"
"pgs.plot_optimal_partitions(nx_graph, all_results, show=True)"
]
},
{
Expand All @@ -131,7 +130,7 @@
],
"source": [
"# scan markov scale for communities using linearized directed\n",
"all_results = run(sp.csgraph.csgraph_from_dense(adjacency), \n",
"all_results = pgs.run(sp.csgraph.csgraph_from_dense(adjacency), \n",
" min_scale=-1.0, \n",
" max_scale=1.0, \n",
" n_scale=90, \n",
Expand All @@ -158,8 +157,8 @@
],
"source": [
"# select optimal scales\n",
"all_results = identify_optimal_scales(all_results,kernel_size=30,window_size=10)\n",
"_ = plotting.plot_scan(all_results)"
"all_results = pgs.identify_optimal_scales(all_results,kernel_size=30,window_size=10)\n",
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -190,7 +189,7 @@
],
"source": [
"# plot optimal partitions\n",
"plotting.plot_optimal_partitions(nx_graph, all_results, show=True)"
"pgs.plot_optimal_partitions(nx_graph, all_results, show=True)"
]
}
],
Expand Down
14 changes: 7 additions & 7 deletions examples/Example_4_constructors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"source": [
"import networkx as nx\n",
"\n",
"from pygenstability import run, plotting\n",
"import pygenstability as pgs\n",
"import create_graph"
]
},
Expand Down Expand Up @@ -76,8 +76,8 @@
}
],
"source": [
"all_results = run(adjacency, min_scale=-1, max_scale=1, n_scale=30, constructor='linearized')\n",
"_ = plotting.plot_scan(all_results)"
"all_results = pgs.run(adjacency, min_scale=-1, max_scale=1, n_scale=30, constructor='linearized')\n",
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -113,8 +113,8 @@
}
],
"source": [
"all_results = run(adjacency, min_scale=-0.5, max_scale =.2, n_scale=30, constructor='continuous_combinatorial')\n",
"_ = plotting.plot_scan(all_results)"
"all_results = pgs.run(adjacency, min_scale=-0.5, max_scale =.2, n_scale=30, constructor='continuous_combinatorial')\n",
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -150,8 +150,8 @@
}
],
"source": [
"all_results = run(adjacency, min_scale=-1, max_scale=1, n_scale=30, constructor='continuous_normalized')\n",
"_ = plotting.plot_scan(all_results)"
"all_results = pgs.run(adjacency, min_scale=-1, max_scale=1, n_scale=30, constructor='continuous_normalized')\n",
"_ = pgs.plot_scan(all_results)"
]
}
],
Expand Down
9 changes: 4 additions & 5 deletions examples/Example_5_hypergraph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"import matplotlib.pyplot as plt\n",
"\n",
"import pygenstability as pgs\n",
"from pygenstability import plotting\n",
"\n",
"import hypernetx as hnx"
]
Expand Down Expand Up @@ -169,7 +168,7 @@
}
],
"source": [
"_ = plotting.plot_scan(results_hypergraph_projection)"
"_ = pgs.plot_scan(results_hypergraph_projection)"
]
},
{
Expand Down Expand Up @@ -214,7 +213,7 @@
"# plot the partition at the optimal scale\n",
"for scale in results_hypergraph_projection['selected_partitions']:\n",
" plt.figure()\n",
" plotting.plot_single_partition(nx_graph, results_hypergraph_projection, scale_id=scale)"
" pgs.plot_single_partition(nx_graph, results_hypergraph_projection, scale_id=scale)"
]
},
{
Expand Down Expand Up @@ -313,7 +312,7 @@
],
"source": [
"# note the 3-way partition that now appears\n",
"_ = plotting.plot_scan(results_hypergraph_ew)"
"_ = pgs.plot_scan(results_hypergraph_ew)"
]
},
{
Expand Down Expand Up @@ -368,7 +367,7 @@
"# plot the partition at the optimal scale\n",
"for scale in results_hypergraph_ew['selected_partitions']:\n",
" plt.figure()\n",
" plotting.plot_single_partition(nx_graph, results_hypergraph_ew, scale_id=scale)"
" pgs.plot_single_partition(nx_graph, results_hypergraph_ew, scale_id=scale)"
]
}
],
Expand Down
15 changes: 7 additions & 8 deletions examples/Example_6_signed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"import numpy as np\n",
"import scipy.sparse as sp\n",
"\n",
"from pygenstability import run, plotting, constructors\n",
"from pygenstability.optimal_scales import identify_optimal_scales"
"import pygenstability as pgs\n"
]
},
{
Expand Down Expand Up @@ -98,7 +97,7 @@
],
"source": [
"# apply MS analysis using signed modularity\n",
"all_results = run(sp.csgraph.csgraph_from_dense(adjacency), \n",
"all_results = pgs.run(sp.csgraph.csgraph_from_dense(adjacency), \n",
" min_scale=-1, \n",
" max_scale=1.0, \n",
" n_scale=90, \n",
Expand All @@ -123,7 +122,7 @@
],
"source": [
"# select optimal scales\n",
"_ = plotting.plot_scan(all_results)"
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -166,7 +165,7 @@
],
"source": [
"# plot optimal partitions\n",
"plotting.plot_optimal_partitions(nx_graph, all_results, show=True)"
"pgs.plot_optimal_partitions(nx_graph, all_results, show=True)"
]
},
{
Expand Down Expand Up @@ -210,7 +209,7 @@
],
"source": [
"# apply MS analysis using signed combinatorial Laplacian\n",
"all_results = run(sp.csgraph.csgraph_from_dense(adjacency), \n",
"all_results = pgs.run(sp.csgraph.csgraph_from_dense(adjacency), \n",
" min_scale=-2.0, \n",
" max_scale=1.0, \n",
" n_scale=90, \n",
Expand All @@ -235,7 +234,7 @@
],
"source": [
"# select optimal scales\n",
"_ = plotting.plot_scan(all_results)"
"_ = pgs.plot_scan(all_results)"
]
},
{
Expand Down Expand Up @@ -276,7 +275,7 @@
],
"source": [
"# plot optimal partitions\n",
"plotting.plot_optimal_partitions(nx_graph, all_results, show=True)"
"pgs.plot_optimal_partitions(nx_graph, all_results, show=True)"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/pygenstability/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
from pygenstability.io import load_results
from pygenstability.io import save_results
from pygenstability.pygenstability import run
from pygenstability.pygenstability import evaluate_NVI
from pygenstability.plotting import *
from pygenstability.optimal_scales import identify_optimal_scales

0 comments on commit a853bae

Please sign in to comment.