Coder Social home page Coder Social logo

loci's Introduction

arXiv Venue

Code for Location-Scale Causal Inference (LOCI) estimator for bivariate causal model identification

Setup

Requires python>=3.8. Install dependencies with

pip install -r requirements.txt

Example Usage

To use the LOCI estimator on some pair x, y in the default setting (with neural network and subsequent independence test) use it like

from causa.loci import loci
score = loci(x, y)
# The score is such that score > 0 indicates x -> y and score < 0 indicates y -> x.
print(score)

To use LOCI with a particular dataset provided in this repository and also plot the estimator fit and scaled residuals that are used for the independence test, the following snippet might be helpful:

from sklearn.preprocessing import StandardScaler
from causa.loci import loci
from causa.datasets import MNU
from causa.utils import plot_pair

# We use the MNU pair 55 as an example and standardize the data
dataset = MNU(55, preprocessor=StandardScaler(), double=True)
x, y = dataset.cause.flatten().numpy(), dataset.effect.flatten().numpy()

# This function call shows all options of LOCI, we return_function to visualize the estimator
score, f_forward, f_reverse = loci(
    x, y, independence_test=True, neural_network=True, 
    return_function=True, n_steps=5000
)
plot_pair(x, y, f_forward, f_reverse)

MNU_False MNU_True

Reproduce All Results

First, create all necessary commands to be executed with

python commands/jobs_generate.py > commands/jobs.sh
python commands/jobs_estimator_generate.py > commands/jobs_estimator.sh

Create the result directory mkdir results. All commands written to commands/jobs.sh and commands/jobs_estimator.sh need to be executed and can be run entirely in parallel. The results will be written to results/.

Run Individual Experiments

Instead of re-running the entire set of jobs, one can run individual causal pair benchmark pairs as follows

python run_individual.py --pair_id PAIR_ID --config configs/ANs_standardized.gin

The results will be printed after the run.

To run an individual estimator benchmark case, run

python run_estimator_benchmark.py --seed SEED --knot_heuristic {sqrt|lin}

Produce Figures and Tables

First, create a directory to store the figure PDFs with mkdir paper_figures. Then run

python generate_figures_and_tables.py

The resulting figures will be saved to the created directory. The overall latex result tables are printed to the command line output.

Repository structure

├── causa  
│   ├── datasets.py  # bivariate causal data sets loaded from /data
│   ├── het_ridge.py  # implementation of our convex LSNM estimator
│   ├── hsic.py  # independence test
│   ├── iterative_fgls.py  # baseline LSNM estimator
│   ├── ml.py  # neural network estimators
│   └── utils.py  # neural network utilities
├── commands
│   ├── jobs_estimator_generate.py  # generate bash commands for estimator benchmark
│   └── jobs_generate.py  # generate bash commands for causal pairs
├── configs  # configs for causal pairs
├── baseline_results  # results for baseline methods (GRCI, QCCD, etc.)
├── data  # data sets
├── requirements.txt  # pip requirements
├── run_estimator_benchmark.py  # estimator benchmark script
├── run_individual.py  # causal pair benchmark script
└── generate_figures_and_tables.py  # create PDF figures and print tex tables

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.