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
sknetwork/utils/format.py
CHANGED
|
@@ -30,7 +30,7 @@ def directed2undirected(adjacency: Union[sparse.csr_matrix, SparseLR],
|
|
|
30
30
|
|
|
31
31
|
or
|
|
32
32
|
|
|
33
|
-
:math:`\\max(A,A^T)`
|
|
33
|
+
:math:`\\max(A,A^T) > 0` (binary)
|
|
34
34
|
|
|
35
35
|
If the initial adjacency matrix :math:`A` is binary, bidirectional edges have weight 2
|
|
36
36
|
(first method, default) or 1 (second method).
|
sknetwork/utils/membership.py
CHANGED
|
@@ -20,9 +20,9 @@ def get_membership(labels: np.ndarray, dtype=bool, n_labels: Optional[int] = Non
|
|
|
20
20
|
Parameters
|
|
21
21
|
----------
|
|
22
22
|
labels :
|
|
23
|
-
Label of each node.
|
|
23
|
+
Label of each node (integers).
|
|
24
24
|
dtype :
|
|
25
|
-
Type of the
|
|
25
|
+
Type of the output. Boolean by default.
|
|
26
26
|
n_labels : int
|
|
27
27
|
Number of labels.
|
|
28
28
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"""Visualization module."""
|
|
2
2
|
|
|
3
|
-
from sknetwork.visualization.dendrograms import svg_dendrogram
|
|
4
|
-
from sknetwork.visualization.graphs import svg_graph, svg_bigraph
|
|
3
|
+
from sknetwork.visualization.dendrograms import visualize_dendrogram, svg_dendrogram
|
|
4
|
+
from sknetwork.visualization.graphs import visualize_graph, visualize_bigraph, svg_graph, svg_bigraph
|
|
@@ -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: Thomas Bonald <bonald@enst.fr>
|
|
6
6
|
"""
|
|
7
7
|
from typing import Iterable, Optional
|
|
@@ -158,12 +158,12 @@ def svg_dendrogram_left(dendrogram, names, width, height, margin, margin_text, s
|
|
|
158
158
|
return svg
|
|
159
159
|
|
|
160
160
|
|
|
161
|
-
def
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"""Return
|
|
161
|
+
def visualize_dendrogram(dendrogram: np.ndarray, names: Optional[np.ndarray] = None, rotate: bool = False,
|
|
162
|
+
width: float = 400, height: float = 300, margin: float = 10, margin_text: float = 5,
|
|
163
|
+
scale: float = 1, line_width: float = 2, n_clusters: int = 2, color: str = 'black',
|
|
164
|
+
colors: Optional[Iterable] = None, font_size: int = 12, reorder: bool = False,
|
|
165
|
+
rotate_names: bool = True, filename: Optional[str] = None):
|
|
166
|
+
"""Return the image of a dendrogram in SVG format.
|
|
167
167
|
|
|
168
168
|
Parameters
|
|
169
169
|
----------
|
|
@@ -227,3 +227,51 @@ def svg_dendrogram(dendrogram: np.ndarray, names: Optional[np.ndarray] = None, r
|
|
|
227
227
|
f.write(svg)
|
|
228
228
|
|
|
229
229
|
return svg
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def svg_dendrogram(dendrogram: np.ndarray, names: Optional[np.ndarray] = None, rotate: bool = False, width: float = 400,
|
|
233
|
+
height: float = 300, margin: float = 10, margin_text: float = 5, scale: float = 1,
|
|
234
|
+
line_width: float = 2, n_clusters: int = 2, color: str = 'black', colors: Optional[Iterable] = None,
|
|
235
|
+
font_size: int = 12, reorder: bool = False, rotate_names: bool = True,
|
|
236
|
+
filename: Optional[str] = None):
|
|
237
|
+
"""Return the image of a dendrogram in SVG format.
|
|
238
|
+
|
|
239
|
+
Alias for visualize_dendrogram.
|
|
240
|
+
|
|
241
|
+
Parameters
|
|
242
|
+
----------
|
|
243
|
+
dendrogram :
|
|
244
|
+
Dendrogram to display.
|
|
245
|
+
names :
|
|
246
|
+
Names of leaves.
|
|
247
|
+
rotate :
|
|
248
|
+
If ``True``, rotate the tree so that the root is on the left.
|
|
249
|
+
width :
|
|
250
|
+
Width of the image (margins excluded).
|
|
251
|
+
height :
|
|
252
|
+
Height of the image (margins excluded).
|
|
253
|
+
margin :
|
|
254
|
+
Margin.
|
|
255
|
+
margin_text :
|
|
256
|
+
Margin between leaves and their names, if any.
|
|
257
|
+
scale :
|
|
258
|
+
Scaling factor.
|
|
259
|
+
line_width :
|
|
260
|
+
Line width.
|
|
261
|
+
n_clusters :
|
|
262
|
+
Number of coloured clusters to display.
|
|
263
|
+
color :
|
|
264
|
+
Default SVG color for the dendrogram.
|
|
265
|
+
colors :
|
|
266
|
+
SVG colors of the clusters of the dendrogram (optional).
|
|
267
|
+
font_size :
|
|
268
|
+
Font size.
|
|
269
|
+
reorder :
|
|
270
|
+
If ``True``, reorder leaves so that left subtree has more leaves than right subtree.
|
|
271
|
+
rotate_names :
|
|
272
|
+
If ``True``, rotate names of leaves (only valid if **rotate** is ``False``).
|
|
273
|
+
filename :
|
|
274
|
+
Filename for saving image (optional).
|
|
275
|
+
"""
|
|
276
|
+
return visualize_dendrogram(dendrogram, names, rotate, width, height, margin, margin_text, scale, line_width,
|
|
277
|
+
n_clusters, color, colors, font_size, reorder, rotate_names, filename)
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
4
|
Created in April 2020
|
|
5
|
-
@
|
|
6
|
-
|
|
7
|
-
Quentin Lutz <qlutz@live.fr>
|
|
5
|
+
@author: Thomas Bonald <thomas.bonald@telecom-paris.fr>
|
|
6
|
+
@author: Quentin Lutz <qlutz@live.fr>
|
|
8
7
|
"""
|
|
9
8
|
from typing import Optional, Iterable, Union, Tuple
|
|
10
9
|
|
|
@@ -357,21 +356,22 @@ def svg_text(pos, text, margin_text, font_size=12, position: str = 'right'):
|
|
|
357
356
|
return """<text text-anchor="{}" x="{}" y="{}" font-size="{}">{}</text>""".format(anchor, x, y, font_size, text)
|
|
358
357
|
|
|
359
358
|
|
|
360
|
-
def
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
359
|
+
def visualize_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[np.ndarray] = None,
|
|
360
|
+
names: Optional[np.ndarray] = None, labels: Optional[Iterable] = None,
|
|
361
|
+
name_position: str = 'right', scores: Optional[Iterable] = None,
|
|
362
|
+
probs: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
363
|
+
seeds: Union[list, dict] = None, width: Optional[float] = 400, height: Optional[float] = 300,
|
|
364
|
+
margin: float = 20, margin_text: float = 3, scale: float = 1,
|
|
365
|
+
node_order: Optional[np.ndarray] = None, node_size: float = 7, node_size_min: float = 1,
|
|
366
|
+
node_size_max: float = 20,
|
|
367
|
+
display_node_weight: Optional[bool] = None, node_weights: Optional[np.ndarray] = None,
|
|
368
|
+
node_width: float = 1, node_width_max: float = 3, node_color: str = 'gray',
|
|
369
|
+
display_edges: bool = True, edge_labels: Optional[list] = None,
|
|
370
|
+
edge_width: float = 1, edge_width_min: float = 0.5,
|
|
371
|
+
edge_width_max: float = 20, display_edge_weight: bool = True,
|
|
372
|
+
edge_color: Optional[str] = None, label_colors: Optional[Iterable] = None,
|
|
373
|
+
font_size: int = 12, directed: Optional[bool] = None, filename: Optional[str] = None) -> str:
|
|
374
|
+
"""Return the image of a graph in SVG format.
|
|
375
375
|
|
|
376
376
|
Parameters
|
|
377
377
|
----------
|
|
@@ -453,8 +453,8 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
453
453
|
>>> graph = karate_club(True)
|
|
454
454
|
>>> adjacency = graph.adjacency
|
|
455
455
|
>>> position = graph.position
|
|
456
|
-
>>> from sknetwork.visualization import
|
|
457
|
-
>>> image =
|
|
456
|
+
>>> from sknetwork.visualization import visualize_graph
|
|
457
|
+
>>> image = visualize_graph(adjacency, position)
|
|
458
458
|
>>> image[1:4]
|
|
459
459
|
'svg'
|
|
460
460
|
"""
|
|
@@ -569,28 +569,28 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
569
569
|
return svg
|
|
570
570
|
|
|
571
571
|
|
|
572
|
-
def
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
"""Return
|
|
572
|
+
def visualize_bigraph(biadjacency: sparse.csr_matrix,
|
|
573
|
+
names_row: Optional[np.ndarray] = None, names_col: Optional[np.ndarray] = None,
|
|
574
|
+
labels_row: Optional[Union[dict, np.ndarray]] = None,
|
|
575
|
+
labels_col: Optional[Union[dict, np.ndarray]] = None,
|
|
576
|
+
scores_row: Optional[Union[dict, np.ndarray]] = None,
|
|
577
|
+
scores_col: Optional[Union[dict, np.ndarray]] = None,
|
|
578
|
+
probs_row: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
579
|
+
probs_col: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
580
|
+
seeds_row: Union[list, dict] = None, seeds_col: Union[list, dict] = None,
|
|
581
|
+
position_row: Optional[np.ndarray] = None, position_col: Optional[np.ndarray] = None,
|
|
582
|
+
reorder: bool = True, width: Optional[float] = 400,
|
|
583
|
+
height: Optional[float] = 300, margin: float = 20, margin_text: float = 3, scale: float = 1,
|
|
584
|
+
node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20,
|
|
585
|
+
display_node_weight: bool = False,
|
|
586
|
+
node_weights_row: Optional[np.ndarray] = None, node_weights_col: Optional[np.ndarray] = None,
|
|
587
|
+
node_width: float = 1, node_width_max: float = 3,
|
|
588
|
+
color_row: str = 'gray', color_col: str = 'gray', label_colors: Optional[Iterable] = None,
|
|
589
|
+
display_edges: bool = True, edge_labels: Optional[list] = None, edge_width: float = 1,
|
|
590
|
+
edge_width_min: float = 0.5, edge_width_max: float = 10, edge_color: str = 'black',
|
|
591
|
+
display_edge_weight: bool = True,
|
|
592
|
+
font_size: int = 12, filename: Optional[str] = None) -> str:
|
|
593
|
+
"""Return the image of a bipartite graph in SVG format.
|
|
594
594
|
|
|
595
595
|
Parameters
|
|
596
596
|
----------
|
|
@@ -682,8 +682,8 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
682
682
|
-------
|
|
683
683
|
>>> from sknetwork.data import movie_actor
|
|
684
684
|
>>> biadjacency = movie_actor()
|
|
685
|
-
>>> from sknetwork.visualization import
|
|
686
|
-
>>> image =
|
|
685
|
+
>>> from sknetwork.visualization import visualize_bigraph
|
|
686
|
+
>>> image = visualize_bigraph(biadjacency)
|
|
687
687
|
>>> image[1:4]
|
|
688
688
|
'svg'
|
|
689
689
|
"""
|
|
@@ -820,3 +820,220 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
820
820
|
f.write(svg)
|
|
821
821
|
|
|
822
822
|
return svg
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[np.ndarray] = None,
|
|
826
|
+
names: Optional[np.ndarray] = None, labels: Optional[Iterable] = None, name_position: str = 'right',
|
|
827
|
+
scores: Optional[Iterable] = None, probs: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
828
|
+
seeds: Union[list, dict] = None, width: Optional[float] = 400, height: Optional[float] = 300,
|
|
829
|
+
margin: float = 20, margin_text: float = 3, scale: float = 1, node_order: Optional[np.ndarray] = None,
|
|
830
|
+
node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20,
|
|
831
|
+
display_node_weight: Optional[bool] = None, node_weights: Optional[np.ndarray] = None,
|
|
832
|
+
node_width: float = 1, node_width_max: float = 3, node_color: str = 'gray',
|
|
833
|
+
display_edges: bool = True, edge_labels: Optional[list] = None,
|
|
834
|
+
edge_width: float = 1, edge_width_min: float = 0.5,
|
|
835
|
+
edge_width_max: float = 20, display_edge_weight: bool = True,
|
|
836
|
+
edge_color: Optional[str] = None, label_colors: Optional[Iterable] = None,
|
|
837
|
+
font_size: int = 12, directed: Optional[bool] = None, filename: Optional[str] = None) -> str:
|
|
838
|
+
"""Return the image of a graph in SVG format.
|
|
839
|
+
|
|
840
|
+
Alias for visualize_graph.
|
|
841
|
+
|
|
842
|
+
Parameters
|
|
843
|
+
----------
|
|
844
|
+
adjacency :
|
|
845
|
+
Adjacency matrix of the graph.
|
|
846
|
+
position :
|
|
847
|
+
Positions of the nodes.
|
|
848
|
+
names :
|
|
849
|
+
Names of the nodes.
|
|
850
|
+
labels :
|
|
851
|
+
Labels of the nodes (negative values mean no label).
|
|
852
|
+
name_position :
|
|
853
|
+
Position of the names (left, right, above, below)
|
|
854
|
+
scores :
|
|
855
|
+
Scores of the nodes (measure of importance).
|
|
856
|
+
probs :
|
|
857
|
+
Probability distribution over labels.
|
|
858
|
+
seeds :
|
|
859
|
+
Nodes to be highlighted (if dict, only keys are considered).
|
|
860
|
+
width :
|
|
861
|
+
Width of the image.
|
|
862
|
+
height :
|
|
863
|
+
Height of the image.
|
|
864
|
+
margin :
|
|
865
|
+
Margin of the image.
|
|
866
|
+
margin_text :
|
|
867
|
+
Margin between node and text.
|
|
868
|
+
scale :
|
|
869
|
+
Multiplicative factor on the dimensions of the image.
|
|
870
|
+
node_order :
|
|
871
|
+
Order in which nodes are displayed.
|
|
872
|
+
node_size :
|
|
873
|
+
Size of nodes.
|
|
874
|
+
node_size_min :
|
|
875
|
+
Minimum size of a node.
|
|
876
|
+
node_size_max:
|
|
877
|
+
Maximum size of a node.
|
|
878
|
+
node_width :
|
|
879
|
+
Width of node circle.
|
|
880
|
+
node_width_max :
|
|
881
|
+
Maximum width of node circle.
|
|
882
|
+
node_color :
|
|
883
|
+
Default color of nodes (svg color).
|
|
884
|
+
display_node_weight :
|
|
885
|
+
If ``True``, display node weights through node size.
|
|
886
|
+
node_weights :
|
|
887
|
+
Node weights.
|
|
888
|
+
display_edges :
|
|
889
|
+
If ``True``, display edges.
|
|
890
|
+
edge_labels :
|
|
891
|
+
Labels of the edges, as a list of tuples (source, destination, label)
|
|
892
|
+
edge_width :
|
|
893
|
+
Width of edges.
|
|
894
|
+
edge_width_min :
|
|
895
|
+
Minimum width of edges.
|
|
896
|
+
edge_width_max :
|
|
897
|
+
Maximum width of edges.
|
|
898
|
+
display_edge_weight :
|
|
899
|
+
If ``True``, display edge weights through edge widths.
|
|
900
|
+
edge_color :
|
|
901
|
+
Default color of edges (svg color).
|
|
902
|
+
label_colors:
|
|
903
|
+
Colors of the labels (svg colors).
|
|
904
|
+
font_size :
|
|
905
|
+
Font size.
|
|
906
|
+
directed :
|
|
907
|
+
If ``True``, considers the graph as directed.
|
|
908
|
+
filename :
|
|
909
|
+
Filename for saving image (optional).
|
|
910
|
+
|
|
911
|
+
Returns
|
|
912
|
+
-------
|
|
913
|
+
image : str
|
|
914
|
+
SVG image.
|
|
915
|
+
"""
|
|
916
|
+
return visualize_graph(adjacency, position, names, labels, name_position, scores, probs, seeds, width, height,
|
|
917
|
+
margin, margin_text, scale, node_order, node_size, node_size_min, node_size_max,
|
|
918
|
+
display_node_weight, node_weights, node_width, node_width_max, node_color, display_edges,
|
|
919
|
+
edge_labels, edge_width, edge_width_min, edge_width_max, display_edge_weight, edge_color,
|
|
920
|
+
label_colors, font_size, directed, filename)
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
924
|
+
names_row: Optional[np.ndarray] = None, names_col: Optional[np.ndarray] = None,
|
|
925
|
+
labels_row: Optional[Union[dict, np.ndarray]] = None,
|
|
926
|
+
labels_col: Optional[Union[dict, np.ndarray]] = None,
|
|
927
|
+
scores_row: Optional[Union[dict, np.ndarray]] = None,
|
|
928
|
+
scores_col: Optional[Union[dict, np.ndarray]] = None,
|
|
929
|
+
probs_row: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
930
|
+
probs_col: Optional[Union[np.ndarray, sparse.csr_matrix]] = None,
|
|
931
|
+
seeds_row: Union[list, dict] = None, seeds_col: Union[list, dict] = None,
|
|
932
|
+
position_row: Optional[np.ndarray] = None, position_col: Optional[np.ndarray] = None,
|
|
933
|
+
reorder: bool = True, width: Optional[float] = 400,
|
|
934
|
+
height: Optional[float] = 300, margin: float = 20, margin_text: float = 3, scale: float = 1,
|
|
935
|
+
node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20,
|
|
936
|
+
display_node_weight: bool = False,
|
|
937
|
+
node_weights_row: Optional[np.ndarray] = None, node_weights_col: Optional[np.ndarray] = None,
|
|
938
|
+
node_width: float = 1, node_width_max: float = 3,
|
|
939
|
+
color_row: str = 'gray', color_col: str = 'gray', label_colors: Optional[Iterable] = None,
|
|
940
|
+
display_edges: bool = True, edge_labels: Optional[list] = None, edge_width: float = 1,
|
|
941
|
+
edge_width_min: float = 0.5, edge_width_max: float = 10, edge_color: str = 'black',
|
|
942
|
+
display_edge_weight: bool = True,
|
|
943
|
+
font_size: int = 12, filename: Optional[str] = None) -> str:
|
|
944
|
+
"""Return the image of a bipartite graph in SVG format.
|
|
945
|
+
|
|
946
|
+
Alias for visualize_bigraph.
|
|
947
|
+
|
|
948
|
+
Parameters
|
|
949
|
+
----------
|
|
950
|
+
biadjacency :
|
|
951
|
+
Biadjacency matrix of the graph.
|
|
952
|
+
names_row :
|
|
953
|
+
Names of the rows.
|
|
954
|
+
names_col :
|
|
955
|
+
Names of the columns.
|
|
956
|
+
labels_row :
|
|
957
|
+
Labels of the rows (negative values mean no label).
|
|
958
|
+
labels_col :
|
|
959
|
+
Labels of the columns (negative values mean no label).
|
|
960
|
+
scores_row :
|
|
961
|
+
Scores of the rows (measure of importance).
|
|
962
|
+
scores_col :
|
|
963
|
+
Scores of the columns (measure of importance).
|
|
964
|
+
probs_row :
|
|
965
|
+
Probability distribution over labels for rows.
|
|
966
|
+
probs_col :
|
|
967
|
+
Probability distribution over labels for columns.
|
|
968
|
+
seeds_row :
|
|
969
|
+
Rows to be highlighted (if dict, only keys are considered).
|
|
970
|
+
seeds_col :
|
|
971
|
+
Columns to be highlighted (if dict, only keys are considered).
|
|
972
|
+
position_row :
|
|
973
|
+
Positions of the rows.
|
|
974
|
+
position_col :
|
|
975
|
+
Positions of the columns.
|
|
976
|
+
reorder :
|
|
977
|
+
Use clustering to order nodes.
|
|
978
|
+
width :
|
|
979
|
+
Width of the image.
|
|
980
|
+
height :
|
|
981
|
+
Height of the image.
|
|
982
|
+
margin :
|
|
983
|
+
Margin of the image.
|
|
984
|
+
margin_text :
|
|
985
|
+
Margin between node and text.
|
|
986
|
+
scale :
|
|
987
|
+
Multiplicative factor on the dimensions of the image.
|
|
988
|
+
node_size :
|
|
989
|
+
Size of nodes.
|
|
990
|
+
node_size_min :
|
|
991
|
+
Minimum size of nodes.
|
|
992
|
+
node_size_max :
|
|
993
|
+
Maximum size of nodes.
|
|
994
|
+
display_node_weight :
|
|
995
|
+
If ``True``, display node weights through node size.
|
|
996
|
+
node_weights_row :
|
|
997
|
+
Weights of rows (used only if **display_node_weight** is ``True``).
|
|
998
|
+
node_weights_col :
|
|
999
|
+
Weights of columns (used only if **display_node_weight** is ``True``).
|
|
1000
|
+
node_width :
|
|
1001
|
+
Width of node circle.
|
|
1002
|
+
node_width_max :
|
|
1003
|
+
Maximum width of node circle.
|
|
1004
|
+
color_row :
|
|
1005
|
+
Default color of rows (svg color).
|
|
1006
|
+
color_col :
|
|
1007
|
+
Default color of cols (svg color).
|
|
1008
|
+
label_colors :
|
|
1009
|
+
Colors of the labels (svg color).
|
|
1010
|
+
display_edges :
|
|
1011
|
+
If ``True``, display edges.
|
|
1012
|
+
edge_labels :
|
|
1013
|
+
Labels of the edges, as a list of tuples (source, destination, label)
|
|
1014
|
+
edge_width :
|
|
1015
|
+
Width of edges.
|
|
1016
|
+
edge_width_min :
|
|
1017
|
+
Minimum width of edges.
|
|
1018
|
+
edge_width_max :
|
|
1019
|
+
Maximum width of edges.
|
|
1020
|
+
display_edge_weight :
|
|
1021
|
+
If ``True``, display edge weights through edge widths.
|
|
1022
|
+
edge_color :
|
|
1023
|
+
Default color of edges (svg color).
|
|
1024
|
+
font_size :
|
|
1025
|
+
Font size.
|
|
1026
|
+
filename :
|
|
1027
|
+
Filename for saving image (optional).
|
|
1028
|
+
|
|
1029
|
+
Returns
|
|
1030
|
+
-------
|
|
1031
|
+
image : str
|
|
1032
|
+
SVG image.
|
|
1033
|
+
"""
|
|
1034
|
+
return visualize_bigraph(biadjacency, names_row, names_col, labels_row, labels_col, scores_row, scores_col,
|
|
1035
|
+
probs_row, probs_col, seeds_row, seeds_col, position_row, position_col, reorder,
|
|
1036
|
+
width, height, margin, margin_text, scale, node_size, node_size_min, node_size_max,
|
|
1037
|
+
display_node_weight, node_weights_row, node_weights_col, node_width, node_width_max,
|
|
1038
|
+
color_row, color_col, label_colors, display_edges, edge_labels, edge_width, edge_width_min,
|
|
1039
|
+
edge_width_max, edge_color, display_edge_weight, font_size, filename)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
|
-
"""tests for visualization
|
|
3
|
+
"""tests for visualization of dendrograms"""
|
|
4
4
|
|
|
5
5
|
import tempfile
|
|
6
6
|
import unittest
|
|
@@ -9,7 +9,7 @@ import numpy as np
|
|
|
9
9
|
|
|
10
10
|
from sknetwork.data.toy_graphs import karate_club, painters
|
|
11
11
|
from sknetwork.hierarchy import Paris
|
|
12
|
-
from sknetwork.visualization.dendrograms import svg_dendrogram, svg_dendrogram_top
|
|
12
|
+
from sknetwork.visualization.dendrograms import visualize_dendrogram, svg_dendrogram, svg_dendrogram_top
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
# noinspection DuplicatedCode
|
|
@@ -22,9 +22,9 @@ class TestVisualization(unittest.TestCase):
|
|
|
22
22
|
image = svg_dendrogram(dendrogram)
|
|
23
23
|
self.assertEqual(image[1:4], 'svg')
|
|
24
24
|
n = adjacency.shape[0]
|
|
25
|
-
image =
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
image = visualize_dendrogram(dendrogram, names=np.arange(n), width=200, height=200, margin=10, margin_text=5,
|
|
26
|
+
scale=3, n_clusters=3, color='green', colors=['red', 'blue'], font_size=14,
|
|
27
|
+
reorder=True, rotate=True)
|
|
28
28
|
self.assertEqual(image[1:4], 'svg')
|
|
29
29
|
image = svg_dendrogram(dendrogram, names=np.arange(n), width=200, height=200, margin=10, margin_text=5, scale=3,
|
|
30
30
|
n_clusters=3, color='green', colors={0: 'red', 1: 'blue'}, font_size=14, reorder=False,
|
|
@@ -40,14 +40,14 @@ class TestVisualization(unittest.TestCase):
|
|
|
40
40
|
names = graph.names
|
|
41
41
|
paris = Paris()
|
|
42
42
|
dendrogram = paris.fit_transform(adjacency)
|
|
43
|
-
image =
|
|
43
|
+
image = visualize_dendrogram(dendrogram)
|
|
44
44
|
self.assertEqual(image[1:4], 'svg')
|
|
45
|
-
image =
|
|
46
|
-
|
|
45
|
+
image = visualize_dendrogram(dendrogram, names=names, width=200, height=200, margin=10, margin_text=5, scale=3,
|
|
46
|
+
n_clusters=3, color='green', font_size=14, reorder=True, rotate=True)
|
|
47
47
|
self.assertEqual(image[1:4], 'svg')
|
|
48
48
|
|
|
49
49
|
filename = tempfile.gettempdir() + '/image'
|
|
50
|
-
_ =
|
|
50
|
+
_ = visualize_dendrogram(dendrogram, filename=filename)
|
|
51
51
|
with open(filename + '.svg', 'r') as f:
|
|
52
52
|
row = f.readline()
|
|
53
53
|
self.assertEqual(row[1:4], 'svg')
|