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)

📄 License & Citation

Distributed under the MIT License.

@inproceedings{melhi2026oncoshift,
  title     = {OncoShift: Enterprise Safety and Robustness Auditing for
               Multi-Modal Health AI Foundation Models},
  author    = {Melhi, Sharon},
  booktitle = {Machine Learning for Health (ML4H)},
  year      = {2026},
  url       = {https://github.com/Sharon-codes/Onco-Shift}
}

Developed by Sharon Melhi (@Sharon-codes) for ML4H 2026.

Download files

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

Source Distribution

oncoshift-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

oncoshift-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file oncoshift-0.1.0.tar.gz.

File metadata

  • Download URL: oncoshift-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for oncoshift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c59596c03b81bdcfadc1c5d640bd2b49598e428010e784569ba7a93f7005a201
MD5 d77ac0a74348ee8f7a35c812ab156da0
BLAKE2b-256 4e9d92a7d9b3d73d6e89070485bbe998fadc3a6a7e522c7b41426ff638fce34c

See more details on using hashes here.

File details

Details for the file oncoshift-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oncoshift-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for oncoshift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e6f8a642e69b7431a4597838a9df98408dd1c64b29007e3216dbb822076df9d
MD5 99ef0d8fd5e060c7a36d64733b51dd3d
BLAKE2b-256 a15245e68ad5789ed38cb25487b4666a010a05f92699e629cd29b15c46aa8ac4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Supported by

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