Exemplo n.º 1
0
    def __init__(self,
                 adj=None,
                 gml_path=None,
                 csv_path=None,
                 leiden=True,
                 threshold=0,
                 gamma=1,
                 n_comms=5,
                 seed=None):
        self.adj = adj
        if adj is not None:
            self.adj = get_adj(adj)
        self.gml_path = gml_path
        self.csv_path = csv_path
        self.detector = leidenalg if leiden else louvain
        self.threshold = threshold
        self.gamma = gamma
        self.n_comms = n_comms
        self.seed = seed

        self.graph = None
        self.main_sub = None
        self.partition = None
        self.df = None
        self.tempfile_path = None
        if self.gml_path is None:
            self.tempfile_path = Path(str(uuid.uuid4()) + '.gml')
Exemplo n.º 2
0
def visualize_distro(adj, out_path, sample=None):
    adj = get_adj(adj)
    if isinstance(adj, pd.DataFrame):
        adj = adj.values
    if sample is not None:
        if not 0 < sample <= 1:
            raise ValueError('Value of sample must satisfy: 0 < sample <= 1')
        size = int(len(adj) * sample)
        rows = np.random.choice(len(adj), size, replace=False)
        cols = np.random.choice(len(adj), size, replace=False)
        adj = adj[rows][:, cols]
    flat = adj.ravel()
    mean = flat.mean()
    std = flat.std()
    std1 = mean + std
    std2 = mean + (2 * std)
    ax = sns.distplot(flat, label=f'Distro (n={flat.size})')
    y_max = ax.get_ylim()[1]
    plt.plot((mean, mean), (0, y_max / 2), label='Mean')
    plt.plot((std1, std1), (0, y_max / 2), label='Mean + 1 std. dev.')
    plt.plot((std2, std2), (0, y_max / 2), label='Mean + 2 std. dev.')
    plt.xlabel('r-value')
    plt.legend()
    plt.savefig(out_path, bbox_inches='tight', dpi=600)
    return mean, std
Exemplo n.º 3
0
 def test_get_adj_str_df(self, tmpdir):
     adj_path = self._save_adj(tmpdir, binary=False)
     adj = utils.get_adj(adj_path)
     assert type(adj) == pd.DataFrame
Exemplo n.º 4
0
 def test_get_adj_str_ndarray(self, tmpdir):
     adj_path = self._save_adj(tmpdir)
     adj = utils.get_adj(adj_path)
     assert type(adj) == np.ndarray
Exemplo n.º 5
0
 def test_get_adj_df(self):
     expected = self._build_adj()
     adj = utils.get_adj(expected)
     assert type(adj) == pd.DataFrame
Exemplo n.º 6
0
 def test_get_adj_ndarray(self):
     expected = self._build_adj().values
     adj = utils.get_adj(expected)
     assert type(adj) == np.ndarray