Added explicit average-distance calculation
Browse files- compare-allids-embeds.py +13 -2
compare-allids-embeds.py
CHANGED
|
@@ -41,6 +41,9 @@ if torch.equal(embs1 , embs2):
|
|
| 41 |
print("HEY! Both files are identical!")
|
| 42 |
exit(0)
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
print(f"calculating distances...")
|
| 45 |
|
| 46 |
# This calculates a full cross matrix of ALL distances to ALL other points
|
|
@@ -49,11 +52,19 @@ print(f"calculating distances...")
|
|
| 49 |
|
| 50 |
|
| 51 |
targetdistances = torch.norm(embs2 - embs1, dim=1)
|
| 52 |
-
print(targetdistances.shape)
|
| 53 |
#tl=targetdistances.tolist()
|
| 54 |
#print(tl[:10])
|
| 55 |
|
| 56 |
-
print("sum of distances=",torch.sum(targetdistances))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
import PyQt5
|
| 59 |
import matplotlib
|
|
|
|
| 41 |
print("HEY! Both files are identical!")
|
| 42 |
exit(0)
|
| 43 |
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
print(f"calculating distances...")
|
| 48 |
|
| 49 |
# This calculates a full cross matrix of ALL distances to ALL other points
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
targetdistances = torch.norm(embs2 - embs1, dim=1)
|
| 55 |
+
#print(targetdistances.shape)
|
| 56 |
#tl=targetdistances.tolist()
|
| 57 |
#print(tl[:10])
|
| 58 |
|
| 59 |
+
print("sum of all distances=",torch.sum(targetdistances))
|
| 60 |
+
|
| 61 |
+
embs1_avg=torch.mean(embs1,dim=0)
|
| 62 |
+
embs2_avg=torch.mean(embs2,dim=0)
|
| 63 |
+
avg_dist= torch.cdist( embs1_avg.unsqueeze(0),embs2_avg.unsqueeze(0), p=2)
|
| 64 |
+
print("However, the distance between the avg-point of each is:",avg_dist)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
######################################
|
| 68 |
|
| 69 |
import PyQt5
|
| 70 |
import matplotlib
|