Пример #1
0
 def test_bad_norm_raise_error(self):
     reg_vals = np.array([1, 2, 3, 4, 5])
     with self.assertRaisesRegex(ValueError,
                                 '(?i)Unrecognized.*bad_norm_name'):
         _ = utils.apply_regularization_loss('bad_norm_name', reg_vals)
Пример #2
0
 def test_lpnorm_2_equal_to_l2norm(self):
     reg_vals = np.array([1, 2, 3, 4, 5])
     reg_loss_l2 = utils.apply_regularization_loss('l2_norm', reg_vals)
     reg_loss_lp = utils.apply_regularization_loss('lp_norm', reg_vals, 2)
     self.assertEqual(reg_loss_l2, reg_loss_lp)
Пример #3
0
 def test_apply_lpnorm_5(self):
     reg_vals = np.array([1, 2, 3, 4, 5])
     reg_loss = utils.apply_regularization_loss('lp_norm', reg_vals, 5)
     self.assertAlmostEqual(reg_loss, 5.36022, delta=1e-5)
Пример #4
0
 def test_lpnorm_1_equal_to_l1norm(self):
     reg_vals = np.array([1, 2, 3, 4, 5])
     reg_loss_l1 = utils.apply_regularization_loss('l1_norm', reg_vals)
     reg_loss_lp = utils.apply_regularization_loss('lp_norm', reg_vals, 1)
     self.assertEqual(reg_loss_l1, reg_loss_lp)
Пример #5
0
 def test_apply_l2norm(self):
     reg_vals = np.array([1, 2, 3, 4, 5])
     reg_loss = utils.apply_regularization_loss('l2_norm', reg_vals)
     self.assertEqual(reg_loss, np.sqrt(55))