risk-network 0.0.7b6__tar.gz → 0.0.7b7__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.7b6 → risk_network-0.0.7b7}/PKG-INFO +1 -1
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/__init__.py +1 -1
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/permutation/permutation.py +16 -14
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk_network.egg-info/PKG-INFO +1 -1
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/LICENSE +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/MANIFEST.in +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/README.md +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/pyproject.toml +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/annotations/io.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/constants.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/log/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/log/console.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/log/params.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/neighborhoods/domains.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/network/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/network/geometry.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/network/graph.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/network/io.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/network/plot.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/risk.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/hypergeom.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/permutation/test_functions.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/poisson.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk/stats/stats.py +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/setup.cfg +0 -0
- {risk_network-0.0.7b6 → risk_network-0.0.7b7}/setup.py +0 -0
@@ -4,6 +4,7 @@ risk/stats/permutation/permutation
|
|
4
4
|
"""
|
5
5
|
|
6
6
|
from multiprocessing import get_context, Manager
|
7
|
+
from multiprocessing.managers import ValueProxy
|
7
8
|
from tqdm import tqdm
|
8
9
|
from typing import Any, Callable, Dict
|
9
10
|
|
@@ -111,7 +112,6 @@ def _run_permutation_test(
|
|
111
112
|
# Initialize count matrices for depletion and enrichment
|
112
113
|
counts_depletion = np.zeros(observed_neighborhood_scores.shape)
|
113
114
|
counts_enrichment = np.zeros(observed_neighborhood_scores.shape)
|
114
|
-
|
115
115
|
# Determine the number of permutations to run in each worker process
|
116
116
|
subset_size = num_permutations // max_workers
|
117
117
|
remainder = num_permutations % max_workers
|
@@ -121,7 +121,6 @@ def _run_permutation_test(
|
|
121
121
|
manager = Manager()
|
122
122
|
progress_counter = manager.Value("i", 0)
|
123
123
|
total_progress = num_permutations
|
124
|
-
|
125
124
|
# Execute the permutation test using multiprocessing
|
126
125
|
with ctx.Pool(max_workers) as pool:
|
127
126
|
with tqdm(total=total_progress, desc="Total progress", position=0) as progress:
|
@@ -135,7 +134,8 @@ def _run_permutation_test(
|
|
135
134
|
neighborhood_score_func,
|
136
135
|
subset_size + (1 if i < remainder else 0),
|
137
136
|
progress_counter,
|
138
|
-
|
137
|
+
max_workers,
|
138
|
+
rng, # Pass the random number generator to each worker
|
139
139
|
)
|
140
140
|
for i in range(max_workers)
|
141
141
|
]
|
@@ -152,10 +152,10 @@ def _run_permutation_test(
|
|
152
152
|
# Ensure progress bar reaches 100%
|
153
153
|
progress.update(total_progress - progress.n)
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
155
|
+
# Accumulate results from each worker
|
156
|
+
for local_counts_depletion, local_counts_enrichment in results.get():
|
157
|
+
counts_depletion = np.add(counts_depletion, local_counts_depletion)
|
158
|
+
counts_enrichment = np.add(counts_enrichment, local_counts_enrichment)
|
159
159
|
|
160
160
|
return counts_depletion, counts_enrichment
|
161
161
|
|
@@ -167,7 +167,8 @@ def _permutation_process_subset(
|
|
167
167
|
observed_neighborhood_scores: np.ndarray,
|
168
168
|
neighborhood_score_func: Callable,
|
169
169
|
subset_size: int,
|
170
|
-
progress_counter,
|
170
|
+
progress_counter: ValueProxy,
|
171
|
+
max_workers: int,
|
171
172
|
rng: np.random.Generator,
|
172
173
|
) -> tuple:
|
173
174
|
"""Process a subset of permutations for the permutation test.
|
@@ -179,7 +180,8 @@ def _permutation_process_subset(
|
|
179
180
|
observed_neighborhood_scores (np.ndarray): Observed neighborhood scores.
|
180
181
|
neighborhood_score_func (Callable): Function to calculate neighborhood scores.
|
181
182
|
subset_size (int): Number of permutations to run in this subset.
|
182
|
-
progress_counter: Shared counter for tracking progress.
|
183
|
+
progress_counter (multiprocessing.managers.ValueProxy): Shared counter for tracking progress.
|
184
|
+
max_workers (int): Number of workers for multiprocessing.
|
183
185
|
rng (np.random.Generator): Random number generator object.
|
184
186
|
|
185
187
|
Returns:
|
@@ -188,10 +190,11 @@ def _permutation_process_subset(
|
|
188
190
|
# Initialize local count matrices for this worker
|
189
191
|
local_counts_depletion = np.zeros(observed_neighborhood_scores.shape)
|
190
192
|
local_counts_enrichment = np.zeros(observed_neighborhood_scores.shape)
|
191
|
-
# NOTE: Limit the number of threads used by NumPy's BLAS implementation to 1.
|
192
|
-
# This can help prevent oversubscription of CPU resources during multiprocessing,
|
193
|
-
#
|
194
|
-
|
193
|
+
# NOTE: Limit the number of threads used by NumPy's BLAS implementation to 1 when more than one worker is used.
|
194
|
+
# This can help prevent oversubscription of CPU resources during multiprocessing, ensuring that each process
|
195
|
+
# doesn't use more than one CPU core.
|
196
|
+
limits = None if max_workers == 1 else 1
|
197
|
+
with threadpool_limits(limits=limits, user_api="blas"):
|
195
198
|
for _ in range(subset_size):
|
196
199
|
# Permute the annotation matrix using the RNG
|
197
200
|
annotation_matrix_permut = annotation_matrix[rng.permutation(idxs)]
|
@@ -209,7 +212,6 @@ def _permutation_process_subset(
|
|
209
212
|
local_counts_enrichment,
|
210
213
|
permuted_neighborhood_scores >= observed_neighborhood_scores,
|
211
214
|
)
|
212
|
-
|
213
215
|
# Update the shared progress counter
|
214
216
|
progress_counter.value += 1
|
215
217
|
|
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
|