コード例 #1
0
  def test_interpolate_preset(self, points, weights, indices, _, out):
    """Tests whether interpolation results are correct."""
    weights = tf.convert_to_tensor(value=weights)

    result_unnormalized = weighted.interpolate(
        points=points, weights=weights, indices=indices, normalize=False)
    result_normalized = weighted.interpolate(
        points=points, weights=2.0 * weights, indices=indices, normalize=True)
    estimated_unnormalized = self.evaluate(result_unnormalized)
    estimated_normalized = self.evaluate(result_normalized)

    self.assertAllClose(estimated_unnormalized, out)
    self.assertAllClose(estimated_normalized, out)
コード例 #2
0
 def test_interp_unnormalizable_raised_(self, points, weights, indices, _):
     """Tests whether exception is raised when weights are unnormalizable."""
     with self.assertRaises(tf.errors.InvalidArgumentError):
         result = weighted.interpolate(points=points,
                                       weights=weights,
                                       indices=indices,
                                       normalize=True,
                                       allow_negative_weights=True)
         self.evaluate(result)
コード例 #3
0
  def test_interpolate_negative_weights_raised(self, dim_points, num_points,
                                               num_outputs,
                                               num_pts_to_interpolate):
    """Tests whether exception is raised when weights are negative."""
    points, weights, indices = self._get_tensors_from_shapes(
        num_points, dim_points, num_outputs, num_pts_to_interpolate)
    weights *= -1.0

    with self.assertRaises(tf.errors.InvalidArgumentError):
      result = weighted.interpolate(
          points=points, weights=weights, indices=indices, normalize=True)
      self.evaluate(result)
コード例 #4
0
    def test_interpolate_jacobian_random(self, dim_points, num_points,
                                         num_outputs, num_pts_to_interpolate):
        """Tests whether jacobian is correct."""
        points_np, weights_np, indices_np = self._get_tensors_from_shapes(
            num_points, dim_points, num_outputs, num_pts_to_interpolate)
        points = tf.convert_to_tensor(value=points_np)
        weights = tf.convert_to_tensor(value=weights_np)
        indices = tf.convert_to_tensor(value=indices_np)

        y = weighted.interpolate(points=points,
                                 weights=weights,
                                 indices=indices,
                                 normalize=True)

        with self.subTest(name="points"):
            self.assert_jacobian_is_correct(points, points_np, y)

        with self.subTest(name="weights"):
            self.assert_jacobian_is_correct(weights, weights_np, y)
コード例 #5
0
  def test_interpolate_jacobian_random(self, dim_points, num_points,
                                       num_outputs, num_pts_to_interpolate):
    """Tests whether jacobian is correct."""
    points_np, weights_np, indices_np = self._get_tensors_from_shapes(
        num_points, dim_points, num_outputs, num_pts_to_interpolate)

    # Wrap these in identities because some assert_* ops look at the constant
    # tensor value and mark it as unfeedable.
    points = tf.identity(tf.convert_to_tensor(value=points_np))
    weights = tf.identity(tf.convert_to_tensor(value=weights_np))
    indices = tf.identity(tf.convert_to_tensor(value=indices_np))

    y = weighted.interpolate(
        points=points, weights=weights, indices=indices, normalize=True)

    with self.subTest(name="points"):
      self.assert_jacobian_is_correct(points, points_np, y)

    with self.subTest(name="weights"):
      self.assert_jacobian_is_correct(weights, weights_np, y)
コード例 #6
0
 def interpolate_fn(points, weights):
   return weighted.interpolate(
       points=points, weights=weights, indices=indices_np, normalize=True)