Skip to main content

High-performance Causal Inference engine powered by Rust

Project description

CausalFlow

High-performance Causal Inference engine powered by Rust and LLM-friendly Python interfaces.

Overview

CausalFlow provides a state-of-the-art Causal Forest (Generalized Random Forest) implementation designed for speed, accuracy, and interpretability. By leveraging Rust for core computations and PyO3 for seamless Python integration, CausalFlow enables researchers and data scientists to estimate Heterogeneous Treatment Effects (ITE) on large-scale datasets with minimal overhead.

Key Features

  • 🦀 High-Performance Core: Implemented in Rust with zero-copy data access and Rayon-powered multi-threading.
  • 🌲 Generalized Random Forest (GRF): Robust splitting criteria maximizing treatment effect variance.
  • ⚖️ Honesty Property: Built-in data subsampling to ensure unbiased effect estimation and prevent overfitting.
  • 🤖 LLM-Friendly:
    • Structured Summaries: Automatic natural language interpretation of results.
    • ASCII Tables: Clean terminal outputs for easy digestion by AI agents.
    • Type Hints: Full .pyi support for IDEs and LLM tool calling.
  • 🛡️ Validation Guardrails: Built-in methods for causal robustness checks (cross-validation, time-series support).

Installation

Prerequisites

  • Rust toolchain (cargo, rustc)
  • Python 3.8+
  • maturin (for building from source)

1. Installation

# Clone the repository
git clone https://github.com/taka-data/CausalFlow
cd CausalFlow

# Set up environment and install
python3 -m venv .venv
source .venv/bin/activate
pip install maturin numpy pandas scikit-learn
maturin develop

Quick Start

import numpy as np
import causalflow as cf
from sklearn.datasets import fetch_california_housing

# Load data
data = fetch_california_housing()
X, Y = data.data, data.target
T = (X[:, 0] > X[:, 0].mean()).astype(float) # Dummy treatment

# 1. Create Model
model = cf.create_model(
    features=X, 
    treatment=T, 
    outcome=Y, 
    feature_names=list(data.feature_names)
)

# 2. Estimate Effects
results = model.estimate_effects(X)
print(results)  # Displays a structured summary table & interpretation

# 3. Headless Visualization (for LLM/Chat UI)
viz_data = cf.plot_model(model, plot='graph')
print(f"```json:causal-plot\n{viz_data}\n```")

# 4. Validate Robustness
validation = model.validate(n_folds=5)
print(validation.message)

Headless Visualization concept

CausalFlow follows a "Headless Visualization" architecture. The Python SDK doesn't generate images directly (like Matplotlib). Instead, it outputs strictly structured JSON data intended for a Custom ChatGPT-like UI. This ensures the best design consistency and zero hallucination of data by the LLM.

  • causalflow-core: Core Rust library for causal algorithms.
  • py-causalflow: Python bindings using PyO3.
  • causalflow-macros: Procedural macros for metadata generation.

Contributing

Please see CONTRIBUTING.md for details on our development workflow.

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

causalflow_rust-0.1.7.tar.gz (19.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

causalflow_rust-0.1.7-cp37-abi3-win_amd64.whl (294.0 kB view details)

Uploaded CPython 3.7+Windows x86-64

causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (486.4 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (473.1 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

causalflow_rust-0.1.7-cp37-abi3-macosx_11_0_arm64.whl (416.9 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

causalflow_rust-0.1.7-cp37-abi3-macosx_10_12_x86_64.whl (426.8 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file causalflow_rust-0.1.7.tar.gz.

File metadata

  • Download URL: causalflow_rust-0.1.7.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for causalflow_rust-0.1.7.tar.gz
Algorithm Hash digest
SHA256 f2bb374ce35985c5c215b4c711c527cb92b7fc3cd346e880a63debf49daa1f03
MD5 ca3184718e4c50a2ed3abfdb2a503660
BLAKE2b-256 ba527de3805b56f1383cbe95d7c2de254661eb1f227ec55ad5a60b95a8f0caad

See more details on using hashes here.

File details

Details for the file causalflow_rust-0.1.7-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for causalflow_rust-0.1.7-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f427b7b138c775d21bd5884e90e580296bac0cf78000f9dccc4984a681c94877
MD5 aef7bb7a06fcc8d487714a848784afa4
BLAKE2b-256 f7267ed4886c6d1ff49605afa1a9f37cad8eba3e8156a91ae58a4f5936d35438

See more details on using hashes here.

File details

Details for the file causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e7e410761105675803590ae65f19ce7b5ea4a25a13fdbf1af3fa8f666b7f0c0
MD5 dc3bf94f7288eb6803a33ea30fe05b0e
BLAKE2b-256 e3f479cded167becfb503aed4ac566c291461c0e19b72534b1e9046e4dbbdea6

See more details on using hashes here.

File details

Details for the file causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for causalflow_rust-0.1.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f1d49f7ffc4962d8088347e09e4ccc7ee295ca54fd1fd225d93cb6adc8ab777a
MD5 247364a685b5b729c79505ba487aec81
BLAKE2b-256 e702f2131dd15cb1fecb0972d7ab2ca43b98617117acfcfa570261a48b46ed27

See more details on using hashes here.

File details

Details for the file causalflow_rust-0.1.7-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for causalflow_rust-0.1.7-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 261d8ecb5649b597f97bda2aa7865b8f2ec12f7bba022f2ae6c79b8e9bdafa19
MD5 2130be6a1f87b0ed84b254bb8879b453
BLAKE2b-256 4ff1290a7cb0f618e75f1983aadff65a5c57bc6921ec1886a529420f732113ee

See more details on using hashes here.

File details

Details for the file causalflow_rust-0.1.7-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for causalflow_rust-0.1.7-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a7eeb902b59df69c371585ec8ba69023024969f405ca3d719e2458d6bd494405
MD5 a49319eb8f45c11e6029f15ba6f8b6b8
BLAKE2b-256 85d4af86f4597609dbea0039f6104ee913f0e25ad072068bbbed8d9c32e2e7ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page