Skip to content

Commit

Permalink
LINT: Minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ntfrgl committed Dec 21, 2023
1 parent 7c9776a commit 33bf65a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
56 changes: 30 additions & 26 deletions src/pyunicorn/core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ def degree(self, key=None):
"""
Return list of degrees.
If a link attribute key is specified, return the associated strength
If a link attribute key is specified, return the associated strength.
**Example:**
Expand All @@ -1710,7 +1710,8 @@ def indegree(self, key=None):
"""
Return list of in-degrees.
If a link attribute key is specified, return the associated in strength
If a link attribute key is specified, return the associated
in-strength.
**Example:**
Expand All @@ -1730,8 +1731,8 @@ def outdegree(self, key=None):
"""
Return list of out-degrees.
If a link attribute key is specified, return the associated out
strength
If a link attribute key is specified, return the associated
out-strength.
**Example:**
Expand All @@ -1753,7 +1754,7 @@ def bildegree(self, key=None):
and out-going edges.
If a link attribute key is specified, return the associated bilateral
strength
strength.
**Exmaple:**
Expand All @@ -1779,13 +1780,13 @@ def sp_nsi_diag_k_inv(self):
return sp.diags([np.power(self.nsi_degree(), -1)], [0],
shape=(self.N, self.N), format='csc')

# @cached_var('nsi_degree')
def nsi_degree(self, key=None, typical_weight=None):
"""
For each node, return its uncorrected or corrected n.s.i. degree.
If a link attribute key is specified, return the associated nsi
strength
If a link attribute key is specified, return the associated n.s.i.
strength.
**Examples:**
Expand All @@ -1811,6 +1812,7 @@ def nsi_degree(self, key=None, typical_weight=None):
array([4, 3, 2, 2, 3, 2, 2])
:arg str key: link attribute key (optional)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand All @@ -1834,10 +1836,10 @@ def nsi_degree(self, key=None, typical_weight=None):
# @cached_var('nsi_indegree')
def nsi_indegree(self, key=None, typical_weight=None):
"""
For each node, return its n.s.i. indegree
For each node, return its n.s.i. indegree.
If a link attribute key is specified, return the associated nsi in
strength
If a link attribute key is specified, return the associated n.s.i.
in-strength.
**Examples:**
Expand Down Expand Up @@ -1866,8 +1868,7 @@ def nsi_indegree(self, key=None, typical_weight=None):
if key is None:
res = self.node_weights * self.sp_Aplus()
else:
w = self.link_attribute(key)
res = (self.node_weights @ w).squeeze()
res = (self.node_weights @ self.link_attribute(key)).squeeze()
if typical_weight is None:
return res
else:
Expand All @@ -1876,10 +1877,10 @@ def nsi_indegree(self, key=None, typical_weight=None):
# @cached_var('nsi_outdegree')
def nsi_outdegree(self, key=None, typical_weight=None):
"""
For each node, return its n.s.i.outdegree
For each node, return its n.s.i. outdegree.
If a link attribute key is specified, return the associated nsi out
strength
If a link attribute key is specified, return the associated n.s.i.
out-strength.
**Examples:**
Expand Down Expand Up @@ -1908,20 +1909,19 @@ def nsi_outdegree(self, key=None, typical_weight=None):
if key is None:
res = self.sp_Aplus() * self.node_weights
else:
w = self.link_attribute(key)
res = (w @ self.node_weights.transpose()).transpose().squeeze()
res = (self.link_attribute(key) @ self.node_weights).squeeze()
if typical_weight is None:
return res
else:
return res/typical_weight - 1.0

