causalcompass.algorithms.CLSTM

class causalcompass.algorithms.CLSTM(context=10, hidden_dim=100, lam=0.005, lr=0.01, max_iter=20000, lam_ridge=1e-2, device='cuda', seed=None)[source]

Deep learning-based causal discovery method that uses component-wise LSTMs to model nonlinear Granger causality.

References

https://github.com/iancovert/Neural-GC

Parameters:
  • context (int, default 10) – Context window length

  • hidden_dim (int, default 100) – Number of units in LSTM cell

  • lam (float, default 0.005) – Sparsity penalty term parameter

  • lr (float, default 0.01) – Learning rate

  • max_iter (int, default 20000) – Maximum training iterations

  • lam_ridge (float, default 1e-2) – Ridge regularization parameter

  • device (str, default 'cuda') – Computation device

Examples

>>> from causalcompass.algorithms import CLSTM
>>> model = CLSTM(context=10, hidden_dim=100, lam=0.005, lr=0.01, max_iter=20000, device='cuda')
>>> predicted_adj = model.run(X)
>>> all_metrics, no_diag_metrics = model.eval(true_adj, predicted_adj)
__init__(context=10, hidden_dim=100, lam=0.005, lr=0.01, max_iter=20000, lam_ridge=1e-2, device='cuda', seed=None)[source]

Initialize cLSTM

Methods

__init__([context, hidden_dim, lam, lr, ...])

Initialize cLSTM

eval(true_adj, predicted_adj[, shd_thresholds])

Evaluate the predicted adjacency matrix against the ground truth.

run(X)

Run cLSTM algorithm.

run_raw(X, **kwargs)

Run the algorithm and return an unthresholded intermediate result that can be reused across multiple threshold values.

run_threshold_sweep(X, thresholds)

Run the algorithm once and post-process the raw result for each threshold.