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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

112 lignes
2.8KB

  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. from triacontagon.util import common_one_hot_encoding
  8. def test_per_layer_required_vertices_01():
  9. d = Data()
  10. d.add_vertex_type('Gene', 4)
  11. d.add_vertex_type('Drug', 5)
  12. d.add_edge_type('Gene-Gene', 0, 0, [ torch.tensor([
  13. [1, 0, 0, 1],
  14. [0, 1, 1, 0],
  15. [0, 0, 1, 0],
  16. [0, 1, 0, 1]
  17. ]).to_sparse() ], dedicom_decoder)
  18. d.add_edge_type('Gene-Drug', 0, 1, [ torch.tensor([
  19. [0, 1, 0, 0, 1],
  20. [0, 0, 1, 0, 0],
  21. [1, 0, 0, 0, 1],
  22. [0, 0, 1, 1, 0]
  23. ]).to_sparse() ], dedicom_decoder)
  24. d.add_edge_type('Drug-Drug', 1, 1, [ torch.tensor([
  25. [1, 0, 0, 0, 0],
  26. [0, 1, 0, 0, 0],
  27. [0, 0, 1, 0, 0],
  28. [0, 0, 0, 1, 0],
  29. [0, 0, 0, 0, 1]
  30. ]).to_sparse() ], dedicom_decoder)
  31. batch = TrainingBatch(0, 1, 0, torch.tensor([
  32. [0, 1]
  33. ]))
  34. res = _per_layer_required_vertices(d, batch, 5)
  35. print('res:', res)
  36. def test_model_convolve_01():
  37. d = Data()
  38. d.add_vertex_type('Gene', 4)
  39. d.add_vertex_type('Drug', 5)
  40. d.add_edge_type('Gene-Gene', 0, 0, [ torch.tensor([
  41. [1, 0, 0, 1],
  42. [0, 1, 1, 0],
  43. [0, 0, 1, 0],
  44. [0, 1, 0, 1]
  45. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  46. d.add_edge_type('Gene-Drug', 0, 1, [ torch.tensor([
  47. [0, 1, 0, 0, 1],
  48. [0, 0, 1, 0, 0],
  49. [1, 0, 0, 0, 1],
  50. [0, 0, 1, 1, 0]
  51. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  52. d.add_edge_type('Drug-Drug', 1, 1, [ torch.tensor([
  53. [1, 0, 0, 0, 0],
  54. [0, 1, 0, 0, 0],
  55. [0, 0, 1, 0, 0],
  56. [0, 0, 0, 1, 0],
  57. [0, 0, 0, 0, 1]
  58. ], dtype=torch.float).to_sparse() ], dedicom_decoder)
  59. model = Model(d, [9, 32, 64], keep_prob=1.0,
  60. conv_activation = torch.sigmoid,
  61. dec_activation = torch.sigmoid)
  62. repr_1 = torch.eye(9)
  63. repr_1[4:, 4:] = 0
  64. repr_2 = torch.eye(9)
  65. repr_2[:4, :4] = 0
  66. in_layer_repr = [
  67. repr_1[:4, :].to_sparse(),
  68. repr_2[4:, :].to_sparse()
  69. ]
  70. _ = model.convolve(in_layer_repr)
  71. def test_model_decode_01():
  72. d = Data()
  73. d.add_vertex_type('Gene', 100)
  74. d.add_edge_type('Gene-Gene', 0, 0, [
  75. torch.rand(100, 100).round().to_sparse()
  76. ], dedicom_decoder)
  77. b = TrainingBatch(0, 0, 0, torch.tensor([
  78. [0, 1],
  79. [10, 51],
  80. [50, 60],
  81. [70, 90],
  82. [98, 99]
  83. ]), torch.ones(5))
  84. in_repr = common_one_hot_encoding([100])
  85. in_repr = [ in_repr[0].to_dense() ]
  86. m = Model(d, [100], 1.0, torch.sigmoid, torch.sigmoid)
  87. _ = m.decode(in_repr, b)