Skip to content

Commit 36b0829

Browse files
authored
Merge pull request #178 from svenpieper/fast_pruning_varlingam
updating pruning func for varlingam for faster processing
2 parents e1e2a6f + 0ac09dc commit 36b0829

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

causallearn/search/FCMBased/lingam/var_lingam.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,14 @@ def _pruning(self, X, B_taus, causal_order):
319319
obj = np.zeros((len(blocks)))
320320
exp = np.zeros(
321321
(len(blocks), causal_order_no + n_features * self._lags))
322-
for j, block in enumerate(blocks):
323-
obj[j] = block[0][i]
324-
exp[j:] = np.concatenate(
325-
[block[0][ancestor_indexes].flatten(), block[1:][:].flatten()], axis=0)
322+
323+
# Create 3D array to hold flattened ancestor indices for each block
324+
ancestor_indexes_flat = blocks[:, 0, ancestor_indexes].reshape(len(blocks), -1)
325+
# Fill obj using advanced indexing
326+
obj[:] = blocks[:, 0, i]
327+
# Fill exp using advanced indexing
328+
exp[:, :causal_order_no] = ancestor_indexes_flat
329+
exp[:, causal_order_no:] = blocks[:, 1:].reshape(len(blocks), -1)
326330

327331
# adaptive lasso
328332
gamma = 1.0

0 commit comments

Comments
 (0)