risk-network 0.0.9b45__tar.gz → 0.0.9b46__tar.gz
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.
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/PKG-INFO +1 -1
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/__init__.py +1 -1
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/neighborhoods/domains.py +23 -13
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/geometry.py +2 -19
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk_network.egg-info/PKG-INFO +1 -1
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/setup.py +1 -1
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/LICENSE +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/MANIFEST.in +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/README.md +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/pyproject.toml +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/annotations/io.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/log/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/log/console.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/log/parameters.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/neighborhoods/api.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/graph/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/graph/api.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/graph/graph.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/graph/summary.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/io.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/api.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/canvas.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/contour.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/labels.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/network.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/plotter.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/utils/colors.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/network/plotter/utils/layout.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/risk.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/permutation/permutation.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/permutation/test_functions.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/significance.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk/stats/stat_tests.py +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.9b45 → risk_network-0.0.9b46}/setup.cfg +0 -0
@@ -3,12 +3,12 @@ risk/neighborhoods/domains
|
|
3
3
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
|
-
from contextlib import suppress
|
7
6
|
from itertools import product
|
8
7
|
from typing import Tuple, Union
|
9
8
|
|
10
9
|
import numpy as np
|
11
10
|
import pandas as pd
|
11
|
+
from numpy.linalg import LinAlgError
|
12
12
|
from scipy.cluster.hierarchy import linkage, fcluster
|
13
13
|
from sklearn.metrics import silhouette_score
|
14
14
|
from tqdm import tqdm
|
@@ -73,7 +73,7 @@ def define_domains(
|
|
73
73
|
domains = fcluster(Z, max_d_optimal, criterion=linkage_criterion)
|
74
74
|
top_annotations["domain"] = 0
|
75
75
|
top_annotations.loc[top_annotations["significant_annotations"], "domain"] = domains
|
76
|
-
except ValueError:
|
76
|
+
except (ValueError, LinAlgError):
|
77
77
|
# If a ValueError is encountered, handle it by assigning unique domains
|
78
78
|
n_rows = len(top_annotations)
|
79
79
|
if linkage_criterion == "off":
|
@@ -247,16 +247,17 @@ def _optimize_silhouette_across_linkage_and_metrics(
|
|
247
247
|
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]",
|
248
248
|
):
|
249
249
|
# Some linkage methods and metrics may not work with certain data
|
250
|
-
|
250
|
+
try:
|
251
251
|
Z = linkage(m, method=method, metric=metric)
|
252
|
+
except (ValueError, LinAlgError):
|
253
|
+
# If linkage fails, set a default threshold (a float) and a very poor score
|
254
|
+
current_threshold = 0.0
|
255
|
+
score = -float("inf")
|
256
|
+
else:
|
252
257
|
# Only optimize silhouette score if the threshold is "auto"
|
253
258
|
if linkage_threshold == "auto":
|
254
259
|
threshold, score = _find_best_silhouette_score(Z, m, metric, linkage_criterion)
|
255
|
-
|
256
|
-
best_overall_score = score
|
257
|
-
best_overall_threshold = threshold
|
258
|
-
best_overall_method = method
|
259
|
-
best_overall_metric = metric
|
260
|
+
current_threshold = threshold
|
260
261
|
else:
|
261
262
|
# Use the provided threshold without optimization
|
262
263
|
score = silhouette_score(
|
@@ -264,11 +265,20 @@ def _optimize_silhouette_across_linkage_and_metrics(
|
|
264
265
|
fcluster(Z, linkage_threshold * np.max(Z[:, 2]), criterion=linkage_criterion),
|
265
266
|
metric=metric,
|
266
267
|
)
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
268
|
+
current_threshold = linkage_threshold
|
269
|
+
|
270
|
+
if score > best_overall_score:
|
271
|
+
best_overall_score = score
|
272
|
+
best_overall_threshold = float(current_threshold) # Ensure it's a float
|
273
|
+
best_overall_method = method
|
274
|
+
best_overall_metric = metric
|
275
|
+
|
276
|
+
# Ensure that we always return a valid tuple:
|
277
|
+
if best_overall_score == -np.inf:
|
278
|
+
# No valid linkage was found; return default values.
|
279
|
+
best_overall_threshold = float(linkage_threshold) if linkage_threshold != "auto" else 0.0
|
280
|
+
best_overall_method = linkage_method
|
281
|
+
best_overall_metric = linkage_metric
|
272
282
|
|
273
283
|
return best_overall_method, best_overall_metric, best_overall_threshold
|
274
284
|
|
@@ -12,7 +12,7 @@ def assign_edge_lengths(
|
|
12
12
|
compute_sphere: bool = True,
|
13
13
|
surface_depth: float = 0.0,
|
14
14
|
) -> nx.Graph:
|
15
|
-
"""Assign edge lengths in the graph, optionally mapping nodes to a sphere
|
15
|
+
"""Assign edge lengths in the graph, optionally mapping nodes to a sphere.
|
16
16
|
|
17
17
|
Args:
|
18
18
|
G (nx.Graph): The input graph.
|
@@ -33,9 +33,8 @@ def assign_edge_lengths(
|
|
33
33
|
return np.arccos(np.clip(dot_products, -1.0, 1.0))
|
34
34
|
return np.linalg.norm(u_coords - v_coords, axis=1)
|
35
35
|
|
36
|
-
# Normalize graph coordinates
|
36
|
+
# Normalize graph coordinates
|
37
37
|
_normalize_graph_coordinates(G)
|
38
|
-
_normalize_weights(G)
|
39
38
|
|
40
39
|
# Map nodes to sphere and adjust depth if required
|
41
40
|
if compute_sphere:
|
@@ -110,22 +109,6 @@ def _normalize_graph_coordinates(G: nx.Graph) -> None:
|
|
110
109
|
G.nodes[node]["x"], G.nodes[node]["y"] = normalized_xy[i]
|
111
110
|
|
112
111
|
|
113
|
-
def _normalize_weights(G: nx.Graph) -> None:
|
114
|
-
"""Normalize the weights of the edges in the graph.
|
115
|
-
|
116
|
-
Args:
|
117
|
-
G (nx.Graph): The input graph with weighted edges.
|
118
|
-
"""
|
119
|
-
# "weight" is present for all edges - weights are 1.0 if weight was not specified by the user
|
120
|
-
weights = [data["weight"] for _, _, data in G.edges(data=True)]
|
121
|
-
if weights: # Ensure there are weighted edges
|
122
|
-
min_weight = min(weights)
|
123
|
-
max_weight = max(weights)
|
124
|
-
range_weight = max_weight - min_weight if max_weight > min_weight else 1
|
125
|
-
for _, _, data in G.edges(data=True):
|
126
|
-
data["normalized_weight"] = (data["weight"] - min_weight) / range_weight
|
127
|
-
|
128
|
-
|
129
112
|
def _create_depth(G: nx.Graph, surface_depth: float = 0.0) -> nx.Graph:
|
130
113
|
"""Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
|
131
114
|
|
@@ -10,8 +10,8 @@ from setuptools import setup, find_packages
|
|
10
10
|
import numpy
|
11
11
|
|
12
12
|
|
13
|
-
# Function to extract version from __init__.py
|
14
13
|
def find_version():
|
14
|
+
"""Function to find the version string in the __init__.py file."""
|
15
15
|
with open("risk/__init__.py", "r", encoding="utf-8") as f:
|
16
16
|
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", f.read(), re.M)
|
17
17
|
if version_match:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|