Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions neural_nets/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,26 @@ def test_sigmoid_activation(N=None):
i += 1


def test_elu_activation(N=None):
from activations import ELU

N = np.inf if N is None else N

i = 0
while i < N:
n_dims = np.random.randint(1, 10)
z = random_tensor((1, n_dims))

alpha = np.random.uniform(0, 10)

mine = ELU(alpha)
gold = lambda z, a: F.elu(torch.from_numpy(z), alpha).numpy()

assert_almost_equal(mine.fn(z), gold(z, alpha))
print("PASSED")
i += 1


def test_softmax_activation(N=None):
from layers import Softmax

Expand Down Expand Up @@ -524,6 +544,25 @@ def test_sigmoid_grad(N=None):
i += 1


def test_elu_grad(N=None):
from activations import ELU

N = np.inf if N is None else N

i = 0
while i < N:
n_ex = np.random.randint(1, 10)
n_dims = np.random.randint(1, 10)
alpha = np.random.uniform(0, 10)
z = random_tensor((n_ex, n_dims))

mine = ELU(alpha)
gold = torch_gradient_generator(F.elu, alpha=alpha)
assert_almost_equal(mine.grad(z), gold(z))
print("PASSED")
i += 1


def test_tanh_grad(N=None):
from activations import Tanh

Expand Down