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.

86 lines
2.2KB

  1. import torch
  2. from triacontagon.model import Model, \
  3. TrainingBatch, \
  4. _per_layer_required_vertices
  5. from triacontagon.data import Data
  6. from triacontagon.decode import dedicom_decoder
  7. def test_per_layer_required_vertices_01():
  8. d = Data()
  9. d.add_vertex_type('Gene', 4)
  10. d.add_vertex_type('Drug', 5)
  11. d.add_edge_type('Gene-Gene', 0, 0, [ torch.tensor([
  12. [1, 0, 0, 1],
  13. [0, 1, 1, 0],
  14. [0, 0, 1, 0],
  15. [0, 1, 0, 1]
  16. ]).to_sparse() ], dedicom_decoder)
  17. d.add_edge_type('Gene-Drug', 0, 1, [ torch.tensor([
  18. [0, 1, 0, 0, 1],
  19. [0, 0, 1, 0, 0],
  20. [1, 0, 0, 0, 1],
  21. [0, 0, 1, 1, 0]
  22. ]).to_sparse() ], dedicom_decoder)
  23. d.add_edge_type('Drug-Drug', 1, 1, [ torch.tensor([
  24. [1, 0, 0, 0, 0],
  25. [0, 1, 0, 0, 0],
  26. [0, 0, 1, 0, 0],
  27. [0, 0, 0, 1, 0],
  28. [0, 0, 0, 0, 1]
  29. ]).to_sparse() ], dedicom_decoder)
  30. batch = TrainingBatch(0, 1, 0, torch.tensor([
  31. [0, 1]
  32. ]))
  33. res = _per_layer_required_vertices(d, batch, 5)
  34. print('res:', res)
  35. def test_model_convolve_01():
  36. d = Data()
  37. d.add_vertex_type('Gene', 4)
  38. d.add_vertex_type('Drug', 5)
  39. d.add_edge_type('Gene-Gene', 0, 0, [ torch.tensor([
  40. [1, 0, 0, 1],
  41. [0, 1, 1, 0],
  42. [0, 0, 1, 0],
  43. [0, 1, 0, 1]
  44. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  45. d.add_edge_type('Gene-Drug', 0, 1, [ torch.tensor([
  46. [0, 1, 0, 0, 1],
  47. [0, 0, 1, 0, 0],
  48. [1, 0, 0, 0, 1],
  49. [0, 0, 1, 1, 0]
  50. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  51. d.add_edge_type('Drug-Drug', 1, 1, [ torch.tensor([
  52. [1, 0, 0, 0, 0],
  53. [0, 1, 0, 0, 0],
  54. [0, 0, 1, 0, 0],
  55. [0, 0, 0, 1, 0],
  56. [0, 0, 0, 0, 1]
  57. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  58. model = Model(d, [9, 32, 64], keep_prob=1.0,
  59. conv_activation = torch.sigmoid,
  60. dec_activation = torch.sigmoid)
  61. repr_1 = torch.eye(9)
  62. repr_1[4:, 4:] = 0
  63. repr_2 = torch.eye(9)
  64. repr_2[:4, :4] = 0
  65. in_layer_repr = [
  66. repr_1[:4, :].to_sparse(),
  67. repr_2[4:, :].to_sparse()
  68. ]
  69. _ = model.convolve(in_layer_repr)