(N=15)
| 115 | |
| 116 | |
| 117 | def test_cross_entropy(N=15): |
| 118 | from numpy_ml.neural_nets.losses import CrossEntropy |
| 119 | |
| 120 | np.random.seed(12345) |
| 121 | |
| 122 | N = np.inf if N is None else N |
| 123 | |
| 124 | mine = CrossEntropy() |
| 125 | gold = log_loss |
| 126 | |
| 127 | # ensure we get 0 when the two arrays are equal |
| 128 | n_classes = np.random.randint(2, 100) |
| 129 | n_examples = np.random.randint(1, 1000) |
| 130 | y = y_pred = random_one_hot_matrix(n_examples, n_classes) |
| 131 | assert_almost_equal(mine.loss(y, y_pred), gold(y, y_pred)) |
| 132 | print("PASSED") |
| 133 | |
| 134 | # test on random inputs |
| 135 | i = 1 |
| 136 | while i < N: |
| 137 | n_classes = np.random.randint(2, 100) |
| 138 | n_examples = np.random.randint(1, 1000) |
| 139 | y = random_one_hot_matrix(n_examples, n_classes) |
| 140 | y_pred = random_stochastic_matrix(n_examples, n_classes) |
| 141 | |
| 142 | assert_almost_equal(mine.loss(y, y_pred), gold(y, y_pred, normalize=False)) |
| 143 | print("PASSED") |
| 144 | i += 1 |
| 145 | |
| 146 | |
| 147 | def test_VAE_loss(N=15): |
nothing calls this directly
no test coverage detected