Skip to content

Commit

Permalink
Merge pull request #32 from barahona-research-group/small_corrections
Browse files Browse the repository at this point in the history
small corrections
  • Loading branch information
arnaudon authored Feb 15, 2021
2 parents 91032a0 + cebf105 commit 1e2516e
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 123 deletions.
23 changes: 0 additions & 23 deletions examples/params.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions examples/run_simple_example.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< Updated upstream
#!/bin/bash

python create_graph.py
Expand All @@ -15,12 +14,6 @@ pygenstability run \
# sbm_graph.pkl

pygenstability plot_scan --help
=======
#!/bin/zsh

python create_graph.py
pygenstability run --n-time 100 sbm_graph.pkl
>>>>>>> Stashed changes
pygenstability plot_scan results.pkl

pygenstability plot_communities --help
Expand Down
5 changes: 3 additions & 2 deletions examples/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def simple_test():

all_results = run(graph)

plotting.plot_scan(all_results, use_plotly=True)
plotting.plot_scan(all_results, use_plotly=False)
plotting.plot_scan(all_results, use_plotly=True, live=False)

with open("sbm_graph.gpickle", "rb") as pickle_file:
graph = pickle.load(pickle_file)
plotting.plot_communities(graph, all_results)
plotting.plot_sankey(all_results)
plotting.plot_sankey(all_results, live=False)


if __name__ == "__main__":
Expand Down
21 changes: 17 additions & 4 deletions pygenstability/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
DTYPE = "float128"


def load_constructor(constructor):
def load_constructor(constructor, graph, **kwargs):
"""Load a constructor from its name, or as a custom Constructor class."""
if isinstance(constructor, str):
if graph is None:
raise Exception(f"No graph was provided with a generic constructor {constructor}")
try:
return getattr(sys.modules[__name__], "constructor_%s" % constructor)
return getattr(sys.modules[__name__], "constructor_%s" % constructor)(graph, **kwargs)
except AttributeError as exc:
raise Exception("Could not load constructor %s" % constructor) from exc
if not isinstance(constructor, Constructor):
Expand Down Expand Up @@ -53,10 +55,21 @@ def get_spectral_gap(laplacian):


class Constructor:
"""Parent constructor class."""
"""Parent constructor class.
This class encodes method specific construction of quality matrix and null models.
Use the method prepare to load and compute time independent quantities, and the method get_data
to return quality matrix, null model, and possible global shift (for linearised stability).
"""

def __init__(self, graph, with_spectral_gap=False, **kwargs):
"""Initialise constructor."""
"""The constructor calls te prepare method upon initialisation.
Args:
graph (csgraph): graph for which to run clustering
with_spectral_gap (bool): set to True to use spectral gap time rescale if available
kwargs (dict): any other properties to pass to the constructor.
"""
self.graph = graph
self.with_spectral_gap = with_spectral_gap
self.spectral_gap = None
Expand Down
Loading

0 comments on commit 1e2516e

Please sign in to comment.