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

Function test_squared_error_grad

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

Source from the content-addressed store, hash-verified

337
338
339def test_squared_error_grad(N=15):
340 from numpy_ml.neural_nets.losses import SquaredError
341 from numpy_ml.neural_nets.activations import Tanh
342
343 np.random.seed(12345)
344
345 N = np.inf if N is None else N
346
347 mine = SquaredError()
348 gold = torch_mse_grad
349 act = Tanh()
350
351 i = 1
352 while i < N:
353 n_dims = np.random.randint(2, 100)
354 n_examples = np.random.randint(1, 1000)
355 y = random_tensor((n_examples, n_dims))
356
357 # raw inputs
358 z = random_tensor((n_examples, n_dims))
359 y_pred = act.fn(z)
360
361 assert_almost_equal(
362 mine.grad(y, y_pred, z, act), 0.5 * gold(y, z, torch.tanh), decimal=4
363 )
364 print("PASSED")
365 i += 1
366
367
368def test_cross_entropy_grad(N=15):

Callers

nothing calls this directly

Calls 5

fnMethod · 0.95
gradMethod · 0.95
SquaredErrorClass · 0.90
TanhClass · 0.90
random_tensorFunction · 0.90

Tested by

no test coverage detected