Verification is the final gate before a cryptographic key is released. When a new fMRI scan arrives, Neural Vault normalizes it with the enrolled user’s statistics, runs it through the trained Transformer encoder to obtain an embedding, and computes the cosine similarity of that embedding against the stored prototype vector. If the similarity exceeds the Equal Error Rate threshold determined during enrollment, the user is authenticated and a 256-bit key is derived. If it falls short, the session is rejected without any key material being produced.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Skieriya/fMRI-key-generation-with-TRIBEv2/llms.txt
Use this file to discover all available pages before exploring further.
Getting an Embedding from Raw Data
get_embedding in model.py is the inference entry point. It applies per-feature normalization using statistics (feat_mean, feat_std) that were computed at enrollment time — never from the current scan — then builds temporal sequences and runs the model:
if len(seqs) == 0) handles the edge case where the input has fewer rows than SEQ_CHUNK. In that case the scan is tiled to reach the minimum window size. The final emb.mean(dim=0) collapses all sequence windows into a single representative embedding vector before returning it.
Because the model outputs L2-normalized embeddings (every vector has unit length), the dot product between any two embedding vectors is exactly their cosine similarity. No explicit cosine computation is needed —
np.dot(emb, prototype_vec) is sufficient.Verification Function
verify combines embedding extraction and similarity scoring into a single call:
[-1.0, 1.0]. A score near 1.0 means the scan is nearly identical to the enrolled prototype in embedding space; a score near 0.0 or below indicates an impostor or a badly degraded scan.
Batch Similarity Scoring for Benchmarking
verify_similarity in main.py evaluates the full score distribution over an embedding matrix at once, separating scores into genuine (same-class) and impostor (different-class) arrays using scipy.spatial.distance.cdist:
cdist with metric='cosine' returns cosine distance (i.e., 1 - cosine_similarity), so lower values indicate better matches. The returned arrays are used to sweep the ROC curve and locate the EER threshold.
EER Threshold Derivation
The Equal Error Rate threshold is the operating point at which the False Acceptance Rate equals the False Rejection Rate. It is computed from the ROC curve inmain.py:
np.argmin(np.abs(fpr_v - (1.0 - tpr_v))) finds the threshold index where FPR and FNR (= 1 - TPR) are closest to each other. The benchmark pipeline reports this threshold at approximately 0.316.
Authentication Decision
The end-to-end authentication flow frommodel.py demonstrates how the threshold gates key derivation:
derive_key call is gated entirely behind the threshold check.
Full Verification Flow
Normalize the incoming scan
Apply z-score normalization using the enrolled user’s stored Using enrollment-time statistics ensures the normalization is consistent regardless of the current session’s signal distribution.
feat_mean and feat_std:Build temporal sequences
Chunk the normalized scan into windows of length If the scan is shorter than one window, tile it to meet the minimum length requirement.
SEQ_CHUNK (5 frames):Run the Transformer encoder
Pass the sequence tensor through the trained model to obtain L2-normalized embeddings, then average across all windows:
Compute cosine similarity
Compute the dot product of the query embedding with the enrolled prototype vector:Because both vectors are L2-normalized, this equals their cosine similarity.
Few-Shot Classification Evaluation
For multi-class scenarios,evaluate_fewshot classifies a query embedding by finding its nearest class prototype via Euclidean distance in embedding space:
X_train) within each episode rather than from pre-stored values. torch.argmin(dists, dim=1) selects the class whose prototype is closest; F.softmax(-dists, dim=1) converts distances to probabilities for ROC-AUC computation.
Benchmark Metrics
The benchmark results from running 40 few-shot episodes on5classpreds.csv confirm strong biometric performance:
| Metric | Value |
|---|---|
| Accuracy (40 episodes) | 98.12% |
| Macro F1 | 0.9810 |
| ROC-AUC | 0.9995 |
| FAR @ EER | ≈ 0.75% |
| FRR @ EER | ≈ 0.75% |
| EER threshold (cosine sim) | ≈ 0.316 |
model.py.