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!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

92 lines
2.3KB

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