(N=15)
| 583 | |
| 584 | |
| 585 | def test_softmax_grad(N=15): |
| 586 | from numpy_ml.neural_nets.layers import Softmax |
| 587 | from functools import partial |
| 588 | |
| 589 | np.random.seed(12345) |
| 590 | |
| 591 | N = np.inf if N is None else N |
| 592 | p_soft = partial(F.softmax, dim=1) |
| 593 | gold = torch_gradient_generator(p_soft) |
| 594 | |
| 595 | i = 0 |
| 596 | while i < N: |
| 597 | mine = Softmax() |
| 598 | n_ex = np.random.randint(1, 3) |
| 599 | n_dims = np.random.randint(1, 50) |
| 600 | z = random_tensor((n_ex, n_dims), standardize=True) |
| 601 | out = mine.forward(z) |
| 602 | |
| 603 | assert_almost_equal( |
| 604 | gold(z), |
| 605 | mine.backward(np.ones_like(out)), |
| 606 | err_msg="Theirs:\n{}\n\nMine:\n{}\n".format( |
| 607 | gold(z), mine.backward(np.ones_like(out)) |
| 608 | ), |
| 609 | decimal=3, |
| 610 | ) |
| 611 | print("PASSED") |
| 612 | i += 1 |
| 613 | |
| 614 | |
| 615 | def test_softplus_grad(N=15): |
nothing calls this directly
no test coverage detected