BioSpace

representation infrastructure · not an ML library

A patient is
not a vector.

Algorithms never observe a patient. They observe a representation built from exams, signals and observations. BioSpace treats that representation as an independent scientific problem — and makes it executable.

M = (B, O, D, R, X, G, Γ, F, C) — nine entities, one theory, any disease.

representation space · live demonstration

based on test_riemannian_geodesic_exceeds_euclidean_across_spiral_loops

full academic paper

Mathematical Foundations of the Computational Representation of Biological Systems

The formal derivation of every entity, principle and contract on this page — with proofs, related work and the full OSAS case study.

Read the manuscript

the problem

The object no one defines

Most AI in healthcare implicitly assumes a patient can be reduced to a vector x = (x₁, x₂, …, xₙ) ∈ ℝⁿ. But that vector isn't the patient — it's just an arbitrary selection of attributes:

x = f(P), and almost always x ≠ P

Two studies on the same syndrome — Obstructive Sleep Apnea, for instance — can mathematically describe different patients: one uses only the AHI, another adds age and BMI, a third incorporates dozens of polysomnography variables. No algorithm resolves this inconsistency — because it's born before the algorithm, in the very definition of the input object.

BioSpace proposes explicitly separating four layers that most pipelines treat as one: the real biological system, its observations, its computational representation, and the inference algorithms.

the formal core

M = (B, O, D, R, X, G, Γ, F, C)

Nine formal entities, each with a corresponding computational implementation. The core knows nothing about any specific disease.

B

Biological System

The patient stops being a spreadsheet row. It becomes an entity that accumulates observations over time.

system = SleepSystem()
O

Observations

Not loose numbers — measurement processes with preserved origin, timestamp and provenance.

system.observe(exam({...}))
D

Semantic Domains

Observations grouped by physiological process — anthropometry, apnea, hypoxemia — each with its own meaning.

R

Representation

Composition of domains into an auditable vector.

R(B) = (φ₁(D₁), …, φₙ(Dₙ))
X

Representation Space

The product of individual spaces. The patient occupies a position, not an isolated vector.

X = X₁ × X₂ × … × Xₙ
G

Geometry

A structure independent of the representation: Euclidean, Mahalanobis, Wasserstein, Information.

Γ

Trajectories

The patient stops being a static state and gains a temporal evolution.

Γ(t) = R(B(t))
F

Phenotypes

Not algorithms. Regions of the representation space — algorithms merely estimate them.

C

Cohorts

Sets of biological systems — cross-sectional snapshots or complete longitudinal trajectories.

representation flow

From biological system to inference

Biological System Observations Measurements Semantic Domains Features Representation Representation Space Geometry Phenotyping Inference

traceability

A Feature is never just a number

Every coordinate of the space carries all information needed for audit — raw value, z-score, weight, missingness and provenance. No coordinate loses the path back to the clinical observation that originated it.

This is what makes the representation a contract, not a convenience: any coordinate can be explained, at any moment, for any patient.

Feature(
    name="spo2_minimum",
    value=-0.62,
    raw_value=88,
    z_score=-0.62,
    weight=0.93,
    is_missing=False,
    provenance=[...],
)

validation plugin · sleep medicine

Semantic domains

Each domain represents only one physiological aspect of the biological system and implements extraction, normalization, weighting and Feature construction independently of the others.

Anthropometric Apnea Hypoxemia Sleep Architecture Cardiovascular Comorbidities Symptoms Treatment

space geometry

Clinical distance is not unique

Geometry is a structure independent of the representation. Switching metrics never rebuilds the patient — it only reinterprets distances between points that already exist.

Euclidean

Straight-line distance in Feature space.

Mahalanobis

Corrects for correlation and scale across domains.

Wasserstein

Compares distributions, not just points.

Information Geometry

Distance over the underlying statistical manifold.

phenotyping

Phenotypes are regions, not labels

Any operator — clinical K-Means, HDBSCAN, GMM, spectral clustering — operates over exactly the same representation space. Swapping the algorithm never swaps the patient.

