Prototype-based binary classification using asymmetric Tversky similarity fields. The method is general-purpose and applicable to any image or tabular classification task. It is evaluated here on two medical ultrasound benchmarks:
Two complementary pipelines are provided: one for image-based models and one for clinical tabular data.
Fig. 1 - Organ-wise Image Concepts and Patient-wise Concepts with Multiple-Instance Learning
Standard similarity metrics are symmetric — S(A, B) = S(B, A). Many classification problems are not. A borderline case may weakly resemble a positive-class prototype without that prototype resembling the borderline case. Asymmetric Tversky similarity captures this directional structure:
S(x → y) = |x ∩ y| / (|x ∩ y| + α|x \ y| + β|y \ x|)
α ≠ β breaks symmetry. During training, both S(x → prototype) and S(prototype → x) are computed and composed. The classifier is built from multiple composed similarity fields (Propositions 4 & 5): each field projects embeddings to a different subspace, learns its own prototype set, and the fields are combined via a learned convex weighting.
The image pipeline (train_similarity_field_v3_sigmoid.py) implements the multi-field Tversky classifier on top of frozen or fine-tuned pretrained encoders. Dataset-specific entry points wrap the same model code with the appropriate data loader and cross-validation strategy.
| Script | Evaluation dataset | Task |
|---|---|---|
train_similarity_field_v3_sigmoid.py | CARDIUM | CHD vs. control |
train_similarity_field_v3_sigmoid_thyroid.py | ThyroidCineClip | Benign vs. malignant |
Image → Pretrained Encoder → [num_fields × Projection Head] → Similarity Fields → Classification
medvit_original, medvit, visionclip, dinov2 (frozen or fine-tuned)mlp, grn, attention, se, bottleneck, cosinesigmoid, softplus, relu, relu_norm — constrains features to [0, 1] for Tversky compatibility| Component | Default | Purpose |
|---|---|---|
| Multi-field composition | 3 fields | Ensemble of complementary feature subspaces |
| Dynamic α/β | progressive | Starts symmetric, increases asymmetry through training |
| Prototype initialization | k-means / z-score coreset | Data-driven starting points |
| Stability anchors | optional | Prevents prototype drift (Theorem 2) |
| Manifold anchoring | optional | Pulls prototypes toward nearest embeddings |
| Feature attraction | optional | Pulls embeddings toward nearest prototypes |
| Class-weighted hinge | optional | Handles class imbalance with sqrt-dampened weights |
# CARDIUM
python train_similarity_field_v3_sigmoid.py \
--data_dir /path/to/CARDIUM \
--encoders dinov2 \
--feature_dim 128 \
--num_prototypes 7 \
--num_fields 3 \
--alpha_values 0.8 \
--beta_values 0.2 \
--margin_values 0.3 \
--projection_head mlp \
--output_activation sigmoid \
--epochs 100 \
--use_cv \
--patient_level_eval \
--differential_lr \
--class_weighted \
--out results.json
# ThyroidCineClip
python train_similarity_field_v3_sigmoid_thyroid.py \
--data_dir ./thyroidultrasoundcineclip \
--encoders dinov2 \
--feature_dim 128 \
--num_prototypes 5 \
--use_cv \
--num_cv_folds 5 \
--out thyroid_results.json
bash run_experiments_v3_sigmoid.sh --gpus 0,1,2,3 --jobs-per-gpu 2
Sweeps encoders × feature dims × prototype counts × α/β × margin across GPUs and writes per-experiment JSON results.
| Argument | Default | Description |
|---|---|---|
--encoders | efficientnet | Comma-separated encoder names |
--feature_dim | 32 | Projection head output dimension |
--num_prototypes | 5,7,10 | Prototype counts to sweep |
--num_fields | 3 | Number of composed similarity fields |
--alpha_values | 0.7,0.8,0.9 | Tversky α (weight on x\y) |
--beta_values | 0.1,0.2,0.3 | Tversky β (weight on y\x) |
--margin_values | 0.1,0.2,0.3 | Hinge loss margin |
--combine_mode | geometric | Field combination: geometric/arithmetic/forward_only/… |
--projection_head | mlp | Projection architecture |
--output_activation | sigmoid | Output activation for [0,1] constraint |
--differential_lr | off | Separate LRs for encoder / projector / prototypes |
--class_weighted | off | Sqrt-dampened positive class weighting |
--patient_level_eval | off | Aggregate per patient before eval |
--patient_agg | mean | Patient aggregation: mean or attention |
--augmentation | default | default (AugMix) or geometric |
--use_cv | off | Cross-validation |
--dynamic_alpha_beta | progressive | α/β schedule: static/progressive/cyclical |
The tabular pipeline treats clinical records as unordered sets of feature–value pairs, making the model invariant to measurement ordering and robust to variable-length records. The same architecture is evaluated on both benchmarks.
| Script | Evaluation dataset | Task |
|---|---|---|
benchmark_patient_level_v2.py | CARDIUM | CHD vs. control |
benchmark_thyroid_v2.py | ThyroidCineClip | Benign vs. malignant |
Clinical record (set of measurements)
→ Type-specific embedders (numeric / categorical / coded / temporal)
→ Permutation-invariant aggregation (Deep Sets: ρ ∘ Σφ)
→ [optional] Hypergraph layer (patient–feature–cell relationships)
→ Asymmetric Tversky similarity classifier
Type-specific modules:
| Module | Feature type | Method |
|---|---|---|
NumericEmbedder | Continuous values | Gaussian normalization + MLP |
CategoricalEmbedder | Discrete labels | Learned embeddings |
CodedEmbedder | ICD / LOINC / drug codes | Hierarchical ontology embeddings |
MonotonicEncoder | Ordered features | Monotone network (Lipschitz constrained) |
HypergraphLayer | All | Hyperedge message passing over patient–feature graph |
A clinical schema object encodes domain knowledge: valid ranges, feature types, monotonicity directions, and ontology hierarchy depths — but this can be replaced with a schema appropriate for any domain.
# CARDIUM
python benchmark_patient_level_v2.py \
--data_dir /path/to/CARDIUM \
--epochs 50 \
--batch_size 32
# ThyroidCineClip
python benchmark_thyroid_v2.py \
--data_dir ./thyroidultrasoundcineclip \
--epochs 50 \
--batch_size 32
The datasets below are used to evaluate the method; they are not requirements for using the code.
CARDIUM — fetal cardiac ultrasound + clinical records:
cardium_data/
├── cardium_images.tar.gz
├── delfos_clinical_data_woe_wnm_standarized_f_normalized.json
└── delfos_clinical_data_wnm_translated_final_cleaned.json
Download: https://github.com/BCV-Uniandes/Cardium
ThyroidCineClip — thyroid ultrasound cine-clips + metadata:
thyroidultrasoundcineclip/
├── dataset.hdf5
└── metadata.csv
Download: https://stanfordaimi.azurewebsites.net/datasets/thyroid-disease
All evaluation is patient-level: image-level scores are aggregated per patient before computing metrics.
| Metric | Description |
|---|---|
| AUC-ROC | Primary model selection criterion |
| F1 @ 0.5 | Balanced precision/recall |
| Sensitivity | Recall for positive-class patients |
| Specificity | True negative rate |
Results are reported as mean ± std across cross-validation folds.
9 commits
Python
100.0%
Prototype-based binary classification using asymmetric Tversky similarity fields. The method is general-purpose and applicable to any image or tabular classification task. It is evaluated here on two medical ultrasound benchmarks:
Two complementary pipelines are provided: one for image-based models and one for clinical tabular data.
Fig. 1 - Organ-wise Image Concepts and Patient-wise Concepts with Multiple-Instance Learning
Standard similarity metrics are symmetric — S(A, B) = S(B, A). Many classification problems are not. A borderline case may weakly resemble a positive-class prototype without that prototype resembling the borderline case. Asymmetric Tversky similarity captures this directional structure:
S(x → y) = |x ∩ y| / (|x ∩ y| + α|x \ y| + β|y \ x|)
α ≠ β breaks symmetry. During training, both S(x → prototype) and S(prototype → x) are computed and composed. The classifier is built from multiple composed similarity fields (Propositions 4 & 5): each field projects embeddings to a different subspace, learns its own prototype set, and the fields are combined via a learned convex weighting.
The image pipeline (train_similarity_field_v3_sigmoid.py) implements the multi-field Tversky classifier on top of frozen or fine-tuned pretrained encoders. Dataset-specific entry points wrap the same model code with the appropriate data loader and cross-validation strategy.
| Script | Evaluation dataset | Task |
|---|---|---|
train_similarity_field_v3_sigmoid.py | CARDIUM | CHD vs. control |
train_similarity_field_v3_sigmoid_thyroid.py | ThyroidCineClip | Benign vs. malignant |
Image → Pretrained Encoder → [num_fields × Projection Head] → Similarity Fields → Classification
medvit_original, medvit, visionclip, dinov2 (frozen or fine-tuned)mlp, grn, attention, se, bottleneck, cosinesigmoid, softplus, relu, relu_norm — constrains features to [0, 1] for Tversky compatibility| Component | Default | Purpose |
|---|---|---|
| Multi-field composition | 3 fields | Ensemble of complementary feature subspaces |
| Dynamic α/β | progressive | Starts symmetric, increases asymmetry through training |
| Prototype initialization | k-means / z-score coreset | Data-driven starting points |
| Stability anchors | optional | Prevents prototype drift (Theorem 2) |
| Manifold anchoring | optional | Pulls prototypes toward nearest embeddings |
| Feature attraction | optional | Pulls embeddings toward nearest prototypes |
| Class-weighted hinge | optional | Handles class imbalance with sqrt-dampened weights |
# CARDIUM
python train_similarity_field_v3_sigmoid.py \
--data_dir /path/to/CARDIUM \
--encoders dinov2 \
--feature_dim 128 \
--num_prototypes 7 \
--num_fields 3 \
--alpha_values 0.8 \
--beta_values 0.2 \
--margin_values 0.3 \
--projection_head mlp \
--output_activation sigmoid \
--epochs 100 \
--use_cv \
--patient_level_eval \
--differential_lr \
--class_weighted \
--out results.json
# ThyroidCineClip
python train_similarity_field_v3_sigmoid_thyroid.py \
--data_dir ./thyroidultrasoundcineclip \
--encoders dinov2 \
--feature_dim 128 \
--num_prototypes 5 \
--use_cv \
--num_cv_folds 5 \
--out thyroid_results.json
bash run_experiments_v3_sigmoid.sh --gpus 0,1,2,3 --jobs-per-gpu 2
Sweeps encoders × feature dims × prototype counts × α/β × margin across GPUs and writes per-experiment JSON results.
| Argument | Default | Description |
|---|---|---|
--encoders | efficientnet | Comma-separated encoder names |
--feature_dim | 32 | Projection head output dimension |
--num_prototypes | 5,7,10 | Prototype counts to sweep |
--num_fields | 3 | Number of composed similarity fields |
--alpha_values | 0.7,0.8,0.9 | Tversky α (weight on x\y) |
--beta_values | 0.1,0.2,0.3 | Tversky β (weight on y\x) |
--margin_values | 0.1,0.2,0.3 | Hinge loss margin |
--combine_mode | geometric | Field combination: geometric/arithmetic/forward_only/… |
--projection_head | mlp | Projection architecture |
--output_activation | sigmoid | Output activation for [0,1] constraint |
--differential_lr | off | Separate LRs for encoder / projector / prototypes |
--class_weighted | off | Sqrt-dampened positive class weighting |
--patient_level_eval | off | Aggregate per patient before eval |
--patient_agg | mean | Patient aggregation: mean or attention |
--augmentation | default | default (AugMix) or geometric |
--use_cv | off | Cross-validation |
--dynamic_alpha_beta | progressive | α/β schedule: static/progressive/cyclical |
The tabular pipeline treats clinical records as unordered sets of feature–value pairs, making the model invariant to measurement ordering and robust to variable-length records. The same architecture is evaluated on both benchmarks.
| Script | Evaluation dataset | Task |
|---|---|---|
benchmark_patient_level_v2.py | CARDIUM | CHD vs. control |
benchmark_thyroid_v2.py | ThyroidCineClip | Benign vs. malignant |
Clinical record (set of measurements)
→ Type-specific embedders (numeric / categorical / coded / temporal)
→ Permutation-invariant aggregation (Deep Sets: ρ ∘ Σφ)
→ [optional] Hypergraph layer (patient–feature–cell relationships)
→ Asymmetric Tversky similarity classifier
Type-specific modules:
| Module | Feature type | Method |
|---|---|---|
NumericEmbedder | Continuous values | Gaussian normalization + MLP |
CategoricalEmbedder | Discrete labels | Learned embeddings |
CodedEmbedder | ICD / LOINC / drug codes | Hierarchical ontology embeddings |
MonotonicEncoder | Ordered features | Monotone network (Lipschitz constrained) |
HypergraphLayer | All | Hyperedge message passing over patient–feature graph |
A clinical schema object encodes domain knowledge: valid ranges, feature types, monotonicity directions, and ontology hierarchy depths — but this can be replaced with a schema appropriate for any domain.
# CARDIUM
python benchmark_patient_level_v2.py \
--data_dir /path/to/CARDIUM \
--epochs 50 \
--batch_size 32
# ThyroidCineClip
python benchmark_thyroid_v2.py \
--data_dir ./thyroidultrasoundcineclip \
--epochs 50 \
--batch_size 32
The datasets below are used to evaluate the method; they are not requirements for using the code.
CARDIUM — fetal cardiac ultrasound + clinical records:
cardium_data/
├── cardium_images.tar.gz
├── delfos_clinical_data_woe_wnm_standarized_f_normalized.json
└── delfos_clinical_data_wnm_translated_final_cleaned.json
Download: https://github.com/BCV-Uniandes/Cardium
ThyroidCineClip — thyroid ultrasound cine-clips + metadata:
thyroidultrasoundcineclip/
├── dataset.hdf5
└── metadata.csv
Download: https://stanfordaimi.azurewebsites.net/datasets/thyroid-disease
All evaluation is patient-level: image-level scores are aggregated per patient before computing metrics.
| Metric | Description |
|---|---|
| AUC-ROC | Primary model selection criterion |
| F1 @ 0.5 | Balanced precision/recall |
| Sensitivity | Recall for positive-class patients |
| Specificity | True negative rate |
Results are reported as mean ± std across cross-validation folds.
9 commits
Python
100.0%