Skip to content

Commit 384a280

Browse files
committed
update randomness
1 parent f812e7d commit 384a280

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

treeprofiler/src/phylosignal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def mhalpha(a, b, x, l0, se):
6060

6161

6262
# Metropolis-Hastings step for beta parameter
63-
6463
def mhbeta(a, b, x, l0, se):
6564
"""
6665
Metropolis-Hastings step for beta parameter (no numba).
@@ -250,6 +249,7 @@ def run_delta(acr_results, tree, run_whole_tree=False, ent_type='LSE', lambda0=0
250249
marginal_probs = np.asarray(children_data)
251250
# run delta for each discrete trait
252251
# load annotations to leaves
252+
np.random.seed(42) # or any integer seed you prefer
253253
delta_result = delta(marginal_probs, lambda0, se, sim, burn, thin, ent_type, threads)
254254
node.add_prop(add_suffix(prop, "delta"), delta_result)
255255
else:
@@ -259,6 +259,7 @@ def run_delta(acr_results, tree, run_whole_tree=False, ent_type='LSE', lambda0=0
259259
marginal_probs = np.asarray(acr_result[0]['marginal_probabilities'].drop(leafnames))
260260
# run delta for each discrete trait
261261
# load annotations to leaves
262+
np.random.seed(42) # or any integer seed you prefer
262263
delta_result = delta(marginal_probs, lambda0, se, sim, burn, thin, ent_type, threads)
263264
#tree.add_prop(add_suffix(prop, "delta"), delta_result)
264265
prop2delta[prop] = delta_result

treeprofiler/tree_annotate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,13 @@ def parse_fasta(fastafile):
19781978
return fasta_dict
19791979

19801980
def _worker_function(iteration_data):
1981+
1982+
import hashlib
1983+
# Derive a unique seed per worker using time or iteration data
1984+
unique_string = str(iteration_data) + str(time.time())
1985+
seed = int(hashlib.sha256(unique_string.encode()).hexdigest(), 16) % (2**32)
1986+
np.random.seed(seed)
1987+
19811988
# Unpack the necessary data for one iteration
19821989
prop2array, dump_tree, acr_discrete_columns_dict, prediction_method, model, ent_type, lambda0, se, sim, burn, thin, threads = iteration_data
19831990

0 commit comments

Comments
 (0)