Clinical K-Means HDBSCAN Gaussian Mixture Spectral Clustering
space = cohort.snapshot()

phenotyper = ClinicalKMeansPhenotyper()
phenotypes = phenotyper.fit(space)

for phenotype in phenotypes:
    print(phenotype.name,
          phenotype.interpretation)

core principles

Six principles that constrain the entire architecture

3.1

Algorithmic Independence

The same representation space can be used by any learning method.

3.2

Compositionality

The representation emerges from composing independent physiological domains.

3.3

Semantic Preservation

Every coordinate keeps its clinical interpretation and the origin of the information.

3.4

Continuity

Small clinical changes don't produce discontinuous jumps in the space.

3.5

Extensibility

New physiological domains plug in without modifying existing infrastructure.

3.6

Reuse

The same infrastructure serves any disease that can be observed.

implementation

Package architecture

biospace/
├── core/            # mathematical core of the theory
├── geometry/        # Euclidean · DTW · Riemannian · geometric cohorts
├── phenotyping/     # K-Means · HDBSCAN · GMM · Spectral
├── dynamics/        # mean-reverting evolution, stability
├── early_warning/   # critical slowing down (Dakos et al. 2012)
├── survival/        # Kaplan-Meier · Cox · log-rank
├── causal/          # baseline balance · propensity · digital twin
├── gnn/              # graph convolutional networks
├── representation_learning/ # autoencoders vs. PCA
├── prediction/      # any sklearn-compatible classifier
├── explainability/  # SHAP over any trained predictor
├── risk/ · latent/  # transparent scores · factor analysis
├── anomaly/         # Isolation Forest · LOF · One-Class SVM
├── topology/        # Mapper · persistent homology
├── ontology/        # auto-generated ontology
├── longitudinal/    # trajectories, transitions, updates
├── datasets/        # NHANES · UCI Diabetes loaders
└── plugins/         # per-disease implementations — sleep, metabolic

core knows no diseases

All disease-specific clinical knowledge lives in plugins. The mathematical core stays the same for sleep, cardiology or oncology.

geometry is pluggable

Since geometry is independent of representation, swapping metrics never requires rebuilding patients.

ontology is executable documentation

Semantic domains automatically generate the system's ontology — documentation never goes stale.

two independent plugins validate the theory

plugins/sleep (Obstructive Sleep Apnea, real clinical cohort) and plugins/metabolic (endocrine-metabolic system, diabetes as one clinical interpretation among several) — spreadsheet loading, normalization, longitudinal grouping, phenotyping and survival analysis, unchanged across both.

formal contracts

Eleven contracts, locked by regression tests

Every principle of the meta-model is verifiable in code — not just described in prose. A real example: out-of-order observations can no longer contaminate a trajectory's past, a subtle bug fixed by propagating as_of through the whole chain.

5.1 Traceability 5.2 Semantic Preserv. 5.3 Compositionality 5.4 Continuity 5.5 Extensibility 5.6 Algorithmic Indep. 5.7 Temporality 5.8 Reproducibility 5.9 Versionability 5.10 Interoperability Injectivity (pop.)

3.3, 3.6, 3.9 and 3.10 were the last to gain a dedicated empirical test, each with a positive case and a decisive negative case (e.g. a domain-specific algorithm correctly fails the algorithmic independence contract when applied to a mismatched representation) — see ontology.run_contract_suite.

end to end

Complete example

from biospace.plugins.sleep import load_from_excel
from biospace.phenotyping import ClinicalKMeansPhenotyper

cohort, representation = load_from_excel("Exams.xlsx")

space = cohort.snapshot()

phenotyper = ClinicalKMeansPhenotyper()
phenotypes = phenotyper.fit(space)

for phenotype in phenotypes:
    print(phenotype.name, phenotype.interpretation)

beyond sleep

One infrastructure, any specialty

Each specialty implements only its own semantic domains. All infrastructure — core, geometry, phenotyping, longitudinal — stays unchanged.

