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 kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

51 Zeilen
1.5KB

  1. from icosagon.fastmodel import FastModel
  2. from icosagon.data import Data
  3. from icosagon.trainprep import prepare_training, \
  4. TrainValTest
  5. import torch
  6. import time
  7. def _make_symmetric(x: torch.Tensor):
  8. x = (x + x.transpose(0, 1)) / 2
  9. return x
  10. def _symmetric_random(n_rows, n_columns):
  11. return _make_symmetric(torch.rand((n_rows, n_columns),
  12. dtype=torch.float32).round().to_sparse())
  13. def _some_data_with_interactions():
  14. d = Data()
  15. d.add_node_type('Gene', 1000)
  16. d.add_node_type('Drug', 100)
  17. fam = d.add_relation_family('Drug-Gene', 1, 0, True)
  18. fam.add_relation_type('Target',
  19. torch.rand((100, 1000), dtype=torch.float32).round().to_sparse())
  20. fam = d.add_relation_family('Gene-Gene', 0, 0, True)
  21. fam.add_relation_type('Interaction',
  22. _symmetric_random(1000, 1000))
  23. fam = d.add_relation_family('Drug-Drug', 1, 1, True)
  24. for i in range(500):
  25. fam.add_relation_type('Side Effect: Nausea %d' % i,
  26. _symmetric_random(100, 100))
  27. fam.add_relation_type('Side Effect: Infertility %d' % i,
  28. _symmetric_random(100, 100))
  29. fam.add_relation_type('Side Effect: Death %d' % i,
  30. _symmetric_random(100, 100))
  31. return d
  32. def test_fast_model_01():
  33. d = _some_data_with_interactions()
  34. prep_d = prepare_training(d, TrainValTest(.8, .1, .1))
  35. model = FastModel(prep_d)
  36. for i in range(10):
  37. t = time.time()
  38. _ = model(None)
  39. print('Model forward took:', time.time() - t)