MCPcopy
hub / github.com/ddbourgin/numpy-ml / test_squared_error

Function test_squared_error

numpy_ml/tests/test_nn.py:84–114  ·  view source on GitHub ↗
(N=15)

Source from the content-addressed store, hash-verified

82
83
84def 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
117def test_cross_entropy(N=15):

Callers

nothing calls this directly

Calls 3

lossMethod · 0.95
SquaredErrorClass · 0.90
random_tensorFunction · 0.90

Tested by

no test coverage detected