MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / test_cross_entropy

Function test_cross_entropy

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

Source from the content-addressed store, hash-verified

115
116
117def 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
147def test_VAE_loss(N=15):

Callers

nothing calls this directly

Calls 4

lossMethod · 0.95
CrossEntropyClass · 0.90
random_one_hot_matrixFunction · 0.90
random_stochastic_matrixFunction · 0.90

Tested by

no test coverage detected