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.

Files changed (114) hide show
  1. {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/AUTHORS.rst +3 -0
  2. {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/METADATA +19 -3
  3. {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/RECORD +112 -105
  4. {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/WHEEL +1 -1
  5. sknetwork/__init__.py +1 -1
  6. sknetwork/classification/base.py +1 -1
  7. sknetwork/classification/base_rank.py +3 -3
  8. sknetwork/classification/diffusion.py +21 -13
  9. sknetwork/classification/knn.py +19 -13
  10. sknetwork/classification/metrics.py +1 -1
  11. sknetwork/classification/pagerank.py +12 -8
  12. sknetwork/classification/propagation.py +22 -15
  13. sknetwork/classification/tests/test_diffusion.py +10 -0
  14. sknetwork/classification/vote.cp39-win_amd64.pyd +0 -0
  15. sknetwork/classification/vote.cpp +14549 -8668
  16. sknetwork/clustering/__init__.py +3 -1
  17. sknetwork/clustering/base.py +1 -1
  18. sknetwork/clustering/kcenters.py +253 -0
  19. sknetwork/clustering/leiden.py +241 -0
  20. sknetwork/clustering/leiden_core.cp39-win_amd64.pyd +0 -0
  21. sknetwork/clustering/leiden_core.cpp +31564 -0
  22. sknetwork/clustering/leiden_core.pyx +124 -0
  23. sknetwork/clustering/louvain.py +118 -83
  24. sknetwork/clustering/louvain_core.cp39-win_amd64.pyd +0 -0
  25. sknetwork/clustering/louvain_core.cpp +21876 -16332
  26. sknetwork/clustering/louvain_core.pyx +86 -94
  27. sknetwork/clustering/postprocess.py +2 -2
  28. sknetwork/clustering/propagation_clustering.py +4 -4
  29. sknetwork/clustering/tests/test_API.py +7 -3
  30. sknetwork/clustering/tests/test_kcenters.py +92 -0
  31. sknetwork/clustering/tests/test_leiden.py +34 -0
  32. sknetwork/clustering/tests/test_louvain.py +2 -3
  33. sknetwork/data/load.py +2 -4
  34. sknetwork/data/parse.py +41 -20
  35. sknetwork/data/tests/test_parse.py +9 -12
  36. sknetwork/embedding/__init__.py +0 -1
  37. sknetwork/embedding/base.py +20 -19
  38. sknetwork/embedding/force_atlas.py +3 -2
  39. sknetwork/embedding/louvain_embedding.py +1 -1
  40. sknetwork/embedding/random_projection.py +5 -3
  41. sknetwork/embedding/spectral.py +0 -73
  42. sknetwork/embedding/tests/test_API.py +4 -28
  43. sknetwork/embedding/tests/test_louvain_embedding.py +4 -9
  44. sknetwork/embedding/tests/test_spectral.py +2 -5
  45. sknetwork/embedding/tests/test_svd.py +1 -1
  46. sknetwork/gnn/base_layer.py +3 -3
  47. sknetwork/gnn/gnn_classifier.py +40 -86
  48. sknetwork/gnn/layer.py +1 -1
  49. sknetwork/gnn/loss.py +1 -1
  50. sknetwork/gnn/optimizer.py +4 -3
  51. sknetwork/gnn/tests/test_base_layer.py +4 -4
  52. sknetwork/gnn/tests/test_gnn_classifier.py +12 -39
  53. sknetwork/gnn/utils.py +8 -8
  54. sknetwork/hierarchy/base.py +27 -0
  55. sknetwork/hierarchy/louvain_hierarchy.py +45 -41
  56. sknetwork/hierarchy/paris.cp39-win_amd64.pyd +0 -0
  57. sknetwork/hierarchy/paris.cpp +27521 -20771
  58. sknetwork/hierarchy/paris.pyx +7 -7
  59. sknetwork/hierarchy/postprocess.py +16 -16
  60. sknetwork/hierarchy/tests/test_algos.py +5 -0
  61. sknetwork/linalg/__init__.py +1 -1
  62. sknetwork/linalg/diteration.cp39-win_amd64.pyd +0 -0
  63. sknetwork/linalg/diteration.cpp +13916 -8050
  64. sknetwork/linalg/{normalization.py → normalizer.py} +17 -14
  65. sknetwork/linalg/operators.py +1 -1
  66. sknetwork/linalg/ppr_solver.py +1 -1
  67. sknetwork/linalg/push.cp39-win_amd64.pyd +0 -0
  68. sknetwork/linalg/push.cpp +23187 -16973
  69. sknetwork/linalg/tests/test_normalization.py +3 -7
  70. sknetwork/linalg/tests/test_operators.py +2 -6
  71. sknetwork/linalg/tests/test_ppr.py +1 -1
  72. sknetwork/linkpred/base.py +12 -1
  73. sknetwork/linkpred/nn.py +6 -6
  74. sknetwork/path/distances.py +11 -4
  75. sknetwork/path/shortest_path.py +1 -1
  76. sknetwork/path/tests/test_distances.py +7 -0
  77. sknetwork/path/tests/test_search.py +2 -2
  78. sknetwork/ranking/base.py +11 -6
  79. sknetwork/ranking/betweenness.cp39-win_amd64.pyd +0 -0
  80. sknetwork/ranking/betweenness.cpp +5256 -2190
  81. sknetwork/ranking/pagerank.py +13 -12
  82. sknetwork/ranking/tests/test_API.py +0 -2
  83. sknetwork/ranking/tests/test_betweenness.py +1 -1
  84. sknetwork/ranking/tests/test_pagerank.py +11 -5
  85. sknetwork/regression/base.py +18 -1
  86. sknetwork/regression/diffusion.py +24 -10
  87. sknetwork/regression/tests/test_diffusion.py +8 -0
  88. sknetwork/topology/__init__.py +3 -1
  89. sknetwork/topology/cliques.cp39-win_amd64.pyd +0 -0
  90. sknetwork/topology/cliques.cpp +23528 -16848
  91. sknetwork/topology/core.cp39-win_amd64.pyd +0 -0
  92. sknetwork/topology/core.cpp +22849 -16581
  93. sknetwork/topology/cycles.py +243 -0
  94. sknetwork/topology/minheap.cp39-win_amd64.pyd +0 -0
  95. sknetwork/topology/minheap.cpp +19495 -13469
  96. sknetwork/topology/structure.py +2 -42
  97. sknetwork/topology/tests/test_cycles.py +65 -0
  98. sknetwork/topology/tests/test_structure.py +2 -16
  99. sknetwork/topology/triangles.cp39-win_amd64.pyd +0 -0
  100. sknetwork/topology/triangles.cpp +5283 -1397
  101. sknetwork/topology/triangles.pyx +7 -4
  102. sknetwork/topology/weisfeiler_lehman_core.cp39-win_amd64.pyd +0 -0
  103. sknetwork/topology/weisfeiler_lehman_core.cpp +14781 -8915
  104. sknetwork/utils/format.py +1 -1
  105. sknetwork/utils/membership.py +2 -2
  106. sknetwork/visualization/__init__.py +2 -2
  107. sknetwork/visualization/dendrograms.py +55 -7
  108. sknetwork/visualization/graphs.py +261 -44
  109. sknetwork/visualization/tests/test_dendrograms.py +9 -9
  110. sknetwork/visualization/tests/test_graphs.py +63 -57
  111. sknetwork/embedding/louvain_hierarchy.py +0 -142
  112. sknetwork/embedding/tests/test_louvain_hierarchy.py +0 -19
  113. {scikit_network-0.31.0.dist-info → scikit_network-0.32.1.dist-info}/LICENSE +0 -0
  114. {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 on April 2020
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, CoNeighbor
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(NotImplementedError):
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 on Apr 2020
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, normalize
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
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
- """Tests for Louvain"""
3
+ """Tests for d-iteration"""
4
4
  import unittest
5
5
 
6
6
  import numpy as np
@@ -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 fit_predict(self, *args, **kwargs) -> np.ndarray:
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.normalization import normalize
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
@@ -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, force_bipartite: bool = False) \
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 in returned).
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(input_matrix, force_bipartite=force_bipartite, allow_empty=True)
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 = input_matrix.shape
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)
@@ -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 to the source node (or the set of source nodes).
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_ = np.array([1, 3, 4, 2, 5])
40
- self.assertTrue(all(search == search_))
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 fit_predict(self, *args, **kwargs) -> np.ndarray:
30
- """Fit algorithm to data and return the scores. Same parameters as the ``fit`` method.
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
- self.fit(*args, **kwargs)
42
+ if columns:
43
+ return self.scores_col_
38
44
  return self.scores_
39
45
 
40
- def fit_transform(self, *args, **kwargs) -> np.ndarray:
41
- """Fit algorithm to data and return the scores. Alias for ``fit_predict``.
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
  -------