(N=15)
| 82 | |
| 83 | |
| 84 | def test_squared_error(N=15): |
| 85 | from numpy_ml.neural_nets.losses import SquaredError |
| 86 | |
| 87 | np.random.seed(12345) |
| 88 | |
| 89 | N = np.inf if N is None else N |
| 90 | |
| 91 | mine = SquaredError() |
| 92 | gold = ( |
| 93 | lambda y, y_pred: mean_squared_error(y, y_pred) |
| 94 | * y_pred.shape[0] |
| 95 | * y_pred.shape[1] |
| 96 | * 0.5 |
| 97 | ) |
| 98 | |
| 99 | # ensure we get 0 when the two arrays are equal |
| 100 | n_dims = np.random.randint(2, 100) |
| 101 | n_examples = np.random.randint(1, 1000) |
| 102 | y = y_pred = random_tensor((n_examples, n_dims)) |
| 103 | assert_almost_equal(mine.loss(y, y_pred), gold(y, y_pred)) |
| 104 | print("PASSED") |
| 105 | |
| 106 | i = 1 |
| 107 | while i < N: |
| 108 | n_dims = np.random.randint(2, 100) |
| 109 | n_examples = np.random.randint(1, 1000) |
| 110 | y = random_tensor((n_examples, n_dims)) |
| 111 | y_pred = random_tensor((n_examples, n_dims)) |
| 112 | assert_almost_equal(mine.loss(y, y_pred), gold(y, y_pred), decimal=5) |
| 113 | print("PASSED") |
| 114 | i += 1 |
| 115 | |
| 116 | |
| 117 | def test_cross_entropy(N=15): |
nothing calls this directly
no test coverage detected