DeepEMDAlgorithm<T, TInput, TOutput>
Models & Types · AiDotNet.MetaLearning.Algorithms
Implementation of DeepEMD (Earth Mover’s Distance for Few-Shot Learning).
Inheritance: ModelBase<T, TInput, TOutput> → MetaLearnerBase<T, TInput, TOutput> → DeepEMDAlgorithm<T, TInput, TOutput>
For Beginners
DeepEMD measures similarity like a puzzle matching game:
How it works:
- Break each example into local “parts” (features at different spatial positions)
- For each query-support pair, find the optimal matching of parts
- The Earth Mover’s Distance = minimum total cost to match all parts
- Classify by finding the support class with smallest EMD
Analogy: Moving dirt piles Imagine two arrangements of dirt piles. EMD measures the minimum amount of work (weight x distance) needed to reshape one arrangement into the other. Small EMD = similar arrangements = similar examples.
Why optimal transport?
- Handles part-to-part correspondences (left wing of bird A matches right wing of bird B)
- Robust to spatial misalignment
- Captures structural similarity that global features miss
The Sinkhorn algorithm: Computing exact EMD is expensive. Sinkhorn approximation adds entropy regularization, making it fast and differentiable for gradient-based training.
How It Works
DeepEMD computes optimal transport distances between sets of local features from support and query examples. This captures fine-grained structural similarity that simpler metrics (cosine, Euclidean) cannot represent.
Algorithm - DeepEMD:
Reference: Zhang, C., Cai, Y., Lin, G., & Shen, C. (2020). DeepEMD: Few-Shot Image Classification with Differentiable Earth Mover’s Distance and Structured Classifiers. CVPR 2020.
Constructors
| Constructor | Summary |
|---|---|
DeepEMDAlgorithm(DeepEMDOptions<T, TInput, TOutput> options) |
Initializes a new DeepEMD meta-learner. |
Properties
| Property | Summary |
|---|---|
MetaLearningAlgorithmType AlgorithmType { get; } |
Methods
| Method | Summary |
|---|---|
IModel<TInput, TOutput, ModelMetadata<T>> Adapt(IMetaLearningTask<T, TInput, TOutput> task) |
Adapts to a new task using EMD-based nearest-class classification. |
T MetaTrain(TaskBatch<T, TInput, TOutput> taskBatch) |
Performs one meta-training step for DeepEMD. |