scikit-network 0.30.0__cp310-cp310-win_amd64.whl → 0.32.1__cp310-cp310-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.30.0.dist-info → scikit_network-0.32.1.dist-info}/AUTHORS.rst +3 -0
- {scikit_network-0.30.0.dist-info → scikit_network-0.32.1.dist-info}/METADATA +31 -3
- scikit_network-0.32.1.dist-info/RECORD +228 -0
- {scikit_network-0.30.0.dist-info → scikit_network-0.32.1.dist-info}/WHEEL +1 -1
- sknetwork/__init__.py +1 -1
- sknetwork/base.py +67 -0
- sknetwork/classification/base.py +24 -24
- sknetwork/classification/base_rank.py +17 -25
- sknetwork/classification/diffusion.py +35 -35
- sknetwork/classification/knn.py +24 -21
- sknetwork/classification/metrics.py +1 -1
- sknetwork/classification/pagerank.py +10 -10
- sknetwork/classification/propagation.py +23 -20
- sknetwork/classification/tests/test_diffusion.py +13 -3
- sknetwork/classification/vote.cp310-win_amd64.pyd +0 -0
- sknetwork/classification/vote.cpp +14482 -10351
- sknetwork/classification/vote.pyx +1 -3
- sknetwork/clustering/__init__.py +3 -1
- sknetwork/clustering/base.py +36 -40
- sknetwork/clustering/kcenters.py +253 -0
- sknetwork/clustering/leiden.py +241 -0
- sknetwork/clustering/leiden_core.cp310-win_amd64.pyd +0 -0
- sknetwork/clustering/leiden_core.cpp +31564 -0
- sknetwork/clustering/leiden_core.pyx +124 -0
- sknetwork/clustering/louvain.py +133 -102
- sknetwork/clustering/louvain_core.cp310-win_amd64.pyd +0 -0
- sknetwork/clustering/louvain_core.cpp +22457 -18792
- sknetwork/clustering/louvain_core.pyx +86 -96
- sknetwork/clustering/postprocess.py +2 -2
- sknetwork/clustering/propagation_clustering.py +15 -19
- sknetwork/clustering/tests/test_API.py +8 -4
- sknetwork/clustering/tests/test_kcenters.py +92 -0
- sknetwork/clustering/tests/test_leiden.py +34 -0
- sknetwork/clustering/tests/test_louvain.py +3 -4
- sknetwork/data/__init__.py +2 -1
- sknetwork/data/base.py +28 -0
- sknetwork/data/load.py +38 -37
- sknetwork/data/models.py +18 -18
- sknetwork/data/parse.py +54 -33
- sknetwork/data/test_graphs.py +2 -2
- sknetwork/data/tests/test_API.py +1 -1
- sknetwork/data/tests/test_base.py +14 -0
- sknetwork/data/tests/test_load.py +1 -1
- sknetwork/data/tests/test_parse.py +9 -12
- sknetwork/data/tests/test_test_graphs.py +1 -2
- sknetwork/data/toy_graphs.py +18 -18
- sknetwork/embedding/__init__.py +0 -1
- sknetwork/embedding/base.py +21 -20
- sknetwork/embedding/force_atlas.py +3 -2
- sknetwork/embedding/louvain_embedding.py +2 -2
- 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_random_projection.py +2 -2
- sknetwork/embedding/tests/test_spectral.py +5 -8
- sknetwork/embedding/tests/test_svd.py +1 -1
- sknetwork/gnn/base.py +4 -4
- sknetwork/gnn/base_layer.py +3 -3
- sknetwork/gnn/gnn_classifier.py +45 -89
- 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 -35
- sknetwork/gnn/utils.py +8 -8
- sknetwork/hierarchy/base.py +29 -2
- sknetwork/hierarchy/louvain_hierarchy.py +45 -41
- sknetwork/hierarchy/paris.cp310-win_amd64.pyd +0 -0
- sknetwork/hierarchy/paris.cpp +27369 -22852
- sknetwork/hierarchy/paris.pyx +7 -9
- sknetwork/hierarchy/postprocess.py +16 -16
- sknetwork/hierarchy/tests/test_API.py +1 -1
- sknetwork/hierarchy/tests/test_algos.py +5 -0
- sknetwork/hierarchy/tests/test_metrics.py +1 -1
- sknetwork/linalg/__init__.py +1 -1
- sknetwork/linalg/diteration.cp310-win_amd64.pyd +0 -0
- sknetwork/linalg/diteration.cpp +13474 -9454
- sknetwork/linalg/diteration.pyx +0 -2
- sknetwork/linalg/eig_solver.py +1 -1
- sknetwork/linalg/{normalization.py → normalizer.py} +18 -15
- sknetwork/linalg/operators.py +1 -1
- sknetwork/linalg/ppr_solver.py +1 -1
- sknetwork/linalg/push.cp310-win_amd64.pyd +0 -0
- sknetwork/linalg/push.cpp +22993 -18807
- sknetwork/linalg/push.pyx +0 -2
- sknetwork/linalg/svd_solver.py +1 -1
- sknetwork/linalg/tests/test_normalization.py +3 -7
- sknetwork/linalg/tests/test_operators.py +4 -8
- sknetwork/linalg/tests/test_ppr.py +1 -1
- sknetwork/linkpred/base.py +13 -2
- sknetwork/linkpred/nn.py +6 -6
- sknetwork/log.py +19 -0
- sknetwork/path/__init__.py +4 -3
- sknetwork/path/dag.py +54 -0
- sknetwork/path/distances.py +98 -0
- sknetwork/path/search.py +13 -47
- sknetwork/path/shortest_path.py +37 -162
- sknetwork/path/tests/test_dag.py +37 -0
- sknetwork/path/tests/test_distances.py +62 -0
- sknetwork/path/tests/test_search.py +26 -11
- sknetwork/path/tests/test_shortest_path.py +31 -36
- sknetwork/ranking/__init__.py +0 -1
- sknetwork/ranking/base.py +13 -8
- sknetwork/ranking/betweenness.cp310-win_amd64.pyd +0 -0
- sknetwork/ranking/betweenness.cpp +5709 -3017
- sknetwork/ranking/betweenness.pyx +0 -2
- sknetwork/ranking/closeness.py +7 -10
- sknetwork/ranking/pagerank.py +14 -14
- sknetwork/ranking/postprocess.py +12 -3
- sknetwork/ranking/tests/test_API.py +2 -4
- sknetwork/ranking/tests/test_betweenness.py +3 -3
- sknetwork/ranking/tests/test_closeness.py +3 -7
- sknetwork/ranking/tests/test_pagerank.py +11 -5
- sknetwork/ranking/tests/test_postprocess.py +5 -0
- sknetwork/regression/base.py +19 -2
- sknetwork/regression/diffusion.py +24 -10
- sknetwork/regression/tests/test_diffusion.py +8 -0
- sknetwork/test_base.py +35 -0
- sknetwork/test_log.py +15 -0
- sknetwork/topology/__init__.py +7 -8
- sknetwork/topology/cliques.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/{kcliques.cpp → cliques.cpp} +23412 -20276
- sknetwork/topology/cliques.pyx +149 -0
- sknetwork/topology/core.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/{kcore.cpp → core.cpp} +21732 -18867
- sknetwork/topology/core.pyx +90 -0
- sknetwork/topology/cycles.py +243 -0
- sknetwork/topology/minheap.cp310-win_amd64.pyd +0 -0
- sknetwork/{utils → topology}/minheap.cpp +19452 -15368
- sknetwork/{utils → topology}/minheap.pxd +1 -3
- sknetwork/{utils → topology}/minheap.pyx +1 -3
- sknetwork/topology/structure.py +3 -43
- sknetwork/topology/tests/test_cliques.py +11 -11
- sknetwork/topology/tests/test_core.py +19 -0
- sknetwork/topology/tests/test_cycles.py +65 -0
- sknetwork/topology/tests/test_structure.py +2 -16
- sknetwork/topology/tests/test_triangles.py +11 -15
- sknetwork/topology/tests/test_wl.py +72 -0
- sknetwork/topology/triangles.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/triangles.cpp +5056 -2696
- sknetwork/topology/triangles.pyx +74 -89
- sknetwork/topology/weisfeiler_lehman.py +56 -86
- sknetwork/topology/weisfeiler_lehman_core.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/weisfeiler_lehman_core.cpp +14727 -10622
- sknetwork/topology/weisfeiler_lehman_core.pyx +0 -2
- sknetwork/utils/__init__.py +1 -31
- sknetwork/utils/check.py +2 -2
- sknetwork/utils/format.py +5 -3
- sknetwork/utils/membership.py +2 -2
- sknetwork/utils/tests/test_check.py +3 -3
- sknetwork/utils/tests/test_format.py +3 -1
- sknetwork/utils/values.py +1 -1
- sknetwork/visualization/__init__.py +2 -2
- sknetwork/visualization/dendrograms.py +55 -7
- sknetwork/visualization/graphs.py +292 -72
- sknetwork/visualization/tests/test_dendrograms.py +9 -9
- sknetwork/visualization/tests/test_graphs.py +71 -62
- scikit_network-0.30.0.dist-info/RECORD +0 -227
- sknetwork/embedding/louvain_hierarchy.py +0 -142
- sknetwork/embedding/tests/test_louvain_hierarchy.py +0 -19
- sknetwork/path/metrics.py +0 -148
- sknetwork/path/tests/test_metrics.py +0 -29
- sknetwork/ranking/harmonic.py +0 -82
- sknetwork/topology/dag.py +0 -74
- sknetwork/topology/dag_core.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/dag_core.cpp +0 -23350
- sknetwork/topology/dag_core.pyx +0 -38
- sknetwork/topology/kcliques.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/kcliques.pyx +0 -193
- sknetwork/topology/kcore.cp310-win_amd64.pyd +0 -0
- sknetwork/topology/kcore.pyx +0 -120
- sknetwork/topology/tests/test_cores.py +0 -21
- sknetwork/topology/tests/test_dag.py +0 -26
- sknetwork/topology/tests/test_wl_coloring.py +0 -49
- sknetwork/topology/tests/test_wl_kernel.py +0 -31
- sknetwork/utils/base.py +0 -35
- sknetwork/utils/minheap.cp310-win_amd64.pyd +0 -0
- sknetwork/utils/simplex.py +0 -140
- sknetwork/utils/tests/test_base.py +0 -28
- sknetwork/utils/tests/test_bunch.py +0 -16
- sknetwork/utils/tests/test_projection_simplex.py +0 -33
- sknetwork/utils/tests/test_verbose.py +0 -15
- sknetwork/utils/verbose.py +0 -37
- {scikit_network-0.30.0.dist-info → scikit_network-0.32.1.dist-info}/LICENSE +0 -0
- {scikit_network-0.30.0.dist-info → scikit_network-0.32.1.dist-info}/top_level.txt +0 -0
- /sknetwork/{utils → data}/timeout.py +0 -0
|
@@ -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
|
|
|
@@ -12,7 +11,7 @@ import numpy as np
|
|
|
12
11
|
from scipy import sparse
|
|
13
12
|
|
|
14
13
|
from sknetwork.clustering.louvain import Louvain
|
|
15
|
-
from sknetwork.utils.format import is_symmetric
|
|
14
|
+
from sknetwork.utils.format import is_symmetric, check_format
|
|
16
15
|
from sknetwork.embedding.spring import Spring
|
|
17
16
|
from sknetwork.visualization.colors import STANDARD_COLORS, COOLWARM_RGB
|
|
18
17
|
|
|
@@ -291,22 +290,22 @@ def svg_node(pos_node: np.ndarray, size: float, color: str, stroke_width: float
|
|
|
291
290
|
.format(x, y, size, color, stroke_color, stroke_width)
|
|
292
291
|
|
|
293
292
|
|
|
294
|
-
def svg_pie_chart_node(pos_node: np.ndarray, size: float,
|
|
293
|
+
def svg_pie_chart_node(pos_node: np.ndarray, size: float, probs: np.ndarray, colors: np.ndarray,
|
|
295
294
|
stroke_width: float = 1, stroke_color: str = 'black') -> str:
|
|
296
295
|
"""Return svg code for a pie-chart node."""
|
|
297
296
|
x, y = pos_node.astype(float)
|
|
298
297
|
n_colors = len(colors)
|
|
299
298
|
out = ""
|
|
300
|
-
cumsum = np.zeros(
|
|
301
|
-
cumsum[1:] = np.cumsum(
|
|
299
|
+
cumsum = np.zeros(probs.shape[1] + 1)
|
|
300
|
+
cumsum[1:] = np.cumsum(probs)
|
|
302
301
|
if cumsum[-1] == 0:
|
|
303
302
|
return svg_node(pos_node, size, 'white', stroke_width=3)
|
|
304
|
-
|
|
303
|
+
sum_probs = cumsum[-1]
|
|
305
304
|
cumsum = np.multiply(cumsum, (2 * np.pi) / cumsum[-1])
|
|
306
305
|
x_array = size * np.cos(cumsum) + x
|
|
307
306
|
y_array = size * np.sin(cumsum) + y
|
|
308
|
-
large = np.array(
|
|
309
|
-
for index in range(
|
|
307
|
+
large = np.array(probs > sum_probs / 2).ravel()
|
|
308
|
+
for index in range(probs.shape[1]):
|
|
310
309
|
out += """<path d="M {} {} A {} {} 0 {} 1 {} {} L {} {}" style="fill:{};stroke:{};stroke-width:{}" />\n"""\
|
|
311
310
|
.format(x_array[index], y_array[index], size, size, int(large[index]),
|
|
312
311
|
x_array[index + 1], y_array[index + 1], x, y, colors[index % n_colors], stroke_color, stroke_width)
|
|
@@ -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
|
----------
|
|
@@ -387,8 +387,8 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
387
387
|
Position of the names (left, right, above, below)
|
|
388
388
|
scores :
|
|
389
389
|
Scores of the nodes (measure of importance).
|
|
390
|
-
|
|
391
|
-
|
|
390
|
+
probs :
|
|
391
|
+
Probability distribution over labels.
|
|
392
392
|
seeds :
|
|
393
393
|
Nodes to be highlighted (if dict, only keys are considered).
|
|
394
394
|
width :
|
|
@@ -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
|
"""
|
|
@@ -481,7 +481,7 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
481
481
|
position = spring.fit_transform(adjacency)
|
|
482
482
|
|
|
483
483
|
# node colors
|
|
484
|
-
node_colors = get_node_colors(n, labels, scores,
|
|
484
|
+
node_colors = get_node_colors(n, labels, scores, probs, node_color, label_colors)
|
|
485
485
|
|
|
486
486
|
# node sizes
|
|
487
487
|
if display_node_weight is None:
|
|
@@ -545,14 +545,15 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
545
545
|
|
|
546
546
|
# nodes
|
|
547
547
|
for i in node_order:
|
|
548
|
-
if
|
|
548
|
+
if probs is None:
|
|
549
549
|
svg += svg_node(position[i], node_sizes[i], node_colors[i], node_widths[i])
|
|
550
550
|
else:
|
|
551
|
-
|
|
552
|
-
|
|
551
|
+
probs = check_format(probs)
|
|
552
|
+
if probs[i].nnz == 1:
|
|
553
|
+
index = probs[i].indices[0]
|
|
553
554
|
svg += svg_node(position[i], node_sizes[i], node_colors[index], node_widths[i])
|
|
554
555
|
else:
|
|
555
|
-
svg += svg_pie_chart_node(position[i], node_sizes[i],
|
|
556
|
+
svg += svg_pie_chart_node(position[i], node_sizes[i], probs[i].todense(),
|
|
556
557
|
node_colors, node_widths[i])
|
|
557
558
|
|
|
558
559
|
# text
|
|
@@ -568,28 +569,28 @@ def svg_graph(adjacency: Optional[sparse.csr_matrix] = None, position: Optional[
|
|
|
568
569
|
return svg
|
|
569
570
|
|
|
570
571
|
|
|
571
|
-
def
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
"""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.
|
|
593
594
|
|
|
594
595
|
Parameters
|
|
595
596
|
----------
|
|
@@ -607,10 +608,10 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
607
608
|
Scores of the rows (measure of importance).
|
|
608
609
|
scores_col :
|
|
609
610
|
Scores of the columns (measure of importance).
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
611
|
+
probs_row :
|
|
612
|
+
Probability distribution over labels for rows.
|
|
613
|
+
probs_col :
|
|
614
|
+
Probability distribution over labels for columns.
|
|
614
615
|
seeds_row :
|
|
615
616
|
Rows to be highlighted (if dict, only keys are considered).
|
|
616
617
|
seeds_col :
|
|
@@ -681,8 +682,8 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
681
682
|
-------
|
|
682
683
|
>>> from sknetwork.data import movie_actor
|
|
683
684
|
>>> biadjacency = movie_actor()
|
|
684
|
-
>>> from sknetwork.visualization import
|
|
685
|
-
>>> image =
|
|
685
|
+
>>> from sknetwork.visualization import visualize_bigraph
|
|
686
|
+
>>> image = visualize_bigraph(biadjacency)
|
|
686
687
|
>>> image[1:4]
|
|
687
688
|
'svg'
|
|
688
689
|
"""
|
|
@@ -717,9 +718,9 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
717
718
|
score_min = None
|
|
718
719
|
score_max = None
|
|
719
720
|
|
|
720
|
-
colors_row = get_node_colors(n_row, labels_row, scores_row,
|
|
721
|
+
colors_row = get_node_colors(n_row, labels_row, scores_row, probs_row, color_row, label_colors,
|
|
721
722
|
score_min, score_max)
|
|
722
|
-
colors_col = get_node_colors(n_col, labels_col, scores_col,
|
|
723
|
+
colors_col = get_node_colors(n_col, labels_col, scores_col, probs_col, color_col, label_colors,
|
|
723
724
|
score_min, score_max)
|
|
724
725
|
|
|
725
726
|
# node sizes
|
|
@@ -783,25 +784,27 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
783
784
|
|
|
784
785
|
# nodes
|
|
785
786
|
for i in range(n_row):
|
|
786
|
-
if
|
|
787
|
+
if probs_row is None:
|
|
787
788
|
svg += svg_node(position_row[i], node_sizes_row[i], colors_row[i], node_widths_row[i])
|
|
788
789
|
else:
|
|
789
|
-
|
|
790
|
-
|
|
790
|
+
probs_row = check_format(probs_row)
|
|
791
|
+
if probs_row[i].nnz == 1:
|
|
792
|
+
index = probs_row[i].indices[0]
|
|
791
793
|
svg += svg_node(position_row[i], node_sizes_row[i], colors_row[index], node_widths_row[i])
|
|
792
794
|
else:
|
|
793
|
-
svg += svg_pie_chart_node(position_row[i], node_sizes_row[i],
|
|
795
|
+
svg += svg_pie_chart_node(position_row[i], node_sizes_row[i], probs_row[i].todense(),
|
|
794
796
|
colors_row, node_widths_row[i])
|
|
795
797
|
|
|
796
798
|
for i in range(n_col):
|
|
797
|
-
if
|
|
799
|
+
if probs_col is None:
|
|
798
800
|
svg += svg_node(position_col[i], node_sizes_col[i], colors_col[i], node_widths_col[i])
|
|
799
801
|
else:
|
|
800
|
-
|
|
801
|
-
|
|
802
|
+
probs_col = check_format(probs_col)
|
|
803
|
+
if probs_col[i].nnz == 1:
|
|
804
|
+
index = probs_col[i].indices[0]
|
|
802
805
|
svg += svg_node(position_col[i], node_sizes_col[i], colors_col[index], node_widths_col[i])
|
|
803
806
|
else:
|
|
804
|
-
svg += svg_pie_chart_node(position_col[i], node_sizes_col[i],
|
|
807
|
+
svg += svg_pie_chart_node(position_col[i], node_sizes_col[i], probs_col[i].todense(),
|
|
805
808
|
colors_col, node_widths_col[i])
|
|
806
809
|
# text
|
|
807
810
|
if names_row is not None:
|
|
@@ -817,3 +820,220 @@ def svg_bigraph(biadjacency: sparse.csr_matrix,
|
|
|
817
820
|
f.write(svg)
|
|
818
821
|
|
|
819
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')
|