You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

distances.py 808 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import numpy as np
  2. def sum_squares(a, b):
  3. """
  4. Return the sum of squares of the difference between a and b, aka MSE
  5. """
  6. return np.sum([(a[i] - b[i])**2 for i in range(len(a))])
  7. def euclid_d(x, y):
  8. """
  9. 1D euclidean distance
  10. """
  11. return np.sqrt((x-y)**2)
  12. def man_d(x, y):
  13. """
  14. 1D manhattan distance
  15. """
  16. return np.abs((x-y))
  17. def classif_d(x, y):
  18. """
  19. Function adapted to classification problems
  20. """
  21. return np.array(0 if x == y else 1)
  22. def rmse(pred, ground_truth):
  23. import numpy as np
  24. return np.sqrt(sum_squares(pred, ground_truth)/len(ground_truth))
  25. def accuracy(pred, ground_truth):
  26. import numpy as np
  27. return np.mean([a == b for a, b in zip(pred, ground_truth)])
  28. def rbf_k(D, sigma=1):
  29. return np.exp(-(D**2)/sigma)

A Python package for graph kernels, graph edit distances and graph pre-image problem.