def test_unweighted(self): self.setup() logcosh_obj = metrics.Logcosh() self.evaluate(variables.variables_initializer(logcosh_obj.variables)) update_op = logcosh_obj.update_state(self.y_true, self.y_pred) self.evaluate(update_op) result = logcosh_obj.result() expected_result = np.sum(self.expected_results) / self.batch_size self.assertAllClose(result, expected_result, atol=1e-3)
def test_weighted(self): self.setup() logcosh_obj = metrics.Logcosh() self.evaluate(variables.variables_initializer(logcosh_obj.variables)) sample_weight = constant_op.constant([1.2, 3.4], shape=(2, 1)) result = logcosh_obj(self.y_true, self.y_pred, sample_weight=sample_weight) sample_weight = np.asarray([1.2, 1.2, 1.2, 3.4, 3.4, 3.4]).reshape((2, 3)) expected_result = np.multiply(self.expected_results, sample_weight) expected_result = np.sum(expected_result) / np.sum(sample_weight) self.assertAllClose(self.evaluate(result), expected_result, atol=1e-3)
def test_config(self): logcosh_obj = metrics.Logcosh(name='logcosh', dtype=dtypes.int32) self.assertEqual(logcosh_obj.name, 'logcosh') self.assertEqual(logcosh_obj._dtype, dtypes.int32)