scikit-network 0.31.0__cp39-cp39-win_amd64.whl → 0.32.1__cp39-cp39-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scikit-network might be problematic. Click here for more details.
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/AUTHORS.rst +3 -0
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/METADATA +19 -3
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/RECORD +112 -105
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/WHEEL +1 -1
- sknetwork/__init__.py +1 -1
- sknetwork/classification/base.py +1 -1
- sknetwork/classification/base_rank.py +3 -3
- sknetwork/classification/diffusion.py +21 -13
- sknetwork/classification/knn.py +19 -13
- sknetwork/classification/metrics.py +1 -1
- sknetwork/classification/pagerank.py +12 -8
- sknetwork/classification/propagation.py +22 -15
- sknetwork/classification/tests/test_diffusion.py +10 -0
- sknetwork/classification/vote.cp39-win_amd64.pyd +0 -0
- sknetwork/classification/vote.cpp +14549 -8668
- sknetwork/clustering/__init__.py +3 -1
- sknetwork/clustering/base.py +1 -1
- sknetwork/clustering/kcenters.py +253 -0
- sknetwork/clustering/leiden.py +241 -0
- sknetwork/clustering/leiden_core.cp39-win_amd64.pyd +0 -0
- sknetwork/clustering/leiden_core.cpp +31564 -0
- sknetwork/clustering/leiden_core.pyx +124 -0
- sknetwork/clustering/louvain.py +118 -83
- sknetwork/clustering/louvain_core.cp39-win_amd64.pyd +0 -0
- sknetwork/clustering/louvain_core.cpp +21876 -16332
- sknetwork/clustering/louvain_core.pyx +86 -94
- sknetwork/clustering/postprocess.py +2 -2
- sknetwork/clustering/propagation_clustering.py +4 -4
- sknetwork/clustering/tests/test_API.py +7 -3
- sknetwork/clustering/tests/test_kcenters.py +92 -0
- sknetwork/clustering/tests/test_leiden.py +34 -0
- sknetwork/clustering/tests/test_louvain.py +2 -3
- sknetwork/data/load.py +2 -4
- sknetwork/data/parse.py +41 -20
- sknetwork/data/tests/test_parse.py +9 -12
- sknetwork/embedding/__init__.py +0 -1
- sknetwork/embedding/base.py +20 -19
- sknetwork/embedding/force_atlas.py +3 -2
- sknetwork/embedding/louvain_embedding.py +1 -1
- sknetwork/embedding/random_projection.py +5 -3
- sknetwork/embedding/spectral.py +0 -73
- sknetwork/embedding/tests/test_API.py +4 -28
- sknetwork/embedding/tests/test_louvain_embedding.py +4 -9
- sknetwork/embedding/tests/test_spectral.py +2 -5
- sknetwork/embedding/tests/test_svd.py +1 -1
- sknetwork/gnn/base_layer.py +3 -3
- sknetwork/gnn/gnn_classifier.py +40 -86
- sknetwork/gnn/layer.py +1 -1
- sknetwork/gnn/loss.py +1 -1
- sknetwork/gnn/optimizer.py +4 -3
- sknetwork/gnn/tests/test_base_layer.py +4 -4
- sknetwork/gnn/tests/test_gnn_classifier.py +12 -39
- sknetwork/gnn/utils.py +8 -8
- sknetwork/hierarchy/base.py +27 -0
- sknetwork/hierarchy/louvain_hierarchy.py +45 -41
- sknetwork/hierarchy/paris.cp39-win_amd64.pyd +0 -0
- sknetwork/hierarchy/paris.cpp +27521 -20771
- sknetwork/hierarchy/paris.pyx +7 -7
- sknetwork/hierarchy/postprocess.py +16 -16
- sknetwork/hierarchy/tests/test_algos.py +5 -0
- sknetwork/linalg/__init__.py +1 -1
- sknetwork/linalg/diteration.cp39-win_amd64.pyd +0 -0
- sknetwork/linalg/diteration.cpp +13916 -8050
- sknetwork/linalg/{normalization.py → normalizer.py} +17 -14
- sknetwork/linalg/operators.py +1 -1
- sknetwork/linalg/ppr_solver.py +1 -1
- sknetwork/linalg/push.cp39-win_amd64.pyd +0 -0
- sknetwork/linalg/push.cpp +23187 -16973
- sknetwork/linalg/tests/test_normalization.py +3 -7
- sknetwork/linalg/tests/test_operators.py +2 -6
- sknetwork/linalg/tests/test_ppr.py +1 -1
- sknetwork/linkpred/base.py +12 -1
- sknetwork/linkpred/nn.py +6 -6
- sknetwork/path/distances.py +11 -4
- sknetwork/path/shortest_path.py +1 -1
- sknetwork/path/tests/test_distances.py +7 -0
- sknetwork/path/tests/test_search.py +2 -2
- sknetwork/ranking/base.py +11 -6
- sknetwork/ranking/betweenness.cp39-win_amd64.pyd +0 -0
- sknetwork/ranking/betweenness.cpp +5256 -2190
- sknetwork/ranking/pagerank.py +13 -12
- sknetwork/ranking/tests/test_API.py +0 -2
- sknetwork/ranking/tests/test_betweenness.py +1 -1
- sknetwork/ranking/tests/test_pagerank.py +11 -5
- sknetwork/regression/base.py +18 -1
- sknetwork/regression/diffusion.py +24 -10
- sknetwork/regression/tests/test_diffusion.py +8 -0
- sknetwork/topology/__init__.py +3 -1
- sknetwork/topology/cliques.cp39-win_amd64.pyd +0 -0
- sknetwork/topology/cliques.cpp +23528 -16848
- sknetwork/topology/core.cp39-win_amd64.pyd +0 -0
- sknetwork/topology/core.cpp +22849 -16581
- sknetwork/topology/cycles.py +243 -0
- sknetwork/topology/minheap.cp39-win_amd64.pyd +0 -0
- sknetwork/topology/minheap.cpp +19495 -13469
- sknetwork/topology/structure.py +2 -42
- sknetwork/topology/tests/test_cycles.py +65 -0
- sknetwork/topology/tests/test_structure.py +2 -16
- sknetwork/topology/triangles.cp39-win_amd64.pyd +0 -0
- sknetwork/topology/triangles.cpp +5283 -1397
- sknetwork/topology/triangles.pyx +7 -4
- sknetwork/topology/weisfeiler_lehman_core.cp39-win_amd64.pyd +0 -0
- sknetwork/topology/weisfeiler_lehman_core.cpp +14781 -8915
- sknetwork/utils/format.py +1 -1
- sknetwork/utils/membership.py +2 -2
- sknetwork/visualization/__init__.py +2 -2
- sknetwork/visualization/dendrograms.py +55 -7
- sknetwork/visualization/graphs.py +261 -44
- sknetwork/visualization/tests/test_dendrograms.py +9 -9
- sknetwork/visualization/tests/test_graphs.py +63 -57
- sknetwork/embedding/louvain_hierarchy.py +0 -142
- sknetwork/embedding/tests/test_louvain_hierarchy.py +0 -19
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/LICENSE +0 -0
- {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Created
|
|
4
|
+
Created in April 2020
|
|
5
5
|
@author: Nathan de Lara <nathan.delara@polytechnique.org>
|
|
6
6
|
"""
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ import unittest
|
|
|
10
10
|
import numpy as np
|
|
11
11
|
from scipy import sparse
|
|
12
12
|
|
|
13
|
-
from sknetwork.linalg import normalize
|
|
13
|
+
from sknetwork.linalg import normalize
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class TestNormalization(unittest.TestCase):
|
|
@@ -19,12 +19,10 @@ class TestNormalization(unittest.TestCase):
|
|
|
19
19
|
n = 5
|
|
20
20
|
mat1 = normalize(np.eye(n))
|
|
21
21
|
mat2 = normalize(sparse.eye(n))
|
|
22
|
-
mat3 = normalize(CoNeighbor(mat2))
|
|
23
22
|
|
|
24
23
|
x = np.random.randn(n)
|
|
25
24
|
self.assertAlmostEqual(np.linalg.norm(mat1.dot(x) - x), 0)
|
|
26
25
|
self.assertAlmostEqual(np.linalg.norm(mat2.dot(x) - x), 0)
|
|
27
|
-
self.assertAlmostEqual(np.linalg.norm(mat3.dot(x) - x), 0)
|
|
28
26
|
|
|
29
27
|
mat1 = np.random.rand(n**2).reshape((n, n))
|
|
30
28
|
mat2 = sparse.csr_matrix(mat1)
|
|
@@ -32,7 +30,5 @@ class TestNormalization(unittest.TestCase):
|
|
|
32
30
|
mat2 = normalize(mat2, p=2)
|
|
33
31
|
self.assertAlmostEqual(np.linalg.norm(mat1.dot(x) - mat2.dot(x)), 0)
|
|
34
32
|
|
|
35
|
-
with self.assertRaises(
|
|
36
|
-
normalize(mat3, p=2)
|
|
37
|
-
with self.assertRaises(NotImplementedError):
|
|
33
|
+
with self.assertRaises(ValueError):
|
|
38
34
|
normalize(mat1, p=3)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Created
|
|
4
|
+
Created in April 2020
|
|
5
5
|
@author: Thomas Bonald <bonald@enst.fr>
|
|
6
6
|
@author: Nathan de Lara <nathan.delara@polytechnique.org>
|
|
7
7
|
"""
|
|
8
8
|
import unittest
|
|
9
9
|
|
|
10
10
|
from sknetwork.data.test_graphs import *
|
|
11
|
-
from sknetwork.linalg import Laplacian, Normalizer, CoNeighbor
|
|
11
|
+
from sknetwork.linalg import Laplacian, Normalizer, CoNeighbor
|
|
12
12
|
from sknetwork.linalg.basics import safe_sparse_dot
|
|
13
13
|
|
|
14
14
|
|
|
@@ -53,10 +53,6 @@ class TestOperators(unittest.TestCase):
|
|
|
53
53
|
def test_coneighbors(self):
|
|
54
54
|
biadjacency = test_bigraph()
|
|
55
55
|
operator = CoNeighbor(biadjacency)
|
|
56
|
-
transition = normalize(operator)
|
|
57
|
-
x = transition.dot(np.ones(transition.shape[1]))
|
|
58
|
-
|
|
59
|
-
self.assertAlmostEqual(np.linalg.norm(x - np.ones(operator.shape[0])), 0)
|
|
60
56
|
operator.astype('float')
|
|
61
57
|
operator.right_sparse_dot(sparse.eye(operator.shape[1], format='csr'))
|
|
62
58
|
|
sknetwork/linkpred/base.py
CHANGED
|
@@ -7,6 +7,7 @@ Created in March 2022
|
|
|
7
7
|
from abc import ABC
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
|
+
from scipy import sparse
|
|
10
11
|
|
|
11
12
|
from sknetwork.base import Algorithm
|
|
12
13
|
|
|
@@ -23,7 +24,17 @@ class BaseLinker(Algorithm, ABC):
|
|
|
23
24
|
def __init__(self):
|
|
24
25
|
self.links_ = None
|
|
25
26
|
|
|
26
|
-
def
|
|
27
|
+
def predict(self) -> sparse.csr_matrix:
|
|
28
|
+
"""Return the predicted links.
|
|
29
|
+
|
|
30
|
+
Returns
|
|
31
|
+
-------
|
|
32
|
+
links_ : sparse.csr_matrix
|
|
33
|
+
Link matrix.
|
|
34
|
+
"""
|
|
35
|
+
return self.links_
|
|
36
|
+
|
|
37
|
+
def fit_predict(self, *args, **kwargs) -> sparse.csr_matrix:
|
|
27
38
|
"""Fit algorithm to data and return the links. Same parameters as the ``fit`` method.
|
|
28
39
|
|
|
29
40
|
Returns
|
sknetwork/linkpred/nn.py
CHANGED
|
@@ -11,7 +11,7 @@ from scipy import sparse
|
|
|
11
11
|
|
|
12
12
|
from sknetwork.linkpred.base import BaseLinker
|
|
13
13
|
from sknetwork.embedding.base import BaseEmbedding
|
|
14
|
-
from sknetwork.linalg.
|
|
14
|
+
from sknetwork.linalg.normalizer import normalize
|
|
15
15
|
from sknetwork.utils.check import check_n_neighbors
|
|
16
16
|
from sknetwork.utils.format import get_adjacency
|
|
17
17
|
|
|
@@ -23,11 +23,11 @@ class NNLinker(BaseLinker):
|
|
|
23
23
|
|
|
24
24
|
Parameters
|
|
25
25
|
----------
|
|
26
|
-
n_neighbors :
|
|
26
|
+
n_neighbors : int
|
|
27
27
|
Number of nearest neighbors. If ``None``, all nodes are considered.
|
|
28
|
-
threshold :
|
|
28
|
+
threshold : float
|
|
29
29
|
Threshold on cosine similarity. Only links above this threshold are kept.
|
|
30
|
-
embedding_method :
|
|
30
|
+
embedding_method : :class:`BaseEmbedding`
|
|
31
31
|
Embedding method used to represent nodes in vector space.
|
|
32
32
|
If ``None`` (default), use identity.
|
|
33
33
|
|
|
@@ -95,9 +95,9 @@ class NNLinker(BaseLinker):
|
|
|
95
95
|
|
|
96
96
|
Parameters
|
|
97
97
|
----------
|
|
98
|
-
input_matrix :
|
|
98
|
+
input_matrix : sparse.csr_matrix, np.ndarray
|
|
99
99
|
Adjacency matrix or biadjacency matrix of the graph.
|
|
100
|
-
index :
|
|
100
|
+
index : np.ndarray
|
|
101
101
|
Index of source nodes to consider. If ``None``, the links are predicted for all nodes.
|
|
102
102
|
|
|
103
103
|
Returns
|
sknetwork/path/distances.py
CHANGED
|
@@ -14,7 +14,8 @@ from sknetwork.utils.format import get_adjacency
|
|
|
14
14
|
|
|
15
15
|
def get_distances(input_matrix: sparse.csr_matrix, source: Optional[Union[int, Iterable]] = None,
|
|
16
16
|
source_row: Optional[Union[int, Iterable]] = None,
|
|
17
|
-
source_col: Optional[Union[int, Iterable]] = None,
|
|
17
|
+
source_col: Optional[Union[int, Iterable]] = None, transpose: bool = False,
|
|
18
|
+
force_bipartite: bool = False) \
|
|
18
19
|
-> Union[np.ndarray, Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray]]:
|
|
19
20
|
"""Get the distances from a source (or a set of sources) in number of hops.
|
|
20
21
|
|
|
@@ -24,10 +25,12 @@ def get_distances(input_matrix: sparse.csr_matrix, source: Optional[Union[int, I
|
|
|
24
25
|
Adjacency matrix or biadjacency matrix of the graph.
|
|
25
26
|
source :
|
|
26
27
|
If an integer, index of the source node.
|
|
27
|
-
If a list, indices of source nodes (the shortest distances to one of these nodes
|
|
28
|
+
If a list or array, indices of source nodes (the shortest distances to one of these nodes is returned).
|
|
28
29
|
source_row, source_col :
|
|
29
30
|
For bipartite graphs, index of source nodes on rows and columns.
|
|
30
31
|
The parameter source_row is an alias for source (at least one of them must be ``None``).
|
|
32
|
+
transpose :
|
|
33
|
+
If ``True``, transpose the input matrix.
|
|
31
34
|
force_bipartite :
|
|
32
35
|
If ``True``, consider the input matrix as the biadjacency matrix of a bipartite graph.
|
|
33
36
|
Set to ``True`` is the parameters source_row or source_col re specified.
|
|
@@ -47,11 +50,15 @@ def get_distances(input_matrix: sparse.csr_matrix, source: Optional[Union[int, I
|
|
|
47
50
|
>>> get_distances(adjacency, source=[0, 2])
|
|
48
51
|
array([0, 1, 0])
|
|
49
52
|
"""
|
|
53
|
+
if transpose:
|
|
54
|
+
matrix = sparse.csr_matrix(input_matrix.T)
|
|
55
|
+
else:
|
|
56
|
+
matrix = input_matrix
|
|
50
57
|
if source_row is not None or source_col is not None:
|
|
51
58
|
force_bipartite = True
|
|
52
|
-
adjacency, bipartite = get_adjacency(
|
|
59
|
+
adjacency, bipartite = get_adjacency(matrix, force_bipartite=force_bipartite, allow_empty=True)
|
|
53
60
|
adjacency_transpose = adjacency.astype(bool).T.tocsr()
|
|
54
|
-
n_row, n_col =
|
|
61
|
+
n_row, n_col = matrix.shape
|
|
55
62
|
n_nodes = adjacency.shape[0]
|
|
56
63
|
|
|
57
64
|
mask = np.zeros(n_nodes, dtype=bool)
|
sknetwork/path/shortest_path.py
CHANGED
|
@@ -37,7 +37,7 @@ def get_shortest_path(input_matrix: sparse.csr_matrix, source: Optional[Union[in
|
|
|
37
37
|
Returns
|
|
38
38
|
-------
|
|
39
39
|
path : sparse.csr_matrix
|
|
40
|
-
Adjacency matrix of the graph of the shortest paths
|
|
40
|
+
Adjacency matrix of the graph of the shortest paths from the source node (or the set of source nodes).
|
|
41
41
|
If the input graph is a bipartite graph, the shape of the matrix is (n_row + n_col, n_row + n_col) with the new
|
|
42
42
|
index corresponding to the rows then the columns of the original graph.
|
|
43
43
|
|
|
@@ -21,6 +21,8 @@ class TestDistances(unittest.TestCase):
|
|
|
21
21
|
distances = get_distances(adjacency, 0)
|
|
22
22
|
distances_ = np.array([0, 1, 3, 2, 2, 3, 2, 3, 4, 4])
|
|
23
23
|
self.assertTrue(all(distances == distances_))
|
|
24
|
+
distances = get_distances(adjacency, 0, transpose=True)
|
|
25
|
+
self.assertTrue(all(distances == distances_))
|
|
24
26
|
distances = get_distances(adjacency, [0, 5])
|
|
25
27
|
distances_ = np.array([0, 1, 3, 2, 1, 0, 1, 2, 4, 3])
|
|
26
28
|
self.assertTrue(all(distances == distances_))
|
|
@@ -36,6 +38,11 @@ class TestDistances(unittest.TestCase):
|
|
|
36
38
|
distances = get_distances(adjacency, [0])
|
|
37
39
|
distances_ = np.array([0, 1, 3, 2, 2, 3, -1, -1, -1, -1])
|
|
38
40
|
self.assertTrue(all(distances == distances_))
|
|
41
|
+
distances = get_distances(adjacency, [0], transpose=True)
|
|
42
|
+
self.assertTrue(sum(distances < 0) == 9)
|
|
43
|
+
distances = get_distances(adjacency, [0, 5], transpose=True)
|
|
44
|
+
distances_ = np.array([0, 2, -1, -1, 1, 0, 1, -1, -1, -1])
|
|
45
|
+
self.assertTrue(all(distances == distances_))
|
|
39
46
|
|
|
40
47
|
biadjacency = test_bigraph()
|
|
41
48
|
distances_row, distances_col = get_distances(biadjacency, [0])
|
|
@@ -36,5 +36,5 @@ class TestSearch(unittest.TestCase):
|
|
|
36
36
|
|
|
37
37
|
adjacency = test_digraph()
|
|
38
38
|
search = breadth_first_search(adjacency, 1)
|
|
39
|
-
search_ =
|
|
40
|
-
self.assertTrue(
|
|
39
|
+
search_ = {1, 3, 4, 2, 5}
|
|
40
|
+
self.assertTrue(set(list(search)) == search_)
|
sknetwork/ranking/base.py
CHANGED
|
@@ -26,20 +26,25 @@ class BaseRanking(Algorithm, ABC):
|
|
|
26
26
|
def __init__(self):
|
|
27
27
|
self.scores_ = None
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
"""
|
|
29
|
+
def predict(self, columns: bool = False) -> np.ndarray:
|
|
30
|
+
"""Return the scores predicted by the algorithm.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
columns : bool
|
|
35
|
+
If ``True``, return the prediction for columns.
|
|
31
36
|
|
|
32
37
|
Returns
|
|
33
38
|
-------
|
|
34
39
|
scores : np.ndarray
|
|
35
40
|
Scores.
|
|
36
41
|
"""
|
|
37
|
-
|
|
42
|
+
if columns:
|
|
43
|
+
return self.scores_col_
|
|
38
44
|
return self.scores_
|
|
39
45
|
|
|
40
|
-
def
|
|
41
|
-
"""Fit algorithm to data and return the scores.
|
|
42
|
-
Same parameters as the ``fit`` method.
|
|
46
|
+
def fit_predict(self, *args, **kwargs) -> np.ndarray:
|
|
47
|
+
"""Fit algorithm to data and return the scores. Same parameters as the ``fit`` method.
|
|
43
48
|
|
|
44
49
|
Returns
|
|
45
50
|
-------
|
|
Binary file
|