TopoHyper: Integrated Topological-Hypergraph Neural Networks for Medical Image Classification

A novel hybrid architecture that integrates Topological Neural Networks (TNNs) with Hypergraph Neural Networks (HGNNs) for medical image classification, achieving 82.0% test accuracy on PathMNIST (9-class colon pathology).

Key Innovation

TopoHyper introduces a three-phase message passing mechanism that combines the strengths of both topological and hypergraph representations:

  1. Phase 1 β€” Simplicial Convolution: Propagation via unsigned Hodge Laplacian |B₁||B₁|α΅€, capturing topological structure (boundary relationships, holes, cavities)
  2. Phase 2 β€” Hypergraph Convolution: Spectral propagation via D_v^{-1/2} H W D_e^{-1} Hα΅€ D_v^{-1/2}, modeling arbitrary higher-order group relationships
  3. Phase 3 β€” Cross-Structure Fusion: Attention-gated combination + bridge matrix B = A_sc βŠ™ A_hg that propagates information through nodes connected in both views

The bridge matrix turned out to be the most critical component β€” ablation shows removing it drops accuracy by 3.5%.

Architecture Diagram

Input Image (64Γ—64)
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Patch Extraction    β”‚  8Γ—8 patches, stride 6 β†’ 100 nodes
β”‚  Feature Engineering β”‚  38-dim: color histogram + texture + spatial
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Structure Building  β”‚  k-NN (k=6) β†’ edges β†’ triangles
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚Simplicβ”‚Hyper-  β”‚ β”‚  Simplicial: nodes + edges + triangles
β”‚  β”‚Complexβ”‚graph   β”‚ β”‚  Hypergraph: k-NN neighborhoods + triangles
β”‚  β””β”€β”€β”€β”¬β”€β”€β”€β”΄β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”˜
       β”‚       β”‚
       β–Ό       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   TopoHyperConv Γ—2  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚  Phase 1: SimplicialConv (Hodge Laplacian)
β”‚  β”‚ Phase 1: SC     β”‚β”‚
β”‚  β”‚ Phase 2: HG     β”‚β”‚  Phase 2: HypergraphConv (spectral)
β”‚  β”‚ Phase 3: Fusion β”‚β”‚  Phase 3: Attention gate + Bridge matrix
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  TopoHyperPool      β”‚  Mean + Max + Attention pooling
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Classification Head β”‚  MLP β†’ 9 classes
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Results

Main Comparison (PathMNIST, 9-class colon pathology)

Model Test Acc F1-macro Val Acc Params
TopoHyper 82.0% 0.7116 83.0% 94,858
GCN 81.5% 0.7096 83.0% 17,161
Simplicial 81.5% 0.7096 81.0% 17,417
HGNN 81.0% 0.6848 79.5% 17,161
SimpleHybrid 78.5% 0.6731 78.5% 14,537
GAT 77.0% 0.6765 78.0% 17,801

Ablation Study (TopoHyper variants)

Configuration Test Acc Val Acc
Full (Bridge + Attention) 82.0% 83.0%
No Attention (Bridge only) 83.0% 83.5%
Neither (Average fusion) 80.5% 81.0%
No Bridge (Attention only) 78.5% 79.0%

Key findings:

  • Bridge matrix is the most critical component β€” removing it drops accuracy by 3.5%
  • Cross-structure attention provides modest gains (+1.5%) when bridge is present
  • Naive concatenation hybrid (SimpleHybrid) underperforms standalone baselines β€” principled fusion matters
  • The bridge-only variant actually scores highest (83.0%), suggesting simpler fusion may be better

Theoretical Background

Topological Neural Networks (TNNs)

TNNs operate on simplicial/cell complexes using algebraic topology. The fundamental object is the boundary operator B_k: C_k β†’ C_{k-1}, and the Hodge Laplacian L_k = B_kα΅€ B_k + B_{k+1} B_{k+1}α΅€ decomposes signals into gradient, curl, and harmonic components.

Advantages: Captures topological invariants (Betti numbers), multi-scale Hodge decomposition, principled boundary handling. Limitations: Closure property requirement, O(n^{3/2}) clique detection, cannot represent non-clique groups.

Reference: Papillon et al., "Architectures of Topological Deep Learning: A Survey of Message-Passing Topological Neural Networks" (arXiv:2304.10031)

Hypergraph Neural Networks (HGNNs)

HGNNs operate on hypergraphs H=(V,E,W) where hyperedges connect arbitrary subsets of vertices. The spectral convolution uses: X^{(l+1)} = Οƒ(D_v^{-1/2} H W D_e^{-1} Hα΅€ D_v^{-1/2} X^{(l)} Θ^{(l)}).

Advantages: Arbitrary higher-order relationships, no closure requirement, efficient V→E→V propagation. Limitations: No boundary/orientation information, less rich spectral theory, symmetric node treatment within hyperedges.

