def test_regularized_logstic_cost_function_val(self): x_train = TEST_DATA['rcost']['x_train'] y_train = TEST_DATA['rcost']['y_train'] w = TEST_DATA['rcost']['w'] reg_lambda = TEST_DATA['rcost']['lambda'] val = TEST_DATA['rcost']['L'] val_computed, _ = regularized_logistic_cost_function( w, x_train, y_train, reg_lambda) self.assertAlmostEqual(val, val_computed, 6)
def test_regularized_logstic_cost_function_grad(self): x_train = TEST_DATA['rcost']['x_train'] y_train = TEST_DATA['rcost']['y_train'] w = TEST_DATA['rcost']['w'] reg_lambda = TEST_DATA['rcost']['lambda'] grad = TEST_DATA['rcost']['grad'] _, grad_computed = regularized_logistic_cost_function( w, x_train, y_train, reg_lambda) max_diff = np.max(np.abs(grad - grad_computed)) self.assertAlmostEqual(max_diff, 0, 6)
def test_regularized_logstic_cost_function_grad(self): w = TEST_DATA['rcost']['w'] x_train = TEST_DATA['rcost']['x_train'] y_train = TEST_DATA['rcost']['y_train'] reg_lambda = TEST_DATA['rcost']['lambda'] grad_expected = TEST_DATA['rcost']['grad'] _, grad = regularized_logistic_cost_function(w, x_train, y_train, reg_lambda) self.assertEqual(np.shape(grad), (20, 1)) np.testing.assert_almost_equal(grad, grad_expected)
def test_regularized_logstic_cost_function_val(self): w = TEST_DATA['rcost']['w'] x_train = TEST_DATA['rcost']['x_train'] y_train = TEST_DATA['rcost']['y_train'] reg_lambda = TEST_DATA['rcost']['lambda'] val_expected = TEST_DATA['rcost']['L'] val, _ = regularized_logistic_cost_function(w, x_train, y_train, reg_lambda) self.assertEqual(np.size(val), 1) self.assertAlmostEqual(val, val_expected)