Exemplo n.º 1
0
    def test_config(self):
        poisson_obj = metrics.Poisson(name='poisson', dtype=dtypes.int32)
        self.assertEqual(poisson_obj.name, 'poisson')
        self.assertEqual(poisson_obj._dtype, dtypes.int32)

        poisson_obj2 = metrics.Poisson.from_config(poisson_obj.get_config())
        self.assertEqual(poisson_obj2.name, 'poisson')
        self.assertEqual(poisson_obj2._dtype, dtypes.int32)
Exemplo n.º 2
0
    def test_unweighted(self):
        self.setup()
        poisson_obj = metrics.Poisson()
        self.evaluate(variables.variables_initializer(poisson_obj.variables))

        update_op = poisson_obj.update_state(self.y_true, self.y_pred)
        self.evaluate(update_op)
        result = poisson_obj.result()
        expected_result = np.sum(self.expected_results) / self.batch_size
        self.assertAllClose(result, expected_result, atol=1e-3)
Exemplo n.º 3
0
  def test_weighted(self):
    self.setup()
    poisson_obj = metrics.Poisson()
    self.evaluate(variables.variables_initializer(poisson_obj.variables))
    sample_weight = constant_op.constant([1.2, 3.4], shape=(2, 1))

    result = poisson_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)