Skip to content

Commit 0b319e0

Browse files
committed
Fix bug in effsize_object, remove unnecessary numba function
1 parent cfa479f commit 0b319e0

7 files changed

Lines changed: 17 additions & 30 deletions

File tree

dabest/_effsize_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def __pre_calc(self):
762762
for ix, tname in enumerate(current_tuple[1:]):
763763
if self.__is_paired == "sequential":
764764
cname = current_tuple[ix]
765-
control = grouped_data[tname]
765+
control = grouped_data[cname]
766766
test = grouped_data[tname]
767767

768768
result = TwoGroupsEffectSize(

dabest/_stats_tools/confint_1group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,4 @@ def summary_ci_1group(
135135
}
136136

137137
del B
138-
return out
138+
return out

dabest/_stats_tools/confint_2group_diff.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _calc_accel(jack_dist):
120120
return numer / denom
121121

122122

123-
@njit(cache=True, parallel=True)
123+
@njit(cache=True) # parallelization must be turned off for random number generation
124124
def bootstrap_indices(is_paired, x0_len, x1_len, resamples, random_seed):
125125
np.random.seed(random_seed)
126126
indices = np.empty((resamples, x0_len if is_paired else x0_len + x1_len), dtype=np.int64)
@@ -157,7 +157,7 @@ def compute_bootstrapped_diff(
157157

158158
return out
159159

160-
@njit(cache=True, parallel=True)
160+
@njit(cache=True) # parallelization must be turned off for random number generation
161161
def delta2_bootstrap_loop(x1, x2, x3, x4, resamples, pooled_sd, rng_seed, is_paired):
162162
np.random.seed(rng_seed)
163163
out_delta_g = np.empty(resamples)
@@ -268,7 +268,7 @@ def _compute_alpha_from_ci(ci):
268268
return (100.0 - ci) / 100.0
269269

270270

271-
@njit(cache=True)
271+
# @njit(cache=True)
272272
def _compute_quantile(z, bias, acceleration):
273273
numer = bias + z
274274
denom = 1 - (acceleration * numer)

dabest/_stats_tools/effsize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from scipy.special import gamma
99
from scipy.stats import mannwhitneyu
1010

11+
1112
# %% auto 0
1213
__all__ = ['two_group_difference', 'func_difference', 'cohens_d', 'cohens_h', 'hedges_g', 'cliffs_delta', 'weighted_delta']
1314

@@ -208,6 +209,7 @@ def cohens_d(control:list|tuple|np.ndarray,
208209
return M / divisor
209210

210211
# %% ../../nbs/API/effsize.ipynb 8
212+
# @njit(cache=True) # It uses np.seterr which is not supported by Numba
211213
def cohens_h(control:list|tuple|np.ndarray,
212214
test:list|tuple|np.ndarray
213215
)->float:
@@ -382,4 +384,4 @@ def weighted_delta(difference, group_var):
382384
'''
383385

384386
weight = np.true_divide(1, group_var)
385-
return np.sum(difference*weight)/np.sum(weight)
387+
return np.sum(difference*weight)/np.sum(weight)

nbs/API/confint_2group_diff.ipynb

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
" return numer / denom\n",
177177
"\n",
178178
"\n",
179-
"@njit(cache=True, parallel=True)\n",
179+
"@njit(cache=True) # parallelization must be turned off for random number generation\n",
180180
"def bootstrap_indices(is_paired, x0_len, x1_len, resamples, random_seed):\n",
181181
" np.random.seed(random_seed)\n",
182182
" indices = np.empty((resamples, x0_len if is_paired else x0_len + x1_len), dtype=np.int64)\n",
@@ -213,7 +213,7 @@
213213
"\n",
214214
" return out\n",
215215
"\n",
216-
"@njit(cache=True, parallel=True)\n",
216+
"@njit(cache=True) # parallelization must be turned off for random number generation\n",
217217
"def delta2_bootstrap_loop(x1, x2, x3, x4, resamples, pooled_sd, rng_seed, is_paired):\n",
218218
" np.random.seed(rng_seed)\n",
219219
" out_delta_g = np.empty(resamples)\n",
@@ -324,7 +324,7 @@
324324
" return (100.0 - ci) / 100.0\n",
325325
"\n",
326326
"\n",
327-
"@njit(cache=True)\n",
327+
"# @njit(cache=True)\n",
328328
"def _compute_quantile(z, bias, acceleration):\n",
329329
" numer = bias + z\n",
330330
" denom = 1 - (acceleration * numer)\n",
@@ -365,37 +365,26 @@
365365
" return control_var / control_N + test_var / test_N\n",
366366
"\n",
367367
"\n",
368-
"@njit(cache=True)\n",
369368
"def calculate_weighted_delta(group_var, differences):\n",
370369
" \"\"\"\n",
371370
" Compute the weighted deltas.\n",
372371
" \"\"\"\n",
373372
"\n",
374373
" weight = 1 / group_var\n",
375374
" denom = np.sum(weight)\n",
376-
" num = np.sum(weight[i] * differences[i] for i in range(0, len(weight)))\n",
375+
" num = 0.0\n",
376+
" for i in range(len(weight)):\n",
377+
" num += weight[i] * differences[i]\n",
377378
"\n",
378379
" return num / denom"
379380
]
380-
},
381-
{
382-
"cell_type": "code",
383-
"execution_count": null,
384-
"id": "87e0c164",
385-
"metadata": {},
386-
"outputs": [],
387-
"source": []
388381
}
389382
],
390383
"metadata": {
391384
"kernelspec": {
392385
"display_name": "python3",
393386
"language": "python",
394387
"name": "python3"
395-
},
396-
"language_info": {
397-
"name": "python",
398-
"version": "3.11.8"
399388
}
400389
},
401390
"nbformat": 4,

nbs/API/effsize.ipynb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
"outputs": [],
289289
"source": [
290290
"#| export\n",
291-
"@njit(cache=True)\n",
291+
"# @njit(cache=True) # It uses np.seterr which is not supported by Numba\n",
292292
"def cohens_h(control:list|tuple|np.ndarray, \n",
293293
" test:list|tuple|np.ndarray\n",
294294
" )->float:\n",
@@ -383,7 +383,7 @@
383383
" U, _ = mannwhitneyu(t, c, alternative='two-sided') # Not supported by numba.\n",
384384
" cliffs_delta = ((2 * U) / (control_n * test_n)) - 1\n",
385385
"\n",
386-
" return cliffs_delta"
386+
" return cliffs_delta\n"
387387
]
388388
},
389389
{
@@ -510,10 +510,6 @@
510510
"display_name": "python3",
511511
"language": "python",
512512
"name": "python3"
513-
},
514-
"language_info": {
515-
"name": "python",
516-
"version": "3.11.8"
517513
}
518514
},
519515
"nbformat": 4,

nbs/API/effsize_objects.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@
923923
" for ix, tname in enumerate(current_tuple[1:]):\n",
924924
" if self.__is_paired == \"sequential\":\n",
925925
" cname = current_tuple[ix]\n",
926-
" control = grouped_data[tname]\n",
926+
" control = grouped_data[cname]\n",
927927
" test = grouped_data[tname]\n",
928928
"\n",
929929
" result = TwoGroupsEffectSize(\n",

0 commit comments

Comments
 (0)