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.

87 Zeilen
2.5KB

  1. from icosagon.decode import DEDICOMDecoder, \
  2. DistMultDecoder, \
  3. BilinearDecoder, \
  4. InnerProductDecoder
  5. import decagon_pytorch.decode.pairwise
  6. import torch
  7. def test_dedicom_decoder_01():
  8. repr_ = torch.rand(20, 32)
  9. dec_1 = DEDICOMDecoder(32, 7, keep_prob=1.,
  10. activation=torch.sigmoid)
  11. dec_2 = decagon_pytorch.decode.pairwise.DEDICOMDecoder(32, 7, drop_prob=0.,
  12. activation=torch.sigmoid)
  13. dec_2.global_interaction = dec_1.global_interaction
  14. dec_2.local_variation = dec_1.local_variation
  15. res_1 = [ dec_1(repr_, repr_, k) for k in range(7) ]
  16. res_2 = dec_2(repr_, repr_)
  17. assert isinstance(res_1, list)
  18. assert isinstance(res_2, list)
  19. assert len(res_1) == len(res_2)
  20. for i in range(len(res_1)):
  21. assert torch.all(res_1[i] == res_2[i])
  22. def test_dist_mult_decoder_01():
  23. repr_ = torch.rand(20, 32)
  24. dec_1 = DistMultDecoder(32, 7, keep_prob=1.,
  25. activation=torch.sigmoid)
  26. dec_2 = decagon_pytorch.decode.pairwise.DistMultDecoder(32, 7, drop_prob=0.,
  27. activation=torch.sigmoid)
  28. dec_2.relation = dec_1.relation
  29. res_1 = [ dec_1(repr_, repr_, k) for k in range(7) ]
  30. res_2 = dec_2(repr_, repr_)
  31. assert isinstance(res_1, list)
  32. assert isinstance(res_2, list)
  33. assert len(res_1) == len(res_2)
  34. for i in range(len(res_1)):
  35. assert torch.all(res_1[i] == res_2[i])
  36. def test_bilinear_decoder_01():
  37. repr_ = torch.rand(20, 32)
  38. dec_1 = BilinearDecoder(32, 7, keep_prob=1.,
  39. activation=torch.sigmoid)
  40. dec_2 = decagon_pytorch.decode.pairwise.BilinearDecoder(32, 7, drop_prob=0.,
  41. activation=torch.sigmoid)
  42. dec_2.relation = dec_1.relation
  43. res_1 = [ dec_1(repr_, repr_, k) for k in range(7) ]
  44. res_2 = dec_2(repr_, repr_)
  45. assert isinstance(res_1, list)
  46. assert isinstance(res_2, list)
  47. assert len(res_1) == len(res_2)
  48. for i in range(len(res_1)):
  49. assert torch.all(res_1[i] == res_2[i])
  50. def test_inner_product_decoder_01():
  51. repr_ = torch.rand(20, 32)
  52. dec_1 = InnerProductDecoder(32, 7, keep_prob=1.,
  53. activation=torch.sigmoid)
  54. dec_2 = decagon_pytorch.decode.pairwise.InnerProductDecoder(32, 7, drop_prob=0.,
  55. activation=torch.sigmoid)
  56. res_1 = [ dec_1(repr_, repr_, k) for k in range(7) ]
  57. res_2 = dec_2(repr_, repr_)
  58. assert isinstance(res_1, list)
  59. assert isinstance(res_2, list)
  60. assert len(res_1) == len(res_2)
  61. for i in range(len(res_1)):
  62. assert torch.all(res_1[i] == res_2[i])