Ejemplo n.º 1
0
 def test_weighted_mean_semantics(self):
     inputs = onp.array([1, 2, 3], dtype=onp.float32)
     weights1 = onp.array([1, 1, 1], dtype=onp.float32)
     layer = metrics.WeightedMean()
     full_signature = (signature(inputs), signature(weights1))
     layer.initialize_once(full_signature)
     mean1 = layer((inputs, weights1))
     onp.testing.assert_allclose(mean1, 2.0)
     weights2 = onp.array([0, 0, 1], dtype=onp.float32)
     mean2 = layer((inputs, weights2))
     onp.testing.assert_allclose(mean2, 3.0)
     weights3 = onp.array([1, 0, 0], dtype=onp.float32)
     mean3 = layer((inputs, weights3))
     onp.testing.assert_allclose(mean3, 1.0)
Ejemplo n.º 2
0
 def test_weighted_mean_semantics(self):
   inputs = onp.array([1, 2, 3], dtype=onp.float32)
   weights1 = onp.array([1, 1, 1], dtype=onp.float32)
   layer = metrics.WeightedMean()
   rng = backend.random.get_prng(0)
   layer.initialize_once((inputs.shape, weights1.shape),
                         (inputs.dtype, weights1.dtype), rng)
   mean1 = layer((inputs, weights1))
   onp.testing.assert_allclose(mean1, 2.0)
   weights2 = onp.array([0, 0, 1], dtype=onp.float32)
   mean2 = layer((inputs, weights2))
   onp.testing.assert_allclose(mean2, 3.0)
   weights3 = onp.array([1, 0, 0], dtype=onp.float32)
   mean3 = layer((inputs, weights3))
   onp.testing.assert_allclose(mean3, 1.0)
Ejemplo n.º 3
0
 def test_weighted_mean_shape(self):
   input_shape = ((29, 4, 4, 20), (29, 4, 4, 20))
   result_shape = base.check_shape_agreement(
       metrics.WeightedMean(), input_shape)
   self.assertEqual(result_shape, ())