PerturbClaw: Differential Attribution Aggregation Under Structural Uncertainty
1. Motivation
A recurring problem across many domains is measuring the relative importance of one feature within a large group, and then determining whether that localized feature influences its environment macroscopically. The question is not merely which features are important in aggregate, but whether a small component of a complex system — when perturbed — produces changes that propagate outward in meaningful ways. This kind of reasoning sits at the intersection of local attribution and global causal inference, and it is rarely addressed well by standard feature-importance pipelines.
PerturbClaw was directly inspired by work in determining the relative importance of transcription factor to gene relationships in gene regulatory networks. In that setting, the question is whether a single transcription factor, among hundreds of candidates, meaningfully changes its influence on a target gene between two biological conditions — for example, disease versus healthy tissue. But the underlying concept generalizes far beyond genomics: measuring the influence of a small component of a large group, and then testing whether changing that component has a broader macroscopic influence, has widespread potential across scientific disciplines.
Inspired by work from Dibaeinia et al. (2024) (referred to here also as CIMLA), PerturbClaw generalizes a methodology originally designed for gene-transcription factor attribution modeling and expands it to measure feature importance across a host of disciplines. Given data from two conditions (e.g. disease vs. control, treated vs. untreated), this workflow estimates perturbation-relevant feature influence between paired conditions using nonlinear predictive models and attribution aggregation. The workflow trains condition-specific predictive ensembles, computes feature-level attribution scores, and quantifies attribution divergence using stability-aware aggregation metrics.
Under the assumptions described in Dibaeinia et al. (2024), attribution differences approximate graph-marginalized proxies for condition-specific local treatment effects and provide an interpretable estimate of perturbation-relevant feature influence beyond purely correlational importance scores.
Concrete domains where this question arises include:
- Genomics: regulatory influence may differ between disease and control conditions; identifying which transcription factors changed their influence on target genes is a core unsolved problem
- Neuroscience: stimulus conditions may alter which features of neural activity are most relevant to a behavioral outcome
- Climate modeling: relationships between atmospheric variables and regional outcomes shift across eras, and identifying which variables changed their predictive role is essential for attribution
- Materials science: processing conditions change which material properties most strongly predict performance outcomes
Static feature-importance pipelines are often insufficient for all of these settings. They may ignore nonlinear response structure, and they do not provide a stable summary of how local attributions diverge between conditions. A method that ranks features by their raw importance in a single model cannot distinguish genuine condition-driven changes from spurious differences driven by confounding or model instability.
PerturbClaw addresses this gap by packaging a reproducible workflow that separates predictive modeling, attribution estimation, and attribution aggregation into explicit stages that can be executed by agents and adapted across domains. PerturbClaw implements a domain-independent workflow template for estimating perturbation-relevant feature influence under partially observed causal structure. The workflow separates these stages into independent reproducible components, allowing substitution of model classes, attribution methods, and aggregation metrics across scientific domains.
The current reference implementation uses the CIMLA Python package as a backend for predictive modeling and attribution computation; however, the PerturbClaw workflow abstraction is independent of this implementation choice and supports alternative predictive estimators and attribution operators. PerturbClaw supports both single-target execution and scalable multi-target batch workflows through configuration-driven automation.
2. Method
Attribution grounding
Let be input features and be the target output. Under the assumptions described in Dibaeinia et al. (2024), local SHAP values can be interpreted as graph-marginalized proxies for condition-specific local treatment effects. This motivates comparing feature-level attributions between two condition-specific predictive models evaluated on a shared set of samples.
For feature and target , define a condition-specific local treatment effect proxy at state as:
{t,g}(\mathbf{x}) = E!\left[Y_g \mid \mathrm{do}(X_t = x_t),, \mathrm{do}(\mathbf{X}{-t} = \mathbf{x}{-t})\right] - E!\left[Y_g \mid \mathrm{do}(X_t = \hat{x}t),, \mathrm{do}(\mathbf{X}{-t} = \mathbf{x}{-t})\right]
The reference implementation follows the theorem of Dibaeinia et al. (2024), under which the SHAP value approximates a graph-marginalized, baseline-averaged proxy:
t,,\psi}!\left[\mathrm{LTE}{t,g}(\mathbf{x},, \hat{x}_t,, \psi)\right]
This interpretation is approximate and assumption-dependent, but it provides a useful scientific rationale for comparing attribution structure between conditions.
The PerturbClaw workflow
PerturbClaw implements a domain-independent workflow template for estimating perturbation-relevant feature influence under partially observed causal structure. The workflow separates predictive modeling, attribution estimation, and attribution aggregation into independent reproducible stages, allowing substitution of model classes, attribution methods, and aggregation metrics across scientific domains.
The current reference implementation uses the CIMLA python package as a backend for predictive modeling and attribution computation; however, the PerturbClaw workflow abstraction is independent of this implementation choice and supports alternative predictive estimators and attribution operators. PerturbClaw supports both single-target execution and scalable multi-target batch workflows through configuration-driven automation.
The workflow follows a five-stage pipeline:
predict → attribute → aggregate → compare → rank
Step 1 — Predict. Paired-condition matrices are loaded, normalized, and split into train/test sets. If a target variable also appears as an input, its column is permuted to avoid leakage.
Step 2 — Attribute. Two independent nonlinear models are trained: on condition 0 and on condition 1. The package currently exposes Random Forest and Neural Network variants through the CIMLA backend.
Step 3 — Aggregate. Both models are evaluated on the same attribution dataset. For RF, TreeSHAP is used; for NN, DeepSHAP is used. The workflow then compares attribution vectors feature-by-feature between the two condition-specific models on the shared evaluation samples.
Step 4 — Compare. The reference aggregation metric is the RMS attribution divergence statistic (RAD) for feature and target :
{t,g} = \sqrt{\frac{1}{|X|}\sum{\mathbf{x} \in X}!\left[\phi_t(f_1, \mathbf{x}) - \phi_t(f_0, \mathbf{x})\right]^2}
Using RMS aggregation rather than a signed mean prevents heterogeneous local changes from cancelling out.
Step 5 — Rank. Features are ranked by for downstream interpretation and follow-up analysis.
3. Skill Design and Executability
The SKILL.md is structured as an agent-executable workflow with explicit commands, expected outputs, and validation steps:
- Install dependencies and create the conda environment
- Prepare paired-condition CSV inputs and a target definition
- Configure a YAML file for RF or NN execution
- Run the backend command
cimla --config config.yaml - Verify outputs with
python verify_output.pyand rank features by
This design aligns with the Claw4S review emphasis on executability, reproducibility, and clarity for agents. The package includes a lightweight example run, a verification script, and a synthetic batch workflow for submission-safe demonstrations.
The current executable backend is inherited from the upstream CIMLA package. For submission accuracy, the package documents the validated backend stack as Python 3.8.12 with the legacy CIMLA dependency set, rather than claiming a modernized environment that has not been verified.
Example run
The run_example.sh script executes the full PerturbClaw workflow on the provided example data end-to-end:
conda activate perturbclaw_env
bash run_example.sh
python verify_output.pyThe script checks that the conda environment is active, verifies the CIMLA backend is installed, confirms all four required input files are present, runs cimla --config config_templates/config_rf.yaml, and prints the top features ranked by RMS attribution divergence statistic. Expected output files in example_results/:
global_feature_importance.csv # RAD scores — one per input feature
performance_group1.csv # R2/MSE on train and test, condition 0
performance_group2.csv # R2/MSE on train and test, condition 1A well-fit model should have on the test set. If is near zero for both conditions, the target may not be predictable from these features and results should be interpreted cautiously.
Synthetic batch workflow
For submission-safe demonstrations without real identifiers or real measurements, the package includes a fully synthetic workflow:
bash run_synthetic_pipeline.shThis path uses only synthetic entity names (TF001...TF200, GENE001...GENE200) and synthetic measurements. The generator can be tuned via environment variables:
N_TF=200 N_GENE=200 N_G1=500 N_G2=500 SEED=7 \
./scripts/generate_synthetic_perturbclaw_inputs.shDefault synthetic dataset parameters:
- 200 synthetic features (
TF001...TF200) - 200 synthetic targets (
GENE001...GENE200) - 600 samples in condition 0
- 800 samples in condition 1
The synthetic_batch/ directory is fully regenerable from the scripts if a reviewer wants a clean fresh run.
4. Validated Backend Environment
The reference backend in this package is the upstream CIMLA implementation and inherits its dependency constraints. This package has been reconciled to the working backend environment inspected from a successful installation:
| Package | Version |
|---|---|
| Python | 3.8.12 |
| tensorflow | 2.2.0 |
| scikit-learn | 0.24.2 |
| shap | 0.39.0 |
| pandas | 1.3.3 |
| xgboost | 1.5.0 |
Validated execution is currently tied to the legacy CIMLA stack. The inspected working environment is Linux-based. Apple Silicon (osx-arm64) support is not claimed by this package and may require Docker, x86 emulation, or upstream maintenance by the original CIMLA authors.
5. Generalizability
PerturbClaw is explicitly framed as a domain-general workflow abstraction. Although the current backend is derived from a genomics-motivated method, the workflow itself requires only paired conditions, tabular predictors, a continuous outcome, and an attribution-capable predictive model.
The package documents how to substitute any such dataset and highlights several application classes:
- Drug response: condition 0 = untreated cells, condition 1 = drug-treated; features = protein levels; target = cell viability
- Climate science: condition 0 = pre-2000 climate, condition 1 = post-2000; features = atmospheric variables; target = regional temperature
- Economics: condition 0 = pre-policy period, condition 1 = post-policy; features = economic indicators; target = unemployment rate
- Neuroscience: condition 0 = baseline stimulus, condition 1 = active stimulus; features = neural firing rates; target = behavioral outcome
- Materials science: condition 0 = standard processing, condition 1 = modified processing; features = material properties; target = yield strength
The core question — which features differ most in attributional influence between two conditions? — is domain-agnostic, and provides a portable aggregation target for that question.
6. Evidence and Positioning
The reference implementation is grounded in the empirical results reported by Dibaeinia et al. (2024), where the underlying method was evaluated on synthetic and real biological datasets. On synthetic scRNA-seq data generated by the SERGIO simulator with known ground-truth regulatory networks, the method outperforms all competing approaches (GENIE3-diff, BoostDiff, DoubleML-diff, co-expression baselines) in both AUROC and AUPRC. The advantage is largest in the high-confounding condition, where competing methods degrade substantially while the attribution-based approach maintains high performance.
PerturbClaw does not claim to replace those experiments; instead, it turns the methodological pattern into an executable, reusable workflow suitable for CLAW-style review and adaptation across domains.
For this submission package, emphasis is placed on:
- Executable reproducibility of the workflow
- Portability through synthetic paired-condition data
- Clarity of the predict–attribute–aggregate–compare–rank decomposition
- Faithful documentation of the validated dependency stack
7. Limitations
The workflow should not be interpreted as exact causal identification. The attribution differences are assumption-dependent proxies, and latent confounding or model misspecification can distort them. Specifically:
- averages the LTE over all allowed causal diagrams, including unrealistic ones — making it a statistical proxy rather than the true causal effect in the underlying network. Selecting attribution data strategically — for example, by restricting to matched samples, homogeneous subpopulations, or time-aligned observations — can reduce the influence of latent confounders and improve the interpretability of RAD scores across domains.
- Latent confounders such as unmeasured cell type composition are not fully removed by the intervention on observed features
- SHAP-based attribution is computationally expensive for large feature sets; sampling and batching strategies are important in practice
There is also an implementation-level limitation: the reference backend depends on a legacy Python 3.8.12 stack and has been validated in a Linux environment. Cross-platform support, especially on Apple Silicon, should be treated as a separate engineering problem rather than assumed from the current package.
References
- Dibaeinia P., Ojha A., Sinha S. (2024). Interpretable AI for inference of causal molecular relationships from omics data. Science Advances, 11(7), eadk0837.
- Pearl, J. (2009). Causality: Models, Reasoning, and Inference. Cambridge University Press.
- Lundberg, S.M. & Lee, S.I. (2017). A unified approach to interpreting model predictions. NeurIPS.
- Lundberg, S.M. et al. (2020). From local explanations to global understanding with explainable AI for trees. Nature Machine Intelligence (TreeSHAP).
- Dibaeinia P. & Sinha S. (2020). SERGIO: a single-cell expression simulator guided by gene regulatory networks. Cell Systems.
Reproducibility: Skill File
The full SKILL.md for this submission is included in the package. Key execution commands:
# Set up environment
conda env create -f environment.yml
conda activate perturbclaw_env
# Install backend
pip install CIMLA
# Run example
bash run_example.sh
# Verify outputs
python verify_output.py
# Run synthetic batch workflow
bash run_synthetic_pipeline.shAll commands are run from the submission directory. No API keys or GPU are required for the RF backend. The synthetic workflow is the recommended demonstration path for external review as it avoids real identifiers and preserves package portability.
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
# PerturbClaw: Differential Attribution Aggregation Under Structural Uncertainty
Inspired by work from Dibaeinia et al. (2024) (referred to here also as CIMLA), PerturbClaw generalizes a methodology
meant for gene-transcription factor attribution modeling and expands it to measure
feature importance in a host of disciplines. Given data from two conditions
(e.g. disease vs. control, treated vs. untreated), this workflow estimates perturbation-relevant
feature influence between paired
conditions using nonlinear predictive models and attribution aggregation. The
workflow trains condition-specific predictive ensembles, computes feature-level
attribution scores, and quantifies attribution divergence using stability-aware
aggregation metrics.
Under the assumptions described in Dibaeinia et al. (2024), attribution differences approximate graph-marginalized proxies for
condition-specific local treatment effects and provide an interpretable estimate of perturbation-relevant feature influence
beyond purely correlational importance scores.
## Workflow abstraction
PerturbClaw implements a domain-independent workflow template for estimating
perturbation-relevant feature influence under partially observed causal structure.
The workflow separates predictive modeling, attribution estimation, and attribution
aggregation into independent reproducible stages, allowing substitution of model
classes, attribution methods, and aggregation metrics across scientific domains.
The current reference implementation uses the CIMLA python package as a backend
for predictive modeling and attribution computation; however, the PerturbClaw
workflow abstraction is independent of this implementation choice and supports
alternative predictive estimators and attribution operators. PerturbClaw supports both
single-target execution and scalable multi-target batch workflows through
configuration-driven automation.
## Workflow stages
The workflow follows a five-stage structure:
predict → attribute → aggregate → compare → rank
PerturbClaw applies to any tabular dataset containing paired conditions and a
continuous outcome variable, including applications in genomics, neuroscience,
climate modeling, and materials science.
---
## Validated backend environment
The current reference implementation depends on the upstream CIMLA package and
therefore inherits its legacy backend constraints. This skill is validated
against an inspected working backend environment with Python `3.8.12`,
`tensorflow==2.2.0`, `scikit-learn==0.24.2`, `shap==0.39.0`,
`pandas==1.3.3`, and `xgboost==1.5.0`.
The inspected working backend environment is Linux-based. Apple Silicon support
is not claimed in this submission package. On `osx-arm64`, execution may require
Docker, x86 emulation, or upstream maintenance by the original CIMLA authors.
## Prerequisites
### Step 0 -- Set up environment
```bash
# Create and activate conda environment
conda env create -f environment.yml
conda activate perturbclaw_env
# Install the CIMLA backend, making sure the legacy packages are correct
pip install CIMLA
# Verify installation
python -c "import CIMLA; print('CIMLA installed successfully')"
```
---
## Input data format
Four CSV files are required:
| File | Description | Shape |
|------|-------------|-------|
| `condition0_data.csv` | Feature matrix, condition 0 (control) | cells x features |
| `condition1_data.csv` | Feature matrix, condition 1 (case) | cells x features |
| `features.csv` | Input feature names, one per row | m x 1 |
| `target.csv` | Target output variable name | 1 x 1 |
Requirements:
- All values must be numeric
- Both condition files must have identical column names
- The target variable column must appear in both condition files
- No missing values -- impute before running
The workflow assumes both condition matrices share identical feature columns and differ only in sample membership.
To test immediately with provided example data, skip to Step 1 --
example CSVs are already in `example_data/`.
---
## Step 1 -- Configure your YAML file
Two templates are provided in `config_templates/`. Choose based on your ML backend.
### Option A: Random Forest (recommended -- no GPU required)
Copy and edit `config_templates/config_rf.yaml`:
```yaml
data:
group1: path/to/condition0_data.csv
group2: path/to/condition1_data.csv
independent: path/to/features.csv
dependent: path/to/target.csv
normalize: true
test_size: 0.2
random_state: 42
ML:
type: RF
n_estimators: [100, 200]
max_depth: [3, 5, null]
max_features: [0.3, 0.5]
min_samples_leaf: [1, 5]
max_leaf_nodes: [null]
attribution:
type: tree_shap
attr_data_group: group2
attr_data_size: null
aggregation:
global_type: RMSD
output:
dir: results/
save_local: false
save_models: true
performance_metric: R2
```
### Option B: Neural Network (GPU recommended for large datasets)
Create `config_nn.yaml`:
```yaml
data:
group1: path/to/condition0_data.csv
group2: path/to/condition1_data.csv
independent: path/to/features.csv
dependent: path/to/target.csv
normalize: true
test_size: 0.2
random_state: 42
ML:
type: MLP
hidden_units: [64, 32]
dropout: 0.2
l2: 0.001
epochs: 100
batch_size: 128
learning_rate: 0.001
attribution:
type: deep_shap
attr_data_group: group2
attr_data_size: null
background_size: 1000
aggregation:
global_type: RMSD
output:
dir: results/
save_local: false
save_models: true
performance_metric: R2
```
---
## Step 2 -- Run the PerturbClaw differential attribution workflow on a single target
```bash
cimla --config config.yaml
```
To run the provided example end-to-end:
```bash
bash run_example.sh
```
Expected output files in `results/` (or `example_results/` for the example run):
```
global_feature_importance.csv # RMS attribution divergence statistics -- one per input feature
model_group1.joblib # trained model for condition 0
model_group2.joblib # trained model for condition 1
performance_group1.csv # R2/MSE on train and test, condition 0
performance_group2.csv # R2/MSE on train and test, condition 1
```
Validate model quality after running:
```python
import pandas as pd
for g in ["group1", "group2"]:
perf = pd.read_csv(f"results/performance_{g}.csv")
print(f"{g}:", perf)
```
A well-fit model should have R2 > 0.3 on the test set. If R2 is near zero for both
conditions, the target may not be predictable from these features -- interpret
results cautiously.
---
## Step 3 -- Run across multiple targets
The underlying CIMLA engine processes one target at a time. Use this driver script to loop over many:
```bash
#!/bin/bash
# Usage: bash run_all_targets.sh targets.txt config_template.yaml results_dir/
TARGETS=$1
CONFIG_TEMPLATE=$2
RESULTS_DIR=$3
mkdir -p "$RESULTS_DIR"
while IFS= read -r target; do
echo "Processing: $target"
sed "s/TARGET_PLACEHOLDER/$target/" "$CONFIG_TEMPLATE" > tmp_config_$target.yaml
sed -i "s|results/|$RESULTS_DIR/$target/|" tmp_config_$target.yaml
cimla --config tmp_config_$target.yaml
rm tmp_config_$target.yaml
done < "$TARGETS"
echo "Done. Results in $RESULTS_DIR"
```
In your config template set `dependent: TARGET_PLACEHOLDER` -- the script substitutes
the actual target name on each iteration.
---
## Step 4 -- Rank and interpret results
```python
import pandas as pd
import os
results_dir = "results/"
# Aggregate scores across multiple targets
all_scores = []
for target in os.listdir(results_dir):
score_file = os.path.join(results_dir, target,
"global_feature_importance.csv")
if os.path.exists(score_file):
scores = pd.read_csv(score_file)
scores["target"] = target
all_scores.append(scores)
combined = pd.concat(all_scores, ignore_index=True)
mean_scores = combined.drop(columns="target").mean().sort_values(ascending=False)
print("Top 10 features by mean RMS attribution divergence statistic:")
print(mean_scores.head(10))
mean_scores.to_csv("ranked_features.csv", header=["mean_rms_attribution_divergence_statistic"])
```
Interpreting scores:
- High RMS attribution divergence statistic = feature's attributional influence changed substantially between conditions
- This is a proxy for causal regulatory change (alpha_{t,g}), not direct proof
- High-scoring features are candidates for follow-up experimental validation
---
## Step 5 -- Ensemble RF and NN scores (MeanRank, optional)
For more robust results, run both backends and combine rankings:
```python
import pandas as pd
rf = pd.read_csv("results_rf/global_feature_importance.csv").T
nn = pd.read_csv("results_nn/global_feature_importance.csv").T
rf.columns = ["rf_score"]
nn.columns = ["nn_score"]
rf["rf_rank"] = rf["rf_score"].rank(ascending=False)
nn["nn_rank"] = nn["nn_score"].rank(ascending=False)
combined = rf.join(nn)
combined["mean_rank"] = (combined["rf_rank"] + combined["nn_rank"]) / 2
combined = combined.sort_values("mean_rank")
print("Top features by MeanRank ensemble:")
print(combined.head(10))
combined.to_csv("ensemble_ranked_features.csv")
```
---
## Troubleshooting
| Problem | Likely cause | Fix |
|---------|-------------|-----|
| R2 near zero for both models | Target not predictable from features | Check data quality; verify correct files used |
| SHAP computation very slow | Too many cells or features | Set `attr_data_size: 500` to subsample |
| DeepSHAP memory error | Dataset too large | Switch to RF + TreeSHAP, or enable `cache: true` for HDF5 batching |
| All RMS attribution divergence statistics near zero | Models identical between conditions | Verify conditions are genuinely different |
| ImportError on CIMLA | Package not installed | Run `pip install CIMLA` |
---
## Adapting to new domains
This workflow is domain-independent. Replace the input CSVs with your own
two-condition tabular data and run Steps 1-4 identically. Example applications:
- Drug response: condition 0 = untreated, condition 1 = treated; features = protein
levels; target = cell viability
- Climate science: condition 0 = pre-2000, condition 1 = post-2000; features =
atmospheric variables; target = regional temperature
- Economics: condition 0 = pre-policy, condition 1 = post-policy; features =
economic indicators; target = unemployment rate
---
## Shareable synthetic mode (added)
Synthetic mode enables deterministic execution suitable for automated workflow validation and agent-based benchmarking.
This integrated package now includes a fully synthetic workflow for conference/demo use:
- Synthetic TF list and gene list (`synthetic_data/`)
- Synthetic two-condition expression matrices (`synthetic_data/`)
- Batch config generation scripts (`scripts/`)
- End-to-end synthetic runner (`run_synthetic_pipeline.sh`)
Use this mode when sharing the package externally and you need a reproducible run without real identifiers or real measurements.