Skip to content

Commit 3805615

Browse files
committed
Added Cosine Distance example code
1 parent 9cd569d commit 3805615

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import numpy as np
2+
3+
4+
class CosineDistance:
5+
6+
def __call__(self, y: np.ndarray, y_pred: np.ndarray) -> np.ndarray:
7+
return self.loss(y, y_pred)
8+
9+
def loss(self, y: np.ndarray, y_pred: np.ndarray) -> np.float64:
10+
return np.dot(y, y_pred) / (np.linalg.norm(y) * np.linalg.norm(y_pred))

0 commit comments

Comments
 (0)