Metadata-Version: 2.4
Name: coreason_inference
Version: 0.1.0
Summary: coreason-inference
License: # The Prosperity Public License 3.0.0
         
         Contributor: CoReason, Inc.
         
         Source Code: https://github.com/CoReason-AI/coreason_inference
         
         ## Purpose
         
         This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.
         
         ## Agreement
         
         In order to receive this license, you have to agree to its rules.  Those rules are both obligations under that agreement and conditions to your license.  Don't do anything with this software that triggers a rule you can't or won't follow.
         
         ## Notices
         
         Make sure everyone who gets a copy of any part of this software from you, with or without changes, also gets the text of this license and the contributor and source code lines above.
         
         ## Commercial Trial
         
         Limit your use of this software for commercial purposes to a thirty-day trial period.  If you use this software for work, your company gets one trial period for all personnel, not one trial per person.
         
         ## Contributions Back
         
         Developing feedback, changes, or additions that you contribute back to the contributor on the terms of a standardized public software license such as [the Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0), [the Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html), [the MIT license](https://spdx.org/licenses/MIT.html), or [the two-clause BSD license](https://spdx.org/licenses/BSD-2-Clause.html) doesn't count as use for a commercial purpose.
         
         ## Personal Uses
         
         Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn't count as use for a commercial purpose.
         
         ## Noncommercial Organizations
         
         Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution doesn't count as use for a commercial purpose regardless of the source of funding or obligations resulting from the funding.
         
         ## Defense
         
         Don't make any legal claim against anyone accusing this software, with or without changes, alone or with other technology, of infringing any patent.
         
         ## Copyright
         
         The contributor licenses you to do everything with this software that would otherwise infringe their copyright in it.
         
         ## Patent
         
         The contributor licenses you to do everything with this software that would otherwise infringe any patents they can license or become able to license.
         
         ## Reliability
         
         The contributor can't revoke this license.
         
         ## Excuse
         
         You're excused for unknowingly breaking [Notices](#notices) if you take all practical steps to comply within thirty days of learning you broke the rule.
         
         ## No Liability
         
         ***As far as the law allows, this software comes as is, without any warranty or condition, and the contributor won't be liable to anyone for any damages related to this software or this license, under any kind of legal claim.***
License-File: LICENSE
License-File: NOTICE
Author: Gowtham A Rao
Author-email: gowtham.rao@coreason.ai
Requires-Python: >=3.11
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Dist: aiofiles (>=23.2.1,<24.0.0)
Requires-Dist: anyio (>=4.0.0,<5.0.0)
Requires-Dist: causal-learn (>=0.1.3,<0.2.0)
Requires-Dist: dowhy (>=0.11,<0.13)
Requires-Dist: econml (>=0.16.0,<0.17.0)
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: loguru (>=0.7.2,<0.8.0)
Requires-Dist: networkx (<3.0)
Requires-Dist: numpy (>=1.26.0,<2.0.0)
Requires-Dist: pandas (>=2.3.3,<3.0.0)
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
Requires-Dist: scikit-learn (<1.7)
Requires-Dist: shap (>=0.38.1,<0.49.0)
Requires-Dist: torch (>=2.9.1,<3.0.0)
Requires-Dist: torchdiffeq (>=0.2.5,<0.3.0)
Project-URL: Documentation, https://github.com/CoReason-AI/coreason_inference
Project-URL: Homepage, https://github.com/CoReason-AI/coreason_inference
Project-URL: Repository, https://github.com/CoReason-AI/coreason_inference
Description-Content-Type: text/markdown

# coreason-inference

**Causal Discovery, Representation Learning, Active Experimentation, & Trial Optimization**

[![License](https://img.shields.io/badge/license-Prosperity%203.0-blue)](https://prosperitylicense.com/versions/3.0.0)
[![Build Status](https://github.com/CoReason-AI/coreason_inference/actions/workflows/build.yml/badge.svg)](https://github.com/CoReason-AI/coreason_inference/actions)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Documentation](https://img.shields.io/badge/docs-product_requirements-blue)](docs/product_requirements.md)

**coreason-inference** is the **Causal Intelligence** engine of the CoReason ecosystem. Unlike probabilistic models that predict correlation, this engine is designed to uncover **Mechanism** and **Heterogeneity**. It serves as the "Principal Investigator," discovering biological feedback loops, identifying latent confounders, and optimizing clinical trials through causal stratification and virtual simulation.

## Features

*   **Cyclic Discovery (Dynamics Engine):** Uses Neural ODEs to discover feedback loops and system dynamics in biological systems (Directed Cyclic Graphs).
*   **Latent Phenotyping (Latent Miner):** Disentangles hidden confounders using Causal VAEs to identify unmeasured variables driving outcomes.
*   **Heterogeneous Stratification (Causal Estimator):** Estimates Individual Treatment Effects (CATE) using Causal Forests to identify Super-Responders.
*   **Active Experimentation (Active Scientist):** Proposes physical experiments (e.g., Gene Knockouts) to resolve causal ambiguity using Information Gain heuristics.
*   **Protocol Optimization (Rule Inductor):** Translates CATE scores into human-readable clinical protocol rules to maximize Phase 3 Probability of Success (PoS).
*   **Virtual Trials (Virtual Simulator):** Simulates Phase 3 trials in-silico using synthetic "Digital Twins" to predict efficacy and scan for safety risks.

## Installation

```bash
pip install coreason-inference
```

## Usage

Here is a quick example of how to initialize and use the `InferenceEngine`:

```python
import pandas as pd
from coreason_inference.engine import InferenceEngine

# 1. Initialize the Engine
engine = InferenceEngine()

# 2. Load your data
# Data should contain time-series or observational data
data = pd.read_csv("patient_data.csv")
variable_cols = ["Glucose", "Insulin", "HbA1c"]
time_col = "Time"

# 3. Analyze: Discover Dynamics & Latents
result = engine.analyze(
    data=data,
    time_col=time_col,
    variable_cols=variable_cols,
    estimate_effect_for=("Insulin", "Glucose")
)

# 4. Inspect the Causal Graph
print(f"Discovered Graph Edges: {result.graph.edges}")
print(f"Detected Loops: {result.graph.loop_dynamics}")

# 5. Optimize for Heterogeneity (Identify Super-Responders)
# Estimate CATE for a specific treatment
engine.analyze_heterogeneity(
    treatment="Insulin",
    outcome="Glucose",
    confounders=["Age", "BMI"] + list(result.latents.columns)
)

# Induce rules to find the best subgroup
optimization_output = engine.induce_rules()

print("Recommended Protocol Criteria:")
for rule in optimization_output.new_criteria:
    print(f" - {rule.feature} {rule.operator} {rule.value} ({rule.rationale})")

print(f"Projected Probability of Success: {optimization_output.optimized_pos:.2f}")
```

## Documentation

For detailed requirements and architectural philosophy, please refer to the [Product Requirements Document](docs/product_requirements.md).

