def testSplineCurveInverseIsCorrect(self):
   """Tests that the inverse curve is indeed the inverse of the curve."""
   x_knot = np.arange(0, 16, 0.01, dtype=np.float64)
   with self.session():
     alpha = distribution.inv_partition_spline_curve(x_knot).eval()
     x_recon = distribution.partition_spline_curve(alpha).eval()
   self.assertAllClose(x_recon, x_knot)
Esempio n. 2
0
    def testSplineCurveIsC1Smooth(self):
        """Tests that partition_spline_curve() and its derivative are continuous."""
        x1 = np.linspace(0., 8., 10000, dtype=np.float64)
        x2 = x1 + 1e-7

        x1 = tf.convert_to_tensor(x1)
        x2 = tf.convert_to_tensor(x2)

        with tf.GradientTape(persistent=True) as tape:
            tape.watch(x1)
            tape.watch(x2)
            y1 = distribution.partition_spline_curve(x1)
            y2 = distribution.partition_spline_curve(x2)
            dy1 = tape.gradient(tf.reduce_sum(y1), x1)
            dy2 = tape.gradient(tf.reduce_sum(y2), x2)
            self.assertAllClose(y1, y2)
            self.assertAllClose(dy1, dy2)
 def testSplineCurveIsC1Smooth(self):
   """Tests that partition_spline_curve() and its derivative are continuous."""
   x1 = np.linspace(0., 8., 10000, dtype=np.float64)
   x2 = x1 + 1e-7
   x_ph = tf.placeholder(x1.dtype, len(x1))
   splinefun_ph = distribution.partition_spline_curve(x_ph)
   with self.session() as sess:
     y1, (dy1,) = sess.run(
         (splinefun_ph, tf.gradients(tf.reduce_sum(splinefun_ph), (x_ph))),
         feed_dict={x_ph: x1})
     y2, (dy2,) = sess.run(
         (splinefun_ph, tf.gradients(tf.reduce_sum(splinefun_ph),
                                     (x_ph))), {x_ph: x2})
   self.assertAllClose(y1, y2)
   self.assertAllClose(dy1, dy2)