Metric learning
Here we introduce several metric learning methods.
Siamese network and its loss function
![](/Notes/assets/machine_learning/siamese_net.png)
Siamese network is used to learn similarity of two inputs. It feeds two inputs to two networks (these two nets have same architecture and weights) and output two feature vectors for similarity measurement (e.g. cosine, l2-distance). Then the measurement will be calculated by contrastive loss.
Here is the contrastive loss
where is similarity measurement. is a margin hyperparameter. means the inputs should be similar. means the inputs should different, and when is larger than , then there is no loss penalty.
Triplet network and its loss function
The triplet network is very similar with siamese network. It just uses three inputs: anchor, positive and negative instances.
![](/Notes/assets/machine_learning/triplet_net.png)
The triplet loss is
where is the similarity measurement (distance function). When , there is no loss penalty.