Sleep Medicine Cardiology Endocrinology ✓ validated (NHANES, UCI) Oncology Neurology Psychiatry Epidemiology Intensive Care

independent, real, public data

Endocrinology is no longer hypothetical

The same MetabolicRepresentation was tested against two independent, real, public sources — NHANES (a national health survey) and UCI Diabetes 130-US Hospitals (administrative hospital records) — with structures different enough that they required two genuinely distinct sets of domains, connected only where a real physiological mechanism justified it.

NHANES · 9,232 adults

Lab-based diagnosis vs. self-report

A laboratory classifier (ADA glycemic criteria) agrees with self-reported diabetes diagnosis at 75.0% sensitivity and 95.0% specificity — consistent with well-documented underdiagnosis. 91.5% of lab-classified pre-diabetes cases carry no self-reported diagnosis at all.

Physiological process coherence — the hypothesis that HbA1c and glucose correlate more with each other than with unrelated variables — confirms in this real population (p = 0.0022), the exact opposite of the same test applied earlier to a synthetic cohort.

UCI Diabetes 130-US Hospitals · 71,518 patients

Utilization, not medication, predicts readmission

A phenotype built without age or diagnosis codes — only hospital utilization, sparse glycemic testing and medication intensity — shows nearly double the 30-day readmission rate of the others (8.75% vs. 3.97–4.64%).

The highest-risk phenotype is not the one with the most intensive medication regimen — it's the one with the highest prior utilization, consistent with established readmission-prediction literature. 23.4% of patients had multiple encounters, producing this project's first real multi-point trajectories. Adding a diagnosis-code domain changes this finding — see the manuscript, §10.11 — a live demonstration that representation choice is not neutral, tested within a single data source.

Full tables and confusion matrices: see the manuscript, §10.11, and the dedicated paper "Empirical Findings on Type 2 Diabetes Mellitus in Two Independent Real-World Data Sources."

representation, not one algorithm

Four independent methods, the same honest answer

Because BioSpace is a representation layer, not a model, the same real question can be handed to genuinely different techniques — and when they agree, that agreement means something a single model's score never could.

the question

Does a patient's first hospital visit predict a future early readmission?

Tested on the UCI Diabetes 130-US Hospitals cohort — baseline-only features (Contract 5.7: never look at a patient's future to build a covariate), four unrelated methods: Cox regression on phenotype, Random Forest, Logistic Regression, and SHAP explainability on the trained forest.

the answer, from all four

Near chance — and SHAP shows why

Cox concordance and both classifiers' AUC cluster at 0.50–0.53, cross-validated. SHAP resolves the remaining question a bare metric can't: is there a strong signal in one feature the model just isn't exploiting? No — importance is diffuse across all 13 baseline features, never one dominating by more than 20×, unlike a synthetic control where a truly informative feature dominates by 5× or more.

Reported with the same weight as any positive finding — a null result four independent methods agree on is still a result. Full numbers: METABOLISM_FINDINGS.md, §10–12 and §16.

from foundations to application

A six-article series

The manuscript is the full technical account. These six articles split the same body of work into independently readable pieces — from the formal theory to a single applied methodological question.

I

Mathematical Foundations

The meta-model, five axioms, metric structure, operator algebra, and two independent functor demonstrations.

II

Geometry as a Missing Axis

Holding representation fixed and varying only geometry, tested on two independent real sources — a mixed, honestly reported result.

III

Generalization Across Diseases

Type 2 diabetes on two structurally incompatible real sources — including a live demonstration that representation choice changes the finding.

IV

Representation Before Inference

A position paper engaging directly with normative modeling — why every comparative benchmark compares representation times algorithm.

V

Convergence Between Independent Methods as Evidence

A short methodological paper on the triangulation story above — why a representation-first architecture makes cross-method validation cheap enough to do routinely.

mathematical foundations of computational representation of biological systems

The theory is already software. Read the code, run the tests, extend it to your disease.

BioSpace — mathematical core, pluggable geometries, validation plugin in Sleep Medicine.

MIT license