Implement the triplet margin loss with squared L2 distances.
Signature: def triplet_loss(anchor: np.ndarray, positive: np.ndarray, negative: np.ndarray, margin: float = 1.0) -> float
Formula: max(0, ||a - p||^2 - ||a - n||^2 + margin)
Math
Related problems
Asked at
import numpy as np
def triplet_loss(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?