# @cached_var('nsi_outdegree')
# @cached_var('nsi_bildegree')
def nsi_bildegree(self, key=None, typical_weight=None):
"""
For each node, return its n.s.i.bilateraldegree
For each node, return its n.s.i. bilateral degree.
If a link attribute key is specified, return the associated
nsi bilateral strength
If a link attribute key is specified, return the associated n.s.i.
bilateral strength.
:arg str key: link attribute key [optional]
:type typical_weight: float > 0
Expand All @@ -1932,8 +1932,8 @@ def nsi_bildegree(self, key=None, typical_weight=None):
:rtype: array([float])
"""
assert key is None, "nsi_bildegree is not implemented with key yet"
res = (self.sp_Aplus()
* sp.diags(self.node_weights) * self.sp_Aplus()).diagonal()
Ap = self.sp_Aplus()
res = (Ap * sp.diags(self.node_weights) * Ap).diagonal()
if typical_weight is None:
return res
else:
Expand Down Expand Up @@ -2257,6 +2257,7 @@ def _motif_clustering_helper(self, t_func, T, key=None, nsi=False,
:arg 1d numpy array [node]: denominator made out of (in/out/bil)degrees
:arg str key: link attribute key (optional)
:arg bool nsi: flag for nsi calculation (default: False)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand Down Expand Up @@ -2411,6 +2412,7 @@ def nsi_local_cyclemotif_clustering(self, key=None, typical_weight=None):
array([ 0.3333, 0.125 , 0. , 0. , 0.5 , 0. , 0.125 ])
:arg str key: link attribute key (optional)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand Down Expand Up @@ -2458,6 +2460,7 @@ def nsi_local_midmotif_clustering(self, key=None, typical_weight=None):
array([ 0. , 0. , 0. , 1. , 0.8, 0. , 0.8])
:arg str key: link attribute key (optional)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand Down Expand Up @@ -2506,6 +2509,7 @@ def nsi_local_inmotif_clustering(self, key=None, typical_weight=None):
:arg str key: link attribute key (optional)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand Down Expand Up @@ -2552,6 +2556,7 @@ def nsi_local_outmotif_clustering(self, key=None, typical_weight=None):
array([ 0.5 , 0.5 , 0. , 0. , 0.3333, 1. , 0.5 ])
:arg str key: link attribute key (optional)
:type typical_weight: float > 0
:arg float typical_weight: Optional typical node weight to be used for
correction. If None, the uncorrected measure is
returned. (Default: None)
Expand Down Expand Up @@ -3314,8 +3319,7 @@ def nsi_betweenness(self, parallelize: bool = False, **kwargs):
Calculating node betweenness...
array([ 8.5, 1.5, 0. , 1.5, 4.5, 0. , 0. ])
:arg bool parallelize: Toggle parallelized computation
:arg bool parallelize: Toggle multiprocessing
:rtype: 1d numpy array [node] of floats
"""
if self.silence_level <= 1:
Expand Down
22 changes: 9 additions & 13 deletions tests/test_core/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ def test_nsi_degree():
])
def test_nsi_indegree(tw, exp, exp_split):
net = Network.SmallDirectedTestNetwork()

assert np.allclose(net.nsi_indegree(typical_weight=tw), exp)
assert np.allclose(
net.splitted_copy().nsi_indegree(typical_weight=tw), exp_split)
Expand All @@ -386,10 +385,9 @@ def test_nsi_indegree(tw, exp, exp_split):
])
def test_nsi_outdegree(tw, exp, exp_split):
net = Network.SmallDirectedTestNetwork()

assert np.allclose(net.nsi_outdegree(typical_weight=tw), exp)
assert np.allclose(
net.splitted_copy().nsi_outdegree(typical_weight=tw), exp_split)
assert np.allclose(net.splitted_copy().nsi_outdegree(typical_weight=tw),
exp_split)


@pytest.mark.parametrize("tw, exp, exp_split", [
Expand All @@ -402,10 +400,9 @@ def test_nsi_outdegree(tw, exp, exp_split):
])
def test_nsi_bildegree(tw, exp, exp_split):
net = Network.SmallDirectedTestNetwork()

assert np.allclose(net.nsi_bildegree(typical_weight=tw), exp)
assert np.allclose(
net.splitted_copy().nsi_bildegree(typical_weight=tw), exp_split)
assert np.allclose(net.splitted_copy().nsi_bildegree(typical_weight=tw),
exp_split)


def test_degree_distribution():
Expand Down Expand Up @@ -536,13 +533,12 @@ def test_local_outmotif_clustering():
])
def test_nsi_local_cyclemotif_clustering(tw, exp, exp_split):
net = Network.SmallDirectedTestNetwork()

assert np.allclose(
net.nsi_local_cyclemotif_clustering(typical_weight=tw), exp)

assert np.allclose(net.nsi_local_cyclemotif_clustering(typical_weight=tw),
exp)
assert np.allclose(
net.splitted_copy(node=1)
.nsi_local_cyclemotif_clustering(typical_weight=tw), exp_split)
net.splitted_copy(node=1).nsi_local_cyclemotif_clustering(
typical_weight=tw),
exp_split)


def test_nsi_local_midmotif_clustering():
Expand Down

0 comments on commit 33bf65a

Please sign in to comment.