Skip to main content

🧬 OncoShift (oncoshift)

Enterprise Safety & Robustness Auditing Engine for Multi-Modal Health AI Foundation Models

PyPI Version Python 3.9+ License: MIT ML4H Vercel Dashboard

OncoShift is a Python library for quantifying representation collapse, calibration degradation, and clinical decision utility failure in multi-modal health foundation models under real-world distribution shift.


⚡ Installation

Install the package via pip:

pip install oncoshift

Or install from source in editable mode:

git clone https://github.com/Sharon-codes/Onco-Shift.git
cd Onco-Shift
pip install -e oncoshift_sdk/

🚀 Quickstart

Audit any PyTorch model backbone or Hugging Face model repository in 3 lines of code:

import torch
import torch.nn as nn
from oncoshift import OncoAuditor

# 1. Instantiate auditor for your target medical backbone
auditor = OncoAuditor(model=my_foundation_model, modality="pathology")

# 2. Input baseline clean tensors
x_clean = torch.randn(32, 3, 224, 224)

# 3. Run automated robustness audit
results = auditor.audit(baseline_tensor=x_clean, epsilon=0.5)

# Inspect empirical metric scores
print(f"Wasserstein Distance W₁  : {results['w1_distance']:.4f}")
print(f"Gromov-Wasserstein GW₂   : {results['gromov_wasserstein']:.4f}")
print(f"Feature Leakage Ratio η  : {results['leakage_ratio']:.4f}")
print(f"SVCCA Alignment          : {results['svcca_alignment']:.4f}")
print(f"Brier Reliability Error  : {results['brier_reliability']:.4f}")
print(f"Net Benefit (at pt=0.30) : {results['net_benefit_at_30']:.4f}")

📐 Mathematical Auditing Modules

1. Optimal Transport Geometry (oncoshift.math_engine)

  • 1st Wasserstein Distance ($W_1$): Linear programming exact solver (ot.emd2) over ground metric $M_{ij} = |z_P^{(i)} - z_Q^{(j)}|_2$.
  • Gromov-Wasserstein Alignment ($GW_2$): Topological distance divergence solver (ot.gromov.gromov_wasserstein2).
  • SVD Feature Leakage Ratio ($\eta_{\text{leakage}}$): Quantifies off-manifold feature drift via orthogonal singular vector projection.
  • Singular Vector CCA ($\text{SVCCA}$): Subspace canonical correlation between baseline and shifted feature representations.
from oncoshift import (
    compute_wasserstein_nd,
    compute_gromov_wasserstein,
    compute_feature_leakage_ratio,
    compute_svcca
)

w1 = compute_wasserstein_nd(z_baseline, z_shifted)
gw2 = compute_gromov_wasserstein(z_baseline, z_shifted)
leakage = compute_feature_leakage_ratio(z_baseline, z_shifted)
svcca = compute_svcca(z_baseline, z_shifted)

2. Clinical Decision Analysis (oncoshift.auditor)

  • Murphy (1973) Brier Score Decomposition: Exact decomposition into Reliability ($\text{Rel}$), Resolution ($\text{Res}$), and Uncertainty ($\text{Unc}$).
  • Decision Curve Analysis (DCA Net Benefit): Measures net clinical utility at decision threshold $p_t = 0.30$.
from oncoshift import decompose_brier_score, compute_decision_curve

brier_metrics = decompose_brier_score(y_true, p_pred, n_bins=10)
print(f"Reliability Penalty: {brier_metrics['reliability']:.4f}")

dca_results = compute_decision_curve(y_true, p_pred, thresholds=[0.30])
print(f"Net Benefit at 0.30: {dca_results['net_benefit_model'][0]:.4f}")

3. Multi-Modal Distribution Shift Perturbations (oncoshift.shifts)

Generate realistic clinical perturbations across 3 primary health modalities:

  • Pathology: Stain variation, defocus blur ($\sigma_{\text{blur}}$), and geometric tissue folds.
  • Radiology: Acquisition motion blur and additive Gaussian sensor noise.
  • EHR: Hawkes self-exciting process missingness cascades and irregular observation sampling.
from oncoshift import apply_pathology_shift, apply_radiology_shift, apply_ehr_shift

x_path_shifted = apply_pathology_shift(x_tiles, epsilon=0.5)
x_rad_shifted = apply_radiology_shift(x_cxr, epsilon=0.5)
x_ehr_shifted = apply_ehr_shift(x_seq, epsilon=0.5)

📜 Author & License

Developed by Sharon Melhi (@Sharon-codes).
Distributed under the MIT License.

Metadata

Release files for oncoshift 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oncoshift 0.1.1
File Size Uploaded
oncoshift-0.1.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oncoshift 0.1.1
File Interpreter ABI Platform
oncoshift-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / oncoshift-0.1.1.tar.gz

Download URL oncoshift-0.1.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dd75103b0737d673acb9538b2d3ad7c1665e7cf90bf537580f9811c2d427ce48
BLAKE2b-256 checksum
How to use checksums
b16339c176f7c77db62f2e7f5fcc2dbb10b5ac32aa63d47a9ee9e204ae5345c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / oncoshift-0.1.1-py3-none-any.whl

Download URL oncoshift-0.1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53bbb22215099103b0ba77559400be7a0df5811fc2d64a31d60c0dba3a65c085
BLAKE2b-256 checksum
How to use checksums
7f603497ec8084196e09e730904e1412173bb13aaa82d3309022cf86009c134f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page