Reference: Feng et al., "Hypergraph Neural Networks" (arXiv:1809.09401)

Compatibility Resolution

Challenge Solution
TNN uses signed B_k; HGNN uses unsigned H Use |B_k| (absolute boundary) for message passing
Different spectral paradigms Three-phase architecture with parallel branches
Different optimization objectives Single end-to-end loss with attention-gated fusion

Key insight: |B₁| is an incidence matrix for the simplicial complex viewed as a hypergraph. This duality enables principled integration.

Medical Image β†’ Graph Pipeline

Each 64Γ—64 medical image is converted to a graph:

  1. Patch extraction: 8Γ—8 patches with stride 6 β†’ 100 nodes per image
  2. Feature engineering (38-dim per node):
    • Color histogram: 24 bins (8 per RGB channel)
    • Texture: 8 values (gradient statistics at 2 scales)
    • Spatial position: 6 values (normalized coordinates + quadratic terms)
  3. Structure building:
    • k-NN graph (k=6) β†’ edges
    • 3-clique detection β†’ triangles (for simplicial complex)
    • k-NN neighborhoods + triangles β†’ hyperedges (for hypergraph)

Usage

Installation

pip install torch torchvision scikit-learn scipy medmnist

Quick Start

import torch
from topohyper.structures import build_topohyper_structure
from topohyper.data import extract_patch_features
from topohyper.models import TopoHyperNet

# Load a medical image (C, H, W) tensor normalized to [0, 1]
image = torch.randn(3, 64, 64).clamp(0, 1)

# Convert to graph
features, positions = extract_patch_features(image, patch_size=8, stride=6)
sc, hg, edge_index = build_topohyper_structure(features, k=6)

# Create model
model = TopoHyperNet(
    in_dim=38,
    hidden_dim=64,
    num_classes=9,
    num_layers=2,
    use_bridge=True,
    use_attention=True
)

# Forward pass
logits = model(features, sc, hg, edge_index)
prediction = logits.argmax()

Full Training

from topohyper.data import load_medmnist_data
from topohyper.models import get_model

# Load data (use max_train/val/test to subsample)
train_ds, val_ds, test_ds, num_classes = load_medmnist_data(
    dataset_name='pathmnist',
    size=64,
    max_train=800,
    max_val=200,
    max_test=200
)

# Create model
model = get_model('topohyper', in_dim=38, hidden_dim=64, num_classes=9)

# Train (see train_eval.py for full training loop)

Experimental Setup

Parameter Value
Dataset PathMNIST (9-class colon pathology)
Image size 64Γ—64
Training samples 800
Validation samples 200
Test samples 200
Epochs 25
Learning rate 0.001 (Adam)
Weight decay 1e-4
LR schedule ReduceLROnPlateau (patience=5, factor=0.5)
Hidden dimension 64
Number of layers 2
Dropout 0.3
k-NN neighbors 6
Patch size / stride 8 / 6
Nodes per graph 100
Feature dimension 38

Potential Applications

  1. Medical imaging: Pathology, dermatology, radiology image classification where spatial relationships between tissue regions matter
  2. Social network analysis: Modeling both dyadic (edge) and group (hyperedge) interactions with topological constraints
  3. Molecular property prediction: Atoms as nodes, bonds as edges, functional groups as hyperedges, ring structures as simplices
  4. Recommendation systems: User-item interactions as hyperedges with topological structure from user similarity

File Structure

β”œβ”€β”€ README.md              # This file
β”œβ”€β”€ report.txt             # Full research report
β”œβ”€β”€ results.json           # Experimental results
β”œβ”€β”€ topohyper/
β”‚   β”œβ”€β”€ __init__.py        # Package init
β”‚   β”œβ”€β”€ structures.py      # SimplicialComplex, Hypergraph, build_topohyper_structure()
β”‚   β”œβ”€β”€ layers.py          # SimplicialConv, HypergraphConv, CrossStructureAttention, TopoHyperConv
β”‚   β”œβ”€β”€ models.py          # TopoHyperNet + 5 baselines
β”‚   └── data.py            # Medical image β†’ graph conversion
└── train_eval.py          # Training and evaluation script

Citation

If you use this work, please cite the foundational papers:

@article{papillon2023architectures,
  title={Architectures of Topological Deep Learning: A Survey of Message-Passing Topological Neural Networks},
  author={Papillon, Mathilde and Sanborn, Sophia and Hajij, Mustafa and Miolane, Nina},
  journal={arXiv preprint arXiv:2304.10031},
  year={2023}
}

@inproceedings{feng2019hypergraph,
  title={Hypergraph Neural Networks},
  author={Feng, Yifan and You, Haoxuan and Zhang, Zizhao and Ji, Rongrong and Gao, Yue},
  booktitle={AAAI},
  year={2019}
}

License

MIT

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Papers for chaoshengt/topohyper-medical