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!
ソースを参照

Added test for droput_sparse

master
Stanislaw Adaszewski 4年前
コミット
4d9809c176
6個のファイルの変更34行の追加0行の削除
  1. +0
    -0
      src/decagon_pytorch/__init__.py
  2. +0
    -0
      src/decagon_pytorch/convolve.py
  3. +0
    -0
      src/decagon_pytorch/dropout.py
  4. +0
    -0
      src/decagon_pytorch/model.py
  5. +0
    -0
      src/decagon_pytorch/weights.py
  6. +34
    -0
      tests/decagon_pytorch/test_dropout.py

decagon_pytorch/__init__.py → src/decagon_pytorch/__init__.py ファイルの表示


decagon_pytorch/convolve.py → src/decagon_pytorch/convolve.py ファイルの表示


decagon_pytorch/dropout.py → src/decagon_pytorch/dropout.py ファイルの表示


decagon_pytorch/model.py → src/decagon_pytorch/model.py ファイルの表示


decagon_pytorch/weights.py → src/decagon_pytorch/weights.py ファイルの表示


+ 34
- 0
tests/decagon_pytorch/test_dropout.py ファイルの表示

@@ -0,0 +1,34 @@
from decagon_pytorch.dropout import dropout_sparse
import torch
import numpy as np
def dropout_dense(a, keep_prob):
i = np.array(np.where(a))
v = a[i[0, :], i[1, :]]
# torch.random.manual_seed(0)
n = keep_prob + torch.rand(len(v))
n = torch.floor(n).to(torch.bool)
i = i[:, n]
v = v[n]
x = torch.sparse_coo_tensor(i, v, size=a.shape)
return x * (1./keep_prob)
def test_dropout_sparse():
for i in range(11):
torch.random.manual_seed(i)
a = torch.rand((5, 10))
a[a < .5] = 0
keep_prob=i/10. + np.finfo(np.float32).eps
torch.random.manual_seed(i)
b = dropout_dense(a, keep_prob=keep_prob)
torch.random.manual_seed(i)
c = dropout_sparse(a.to_sparse(), keep_prob=keep_prob)
assert np.all(np.array(b.to_dense()) == np.array(c.to_dense()))

読み込み中…
キャンセル
保存