Metric learning is a branch of machine learning focused on learning a distance function over objects. Rather than learning to classify inputs directly, the model learns an embedding space where the computed distance between semantically similar items is small and the distance between dissimilar items is large. This is typically achieved through loss functions like triplet loss or contrastive loss that explicitly optimize relative distances between anchor, positive, and negative samples.
Glossary
Metric Learning

What is Metric Learning?
Metric learning is a machine learning paradigm that learns a distance function to measure similarity between data points, mapping similar items close together and dissimilar items far apart in an embedding space.
In the context of few-shot device enrollment, metric learning enables authentication systems to compare a new RF transmission against a minimal support set of enrolled device signatures. Architectures like Siamese networks and Prototypical networks leverage learned distance metrics to determine whether an emitter matches a known identity, making them essential for open set recognition where unknown or spoofed devices must be rejected based on their distance from legitimate class prototypes.
Key Characteristics of Metric Learning
Metric learning fundamentally shifts the paradigm from learning explicit classifiers to learning a task-optimal distance function. The following characteristics define how these systems structure data to make similar items proximal and dissimilar items distant in an embedding space.
Distance-Based Objective
Unlike traditional classification which learns decision boundaries, metric learning optimizes a distance function directly. The goal is to ensure that the computed distance—often Euclidean or cosine similarity—between semantically similar inputs is minimized, while the distance between dissimilar inputs is maximized. This is typically enforced through contrastive loss or triplet loss functions that operate on pairs or triplets of data points, penalizing the model when relative distances violate a defined margin.
Contrastive Pair Formation
Training relies on the strategic sampling of data tuples rather than individual samples. Key formations include:
- Positive Pairs: Two samples from the same class (e.g., two RF bursts from the same transmitter).
- Negative Pairs: Samples from different classes.
- Triplets: An anchor, a positive match, and a negative match. The selection of hard negatives—dissimilar samples that are currently close in the embedding space—is critical for fast convergence and robust feature learning.
Embedding Space Geometry
The output of a metric learning model is a mapping to a high-dimensional embedding space where distances are semantically meaningful. This space is structured such that:
- Clusters form for each distinct identity or class.
- Intra-class variance is minimized, pulling all instances of a specific emitter into a tight sphere.
- Inter-class separation is maximized, pushing different identities apart. This geometry enables efficient nearest-neighbor search for identification tasks, even for classes never seen during training.
Generalization to Novel Classes
A defining advantage of metric learning is its ability to perform open set recognition and few-shot generalization. Because the model learns a universal similarity function rather than a fixed set of class weights, it can compare a query sample against a support set of entirely new, previously unseen classes at inference time. This is foundational for few-shot device enrollment, where a new transmitter can be registered with only one or a few examples without retraining the entire network.
Proxy-Based Computational Efficiency
To avoid the combinatorial explosion of pairwise comparisons in large datasets, modern metric learning often employs proxy-based losses such as Proxy-NCA or Proxy Anchor Loss. Instead of comparing every sample against all others, each class is represented by a learnable proxy vector. The model only compares data embeddings to these limited proxies, drastically reducing training complexity from O(N²) to O(N) while maintaining high retrieval accuracy and tight clustering behavior.
Angular Margin Penalties
Advanced metric learning objectives incorporate additive angular margin penalties to enforce stricter intra-class compactness. Techniques like ArcFace or CosFace normalize both the feature embeddings and the class proxy weights, then add a multiplicative or additive angular margin to the target class logit. This forces the model to produce embeddings that are not only closer to their correct proxy but also separated by a precise angular gap, significantly hardening the decision boundary against impostor samples.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about distance-based machine learning and its role in few-shot device authentication.
Metric learning is a branch of machine learning focused on learning a distance function over objects, such that the computed distance between similar items is small and between dissimilar items is large. Unlike traditional classification which learns decision boundaries, metric learning explicitly optimizes an embedding space where semantic relationships are encoded as geometric distances. The process works by training a neural network to map raw inputs—such as images, signals, or text—into dense vector representations, then applying a loss function like triplet loss or contrastive loss to pull similar pairs together and push dissimilar pairs apart. This learned distance metric enables tasks like few-shot recognition, where a model can compare a new query sample to a small support set of labeled examples and determine identity based on proximity in the embedding space. For radio frequency fingerprinting, metric learning allows a system to authenticate a device by measuring how close its signal embedding is to a stored enrollment template, even when only one or two enrollment samples are available.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Metric learning forms the mathematical foundation for few-shot device enrollment. These related terms define the architectures, loss functions, and evaluation frameworks that enable neural networks to authenticate devices from minimal examples.
Triplet Loss
A contrastive loss function that structures the embedding space by enforcing a margin-based relationship between three samples:
- Anchor: A reference sample from a specific class
- Positive: Another sample from the same class as the anchor
- Negative: A sample from a different class
The loss minimizes the distance between the anchor and positive while ensuring the negative is at least a margin α farther away than the positive. Formally: L = max(d(a,p) - d(a,n) + α, 0). This directly trains the network to create clusters where intra-class distances are small and inter-class distances are large, making it ideal for device fingerprinting where each transmitter forms its own class.
Prototypical Networks
A metric-based few-shot learning architecture that represents each class by a single prototype vector: the mean of its support set embeddings in the learned metric space.
Classification proceeds by:
- Embedding all support samples through the network
- Computing the centroid (prototype) for each class
- Classifying query samples by finding the nearest prototype via Euclidean distance
For device enrollment, a new transmitter's prototype can be computed from as few as 1-5 RF fingerprint samples, enabling rapid onboarding without retraining the entire network. The non-parametric nature of the classifier means new device classes can be added instantly.
Siamese Networks
A twin-network architecture composed of two identical subnetworks that share weights and process pairs of inputs in parallel to determine their similarity.
Key characteristics:
- Both branches apply the exact same transformation to their respective inputs
- The outputs are two embedding vectors compared via a distance function (e.g., L1, cosine)
- The final layer outputs a similarity score between 0 and 1
- Trained with contrastive loss or binary cross-entropy on paired data
In RF fingerprinting, Siamese networks excel at verification tasks: given two signal samples, determine if they originated from the same physical transmitter. This pairwise approach is data-efficient and naturally handles open-set scenarios.
Embedding Space
A lower-dimensional continuous vector space where semantically similar data points are mapped close together, enabling distance-based comparison and clustering.
Critical properties for device authentication:
- Dimensionality: Typically 64-512 dimensions, balancing expressiveness with computational efficiency
- Compactness: Intra-class variance is minimized; all samples from one transmitter form a tight cluster
- Separability: Inter-class distance is maximized; different transmitters occupy distinct regions
- Smoothness: Small perturbations in input space produce small displacements in embedding space
The embedding space serves as the mathematical foundation for all distance-based authentication decisions. Its quality directly determines False Acceptance Rate (FAR) and False Rejection Rate (FRR).
Cosine Similarity
A normalized similarity measure between two non-zero vectors that calculates the cosine of the angle between them, ranging from -1 (opposite) to 1 (identical).
Formula: cos(θ) = (A·B) / (||A|| × ||B||)
Advantages over Euclidean distance for RF fingerprinting:
- Magnitude-invariant: Focuses on directional similarity, ignoring vector length variations caused by signal power differences
- Bounded range: Outputs are naturally normalized to [-1, 1], simplifying threshold selection
- Efficient computation: Requires only dot product and L2 norm operations
Often used as the final comparison metric in Siamese networks and as an alternative to Euclidean distance in Prototypical Networks when signal amplitude varies significantly across capture sessions.
Episode-Based Training
A meta-learning training strategy where each iteration simulates a complete few-shot task by sampling a small support set and query set from the overall dataset.
Each episode:
- Randomly selects N classes from the training set
- Samples K support examples and M query examples per class (an N-way K-shot task)
- The model learns to classify the query set using only the support set
- Loss is computed on query predictions and backpropagated
This train-to-learn paradigm explicitly optimizes for rapid adaptation rather than memorization. For device enrollment, episodes mirror real deployment: the model sees a few examples of new transmitters and must immediately authenticate them, matching the exact inference-time distribution.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us