Skip to content

Commit ef35410

Browse files
committed
use generator
1 parent 5765b9b commit ef35410

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

preliz/internal/optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def func(x, dist, q):
612612
def get_weighted_rvs(target, size, rng):
613613
targets = [t[0] for t in target]
614614
weights = [t[1] for t in target]
615-
target_rnd_choices = np.random.choice(len(targets), size=size, p=weights)
615+
target_rnd_choices = rng.choice(len(targets), size=size, p=weights)
616616
samples = [target.rvs(size, random_state=rng) for target in targets]
617617
return np.choose(target_rnd_choices, samples)
618618

preliz/tests/predictive_explorer.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@
9797
"source": [
9898
"%%ipytest\n",
9999
"\n",
100+
"rng = np.random.default_rng(1241)\n",
101+
"\n",
100102
"data = pd.DataFrame(\n",
101103
" {\n",
102-
" \"y\": np.random.normal(size=117),\n",
103-
" \"x\": np.random.normal(size=117),\n",
104+
" \"y\": rng.normal(size=117),\n",
105+
" \"x\": rng.normal(size=117),\n",
104106
" }\n",
105107
")\n",
106108
"data.head()\n",

preliz/tests/test_ppe.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import preliz as pz
1111

12-
np.random.seed(42)
12+
rng = np.random.default_rng(1241)
1313

1414

1515
@pytest.mark.parametrize(
@@ -20,7 +20,7 @@
2020
"sigma_x": 10,
2121
"sigma_z": 10,
2222
"target": pz.Normal(mu=174, sigma=20),
23-
"X": np.random.normal(0, 10, 120),
23+
"X": rng.normal(0, 10, 120),
2424
"new_x": 174,
2525
"new_z": 2.9,
2626
},
@@ -29,7 +29,7 @@
2929
"sigma_x": [10, 10],
3030
"sigma_z": 10,
3131
"target": pz.Normal(mu=174, sigma=20),
32-
"X": np.random.normal(0, 10, 120),
32+
"X": rng.normal(0, 10, 120),
3333
"new_x": [174, 174],
3434
"new_z": 2.9,
3535
},
@@ -38,7 +38,7 @@
3838
"sigma_x": 10,
3939
"sigma_z": 10,
4040
"target": [(pz.Normal(mu=174, sigma=20), 0.5), (pz.Normal(mu=176, sigma=19.5), 0.5)],
41-
"X": np.random.normal(0, 10, 120),
41+
"X": rng.normal(0, 10, 120),
4242
"new_x": 175,
4343
"new_z": 2.9,
4444
},
@@ -51,7 +51,7 @@
5151
(pz.Normal(mu=176, sigma=19.5), 0.4),
5252
(pz.StudentT(mu=174, sigma=20, nu=3), 0.1),
5353
],
54-
"X": np.random.normal(0, 10, 120),
54+
"X": rng.normal(0, 10, 120),
5555
"new_x": [175, 175],
5656
"new_z": 3,
5757
},

0 commit comments

Comments
 (0)