The iscan-dag library is a Python 3 package designed for the direct detection of shifted nodes and structural shifted edges across multiple DAGs originating from distinct environments.
iSCAN-dag operates through a systematic process:
- It initially calculates the derivatives of the score function, a key step in identifying the leaf nodes for all environments.
- Subsequently, it computes the derivative of the score function from the mixture distribution, then evaluating the variance of these derivatives. If the variance exceeds a threshold of zero, it designates these leaf nodes as shifted nodes.
This process is iteratively applied, eliminating the identified leaf nodes across all environments and repeating the procedure to uncover all shifted nodes.
To detect structural shifted edges, the library leverages the by-products of the prior steps, the topological order. It employs FOCI to identify discrepancies in parental relationships.
Citation
This is an implementation of the following paper:
[1] Chen T., Bello K., Aragam B., Ravikumar P. (2023). "iSCAN: Identifying Causal Mechanism Shifts among Nonlinear Additive Noise Models".
If you find this code useful, please consider citing:
BibTeX
@article{chen2023iscan,
author = {Chen, Tianyu and Bello, Kevin and Aragam, Bryon and Ravikumar, Pradeep},
journal = {ArXiv Preprint 2306.17361},
title = {{iSCAN: Identifying Causal Mechanism Shifts among Nonlinear Additive Noise Models}},
year = {2023}
}
Features
- Detecting shifted nodes without the need for separate DAG estimations.
- Accommodates any score estimators that can seamlessly integrate into this versatile framework.
- Unlike DCI and UT-IGSP, iSCAN's time complexity is not influenced by graph density and runs faster in larger networks due to its omission of non-parametric conditional independence tests.
Getting Started
Install the package
We recommend using a virtual environment via virtualenv or conda, and use pip to install the iscan-dag package.
$ pip install -U iscan-dag
Using iSCAN
See an example on how to use iSCAN in this iPython notebook.
An Overview of iSCAN
We propose a new method of identifying changes (shifts) in causal mechanisms between related Structure causal models (SCMs) directly, without recovering the entire underlying DAG structure. This paper focuses on identifying mechanism shifts in two or more related SCMs over the same set of variables---without estimating the entire DAG structure of each SCM. Prior work under this setting assumed linear models with Gaussian noises; instead, in this work we assume that each SCM belongs to the more general class of nonlinear additive noise models (ANMs). We prove a surprising result where the Jacobian of the score function for the mixture distribution reveals information about shifts in general non-parametric functional mechanisms. Once the shifted variables are identified, we leverage recent work to estimate the structural differences (if any) for the shifted variables. The advantages of our method is it is easy to understand and implement, lead to significant improvement in identifying shifted nodes (e.g F1, Recall, Precision).
Identifying the shifted leaf nodes
Let $h$ be the index of the environment, and $p^h(x)$ denote the pdf of the $h$-th environment. Let $q(x)$ be the pdf of the mixture distribution of the all $H$ environments such that $q(x) = \sum_h w_h p^h(x)$. Also, let $s(x) = \nabla \log q(x)$ be the associated score function. Then, under with nonlinear assumption and additive noise assumption, we have:
\begin{array}{cl}
(i) \text{ If } j \text{ is a leaf in all DAGs } G^h, \text{ then } j \text{ is a shifted node if and only if } \text{Var}_X\left[ \frac{\partial s_j(X)}{\partial x_j} \right] > 0\\
(ii) \text{ If } j \text{ is not a leaf in at least one DAG } G^h, \text{ then } \text{Var}_X\left[ \frac{\partial s_j(X)}{\partial x_j} \right] > 0
\end{array}
Identifying the shifted edges
By utilizing a common estimated topological order across all environments, individuals can customize their definition of functional shifted edges and apply any available (non)parametric statistical technique to identify these edges based on the detected shifted nodes. This approach can significantly expedite the process, particularly when the occurrence of shifted nodes is sparse, obviating the need for exhaustive edge comparisons across all nodes and environments.
Regarding structural shifted edges, we have established a connection between FOCI and our method, enabling the detection of such edges with a time complexity of $\mathcal{O}(n\log n)$.
Requirements
- Python 3.6+
numpyigraphtorch
Contents
score_estimator.py: Estimates the diagonal of the Hessian of $\log p(x)$ at the provided samples points.utils.pyset_seed: Manually sets the random seed.node_metrics,ddag_metrics: Metrics for identifying shifted nodes and structural shifted edges.DataGenerator: Generates data for testing purposes.
shifted_nodes.py: Implements iSCAN, providing detected shifted nodes and test cases.shifted_edges.py: Implements the discovery of structural shifted edges using FOCI, along with test cases.my_foci.R: Implements FOCI for finding parents based on given nodes and topological order.
Acknowledgements
We thank the authors of the SCORE for making their code available. Part of our code is based on their implementation, specially the score_estimator.py file.
Metadata
Release files for iscan-dag 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iscan-dag-0.0.4.tar.gz | 18.6 kB | Without provenance | Details for iscan-dag-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iscan_dag-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for iscan_dag-0.0.4-py3-none-any.whl |
Total release size: 35.7 kB
Release files / iscan-dag-0.0.4.tar.gz
| Download URL | iscan-dag-0.0.4.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44e9dbc7d80880af623b878a28de26665ddc87b0140984c7844e13275de08626
|
|
BLAKE2b-256 checksum How to use checksums |
180b18a056ac8ef41c9e329fc6d305c2a3461cb42ee452ea83fb6ac5b8eabda6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / iscan_dag-0.0.4-py3-none-any.whl
| Download URL | iscan_dag-0.0.4-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd794da999bbbb62761b40bd3682dba8a60cd5d7e90dd5fa56b9167202e3688f
|
|
BLAKE2b-256 checksum How to use checksums |
2f5eb868fe40c670d5358a594c22d95d8310d30721e65098169c056fc11dd7b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for iscan-dag 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.