Metadata-Version: 2.1
Name: tessera-ml
Version: 0.3.0
Summary: Topological Entity Similarity Structure for Emergent Response Analysis
Author-email: "João F. R. Tonini" <jtonini@richmond.edu>
License: BSD-3-Clause
Project-URL: Homepage, https://github.com/jtonini/tessera
Project-URL: Repository, https://github.com/jtonini/tessera
Project-URL: Documentation, https://github.com/jtonini/tessera#readme
Project-URL: Issues, https://github.com/jtonini/tessera/issues
Keywords: machine-learning,graph-neural-networks,similarity-networks,community-detection,binary-classification,regime-divergence,network-topology
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21
Requires-Dist: scipy>=1.7
Requires-Dist: pandas>=1.3
Requires-Dist: scikit-learn>=1.0
Requires-Dist: matplotlib>=3.5
Requires-Dist: psutil>=5.8
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Provides-Extra: full
Requires-Dist: torch>=2.0; extra == "full"
Requires-Dist: torch-geometric>=2.3; extra == "full"
Requires-Dist: leidenalg>=0.9; extra == "full"
Requires-Dist: igraph>=0.10; extra == "full"
Requires-Dist: xgboost>=1.7; extra == "full"
Requires-Dist: ripser>=0.6; extra == "full"
Provides-Extra: ml
Requires-Dist: torch>=2.0; extra == "ml"
Requires-Dist: torch-geometric>=2.3; extra == "ml"
Requires-Dist: leidenalg>=0.9; extra == "ml"
Requires-Dist: igraph>=0.10; extra == "ml"

# TESSERA

**Topological Entity Similarity Structure for Emergent Response Analysis**

A domain-general framework for detecting and exploiting geometric structure
in multi-dimensional feature spaces for predictive classification.

*Targeting: Nature Computational Science*

## Core Hypothesis

When entities are characterized by multi-dimensional features and outcomes
depend on relational position in feature space, similarity network topology
carries predictive information that direct feature-based classifiers miss.

## Three Failure Geometries

TESSERA detects geometrically distinct response regions in entity similarity
space:

1. **Ecotone** — responses cluster at boundaries between stable operational
   domains (analogous to ecological transition zones)
2. **Isolated cluster** — responses occupy a distinct region, separate from
   main domains
3. **Diffuse** — responses scattered within domains, driven by individual
   feature thresholds

## Three Demonstration Domains

| | Ecology | Manufacturing | HPC |
|---|---|---|---|
| **Entity** | Reef survey | Production run | Job |
| **Features** | Environmental conditions | Sensor measurements | Resource usage |
| **Outcome** | Bleaching | Defect | Failure |
| **Dataset** | Global Coral Bleaching DB | UCI SECOM | Synthetic / NØMAD |
| **N** | ~35,000 | 1,567 | 5,000+ |

## Validation Protocol

1. **Phase 1 — Ablation**: GNN vs. MLP, RF, XGBoost, LogReg (justify network)
2. **Phase 2 — Similarity**: 7 measures compared (Simpson, Cosine, Bray-Curtis,
   Jaccard, Pearson, Euclidean, Mahalanobis)
3. **Phase 3 — Bin sensitivity**: n_bins = 2, 3, 4, 5 (Simpson only)
4. **Phase 4 — Temporal**: 5-fold temporal cross-validation

## Using TESSERA as a classifier (0.3.0)

`TesseraClassifier` trains and scores the full stack (similarity network,
communities, GNN, LSTM, community autoencoders, performance-weighted blend) in
two calls:

```python
import numpy as np
from tessera.models import TesseraClassifier

clf = TesseraClassifier(gnn_epochs=150, lstm_epochs=80, ae_epochs=80)
clf.fit(X, y, time_windows=tw)      # y: 1, 0, or -1 where the outcome isn't known
risk = clf.predict_proba()          # one score per entity, the -1 ones included
clf.component_weights               # {"gnn": ..., "lstm": ..., "ae": ...}
```

- **Transductive.** Every entity passed to `fit` is a node of the similarity
  graph; `predict_proba()` scores all of them. To score new entities, include
  them in `fit` with label `-1`.
- **Nothing learns from an unlabelled entity**, nor from the internal
  validation split that sets the blend weights: the components train on the
  training split, and the community outcome rates the LSTM sees come from it
  alone (`prepare_lstm_data(..., rate_mask=)`).
- **An honest held-out check:** hide a set's labels as `-1`, fit, and compare
  its scores with the labels you kept aside. In-sample scores of labelled
  entities are optimistic (the GNN saw their place in the graph and their labels).
- **Large populations:** above `dense_max` entities (5000) the similarity is
  the sparse kNN one (`core/sparse_similarity.py`: memory N x k, not N x N).
- Needs the ML extras: `pip install 'tessera-ml[ml]'`. `device` defaults to
  CUDA when available.

## Project Structure

```
tessera/
├── __init__.py                    # Package init (v0.1.0)
├── core/
│   ├── __init__.py
│   ├── similarity.py              # 7 similarity measures
│   └── network.py                 # Graph construction (threshold, kNN, weighted)
├── synthetic/
│   ├── __init__.py
│   ├── landscape.py               # Feature space topology builder
│   ├── outcomes.py                # Failure pattern assignment (3 types + mixed)
│   └── visualize.py               # Diagnostic plots
├── data_acquisition.py            # Real dataset download & preprocessing
├── test_generator.py              # Synthetic data validation
└── test_pipeline.py               # End-to-end pipeline test
```

## Current Status

- [x] Synthetic data generator (3 patterns + mixed, with entity injection)
- [x] Similarity engine (7 measures, vectorized)
- [x] Network construction (threshold, kNN, weighted)
- [x] Pipeline validation (data → similarity → graph)
- [ ] GNN model
- [ ] Real dataset acquisition (coral bleaching, SECOM)
- [ ] Validation pipeline (4 phases)
- [ ] Methods section
- [ ] Results
- [ ] Introduction, Discussion, Conclusions

## Paper Writing Order

1. Methods
2. Results
3. Introduction
4. Discussion
5. Conclusions
6. Abstract (last)

## References

- van Woesik, R. & Kratochwill, C. (2022). A global coral-bleaching database,
  1980–2020. *Scientific Data*, 9(20).
- McCann, M. & Johnston, A. (2008). SECOM Dataset. UCI ML Repository.
- Tonini, J. (2025). NØMAD-HPC. *Journal of Open Research Software*.
