Skip to content

Commit eb6bd6f

Browse files
committed
ccc: select variable with more partitions for permutation
1 parent d2f0573 commit eb6bd6f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

libs/ccc/coef/impl.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -544,21 +544,30 @@ def compute_coef(idx_list):
544544
if pvalue_n_permutations is not None and pvalue_n_permutations > 0:
545545
# compute CCC on permuted data
546546
p_ccc_values = np.full(pvalue_n_permutations, np.nan, dtype=float)
547+
548+
# select the variable that generated more partitions as the one
549+
# to permute
550+
obj_parts_sel_i = obji_parts
551+
obj_parts_sel_j = objj_parts
552+
if (obji_parts[:, 0] >= 0).sum() > (objj_parts[:, 0] >= 0).sum():
553+
obj_parts_sel_i = objj_parts
554+
obj_parts_sel_j = obji_parts
555+
547556
for idx_perm in range(pvalue_n_permutations):
548557
# generate a random permutation of the partitions of one
549558
# variable/feature
550559
perm_idx = np.random.permutation(n_objects)
551-
objj_parts_permuted = np.array(
560+
obj_parts_sel_j_permuted = np.array(
552561
[
553-
objj_parts[i, perm_idx]
554-
for i in range(objj_parts.shape[0])
562+
obj_parts_sel_j[i, perm_idx]
563+
for i in range(obj_parts_sel_j.shape[0])
555564
]
556565
)
557566

558567
# compute the CCC using the permuted partitions
559568
p_comp_values = cdist_func(
560-
obji_parts,
561-
objj_parts_permuted,
569+
obj_parts_sel_i,
570+
obj_parts_sel_j_permuted,
562571
)
563572
p_max_flat_idx = p_comp_values.argmax()
564573
p_max_idx = unravel_index_2d(

0 commit comments

Comments
 (0)