IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.8KB

  1. from triacontagon.data import Data
  2. from triacontagon.sampling import get_true_classes, \
  3. negative_sample_adj_mat, \
  4. negative_sample_data
  5. from triacontagon.decode import dedicom_decoder
  6. import torch
  7. import time
  8. def test_get_true_classes_01():
  9. adj_mat = torch.tensor([
  10. [0, 1, 0, 1, 0],
  11. [0, 0, 0, 0, 1],
  12. [1, 1, 0, 0, 0],
  13. [0, 0, 1, 0, 1],
  14. [0, 1, 0, 0, 0]
  15. ], dtype=torch.float).to_sparse()
  16. true_classes, row_count = get_true_classes(adj_mat)
  17. print('true_classes:', true_classes)
  18. true_classes = torch.repeat_interleave(true_classes, row_count, dim=0)
  19. assert torch.all(true_classes == torch.tensor([
  20. [1, 3],
  21. [1, 3],
  22. [4, -1],
  23. [0, 1],
  24. [0, 1],
  25. [2, 4],
  26. [2, 4],
  27. [1, -1]
  28. ]))
  29. def test_get_true_classes_02():
  30. adj_mat = torch.rand(2000, 2000).round().to_sparse()
  31. t = time.time()
  32. true_classes, row_count = get_true_classes(adj_mat)
  33. print('Elapsed:', time.time() - t)
  34. print('true_classes.shape:', true_classes.shape)
  35. def test_negative_sample_adj_mat_01():
  36. adj_mat = torch.tensor([
  37. [0, 1, 0, 1, 0],
  38. [0, 0, 0, 0, 1],
  39. [1, 1, 0, 0, 0],
  40. [0, 0, 1, 0, 1],
  41. [0, 1, 0, 0, 0]
  42. ])
  43. print('adj_mat:', adj_mat)
  44. adj_mat_neg = negative_sample_adj_mat(adj_mat.to_sparse())
  45. print('adj_mat_neg:', adj_mat_neg.to_dense())
  46. def test_negative_sample_data_01():
  47. d = Data()
  48. d.add_vertex_type('Gene', 5)
  49. d.add_edge_type('Gene-Gene', 0, 0, [
  50. torch.tensor([
  51. [0, 1, 0, 1, 0],
  52. [0, 0, 0, 0, 1],
  53. [1, 1, 0, 0, 0],
  54. [0, 0, 1, 0, 1],
  55. [0, 1, 0, 0, 0]
  56. ], dtype=torch.float).to_sparse()
  57. ], dedicom_decoder)
  58. d_neg = negative_sample_data(d)